X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu-defer-static.h;h=3e5df3e75b11c31efcd19ec380202d070f824620;hp=dd24c61d85d7885d685323757f83c52c2df2f15f;hb=2260a36cd53dc882bf83e39180bae4413d64da8f;hpb=4ce9e4f28aa6de3f3443066c7a64d12156904d6b diff --git a/urcu-defer-static.h b/urcu-defer-static.h index dd24c61..3e5df3e 100644 --- a/urcu-defer-static.h +++ b/urcu-defer-static.h @@ -9,7 +9,7 @@ * TO BE INCLUDED ONLY IN LGPL-COMPATIBLE CODE. See urcu-defer.h for linking * dynamically with the userspace rcu reclamation library. * - * Copyright (c) 2009 Mathieu Desnoyers + * Copyright (c) 2009 Mathieu Desnoyers * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. * * This library is free software; you can redistribute it and/or @@ -32,9 +32,15 @@ #include #include -#include -#include +#include +#include +#include +#include +#include +#ifdef __cplusplus +extern "C" { +#endif /* * Number of entries in the per-thread defer queue. Must be power of 2. @@ -59,36 +65,6 @@ (x = (void *)((unsigned long)(x) & ~DQ_FCT_BIT)) #define DQ_FCT_MARK ((void *)(~DQ_FCT_BIT)) -/* - * Identify a shared load. A smp_rmc() or smp_mc() should come before the load. - */ -#define _LOAD_SHARED(p) ACCESS_ONCE(p) - -/* - * Load a data from shared memory, doing a cache flush if required. - */ -#define LOAD_SHARED(p) \ - ({ \ - smp_rmc(); \ - _LOAD_SHARED(p); \ - }) - -/* - * Identify a shared store. A smp_wmc() or smp_mc() should follow the store. - */ -#define _STORE_SHARED(x, v) ({ ACCESS_ONCE(x) = (v); }) - -/* - * Store v into x, where x is located in shared memory. Performs the required - * cache flush after writing. Returns v. - */ -#define STORE_SHARED(x, v) \ - ({ \ - _STORE_SHARED(x, v); \ - smp_wmc(); \ - (v); \ - }) - /* * This code section can only be included in LGPL 2.1 compatible source code. * See below for the function call wrappers which can be used in code meant to @@ -120,74 +96,13 @@ struct defer_queue { unsigned long tail; /* next element to remove at tail */ void *last_fct_out; /* last fct pointer encoded */ void **q; + /* registry information */ + unsigned long last_head; + struct cds_list_head list; /* list of thread queues */ }; -extern struct defer_queue __thread defer_queue; - -extern void rcu_defer_barrier_thread(void); -extern void wake_up_defer(void); - -/* - * not signal-safe. - */ -static inline void _rcu_defer_queue(void (*fct)(void *p), void *p) -{ - unsigned long head, tail; - - /* - * Head is only modified by ourself. Tail can be modified by reclamation - * thread. - */ - head = defer_queue.head; - tail = LOAD_SHARED(defer_queue.tail); - - /* - * If queue is full, empty it ourself. - * Worse-case: must allow 2 supplementary entries for fct pointer. - */ - if (unlikely(head - tail >= DEFER_QUEUE_SIZE - 2)) { - assert(head - tail <= DEFER_QUEUE_SIZE); - rcu_defer_barrier_thread(); - assert(head - LOAD_SHARED(defer_queue.tail) == 0); - } - - if (unlikely(defer_queue.last_fct_in != fct)) { - defer_queue.last_fct_in = fct; - if (unlikely(DQ_IS_FCT_BIT(fct) || fct == DQ_FCT_MARK)) { - /* - * If the function to encode is not aligned or the - * marker, write DQ_FCT_MARK followed by the function - * pointer. - */ - _STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK], - DQ_FCT_MARK); - _STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK], - fct); - } else { - DQ_SET_FCT_BIT(fct); - _STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK], - fct); - } - } else { - if (unlikely(DQ_IS_FCT_BIT(p) || p == DQ_FCT_MARK)) { - /* - * If the data to encode is not aligned or the marker, - * write DQ_FCT_MARK followed by the function pointer. - */ - _STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK], - DQ_FCT_MARK); - _STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK], - fct); - } - } - _STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK], p); - smp_wmb(); /* Publish new pointer before head */ - /* Write q[] before head. */ - STORE_SHARED(defer_queue.head, head); - /* - * Wake-up any waiting defer thread. - */ - wake_up_defer(); +#ifdef __cplusplus } +#endif #endif /* _URCU_DEFER_STATIC_H */