X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu-defer-static.h;h=427f3d34d7aa04c5a56db02140815bfd4a1d949b;hp=25137690465fa9c32ef5939be20d1cec3bdd17ad;hb=ba59a0c7b244a0939a2298fc76a9002436ef9674;hpb=786ee85b1676d2a1865b2db7120c45bafdf954d6 diff --git a/urcu-defer-static.h b/urcu-defer-static.h index 2513769..427f3d3 100644 --- a/urcu-defer-static.h +++ b/urcu-defer-static.h @@ -42,6 +42,23 @@ #define DEFER_QUEUE_SIZE (1 << 12) #define DEFER_QUEUE_MASK (DEFER_QUEUE_SIZE - 1) +/* + * Typically, data is aligned at least on the architecture size. + * Use lowest bit to indicate that the current callback is changing. + * Assumes that (void *)-2L is not used often. Used to encode non-aligned + * functions and non-aligned data using extra space. + * We encode the (void *)-2L fct as: -2L, fct, data. + * We encode the (void *)-2L data as: -2L, fct, data. + * Here, DQ_FCT_MARK == ~DQ_FCT_BIT. Required for the test order. + */ +#define DQ_FCT_BIT (1 << 0) +#define DQ_IS_FCT_BIT(x) ((unsigned long)(x) & DQ_FCT_BIT) +#define DQ_SET_FCT_BIT(x) \ + (x = (void *)((unsigned long)(x) | DQ_FCT_BIT)) +#define DQ_CLEAR_FCT_BIT(x) \ + (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. */ @@ -86,43 +103,23 @@ #define rcu_assert(args...) #endif +/* + * defer queue. + * Contains pointers. Encoded to save space when same callback is often used. + * When looking up the next item: + * - if DQ_FCT_BIT is set, set the current callback to DQ_CLEAR_FCT_BIT(ptr) + * - next element contains pointer to data. + * - else if item == DQ_FCT_MARK + * - set the current callback to next element ptr + * - following next element contains pointer to data. + * - else current element contains data + */ struct defer_queue { unsigned long head; /* add element at head */ + void *last_fct_in; /* last fct pointer encoded */ unsigned long tail; /* next element to remove at tail */ + void *last_fct_out; /* last fct pointer encoded */ void **q; }; -extern struct defer_queue __thread defer_queue; - -extern void rcu_defer_barrier_thread(void); - -/* - * not signal-safe. - */ -static inline void _rcu_defer_queue(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. - */ - if (unlikely(head - tail >= DEFER_QUEUE_SIZE)) { - assert(head - tail == DEFER_QUEUE_SIZE); - rcu_defer_barrier_thread(); - assert(head - LOAD_SHARED(defer_queue.tail) == 0); - } - - smp_wmb(); /* Publish new pointer before write q[] */ - _STORE_SHARED(defer_queue.q[head & DEFER_QUEUE_MASK], p); - smp_wmb(); /* Write q[] before head. */ - STORE_SHARED(defer_queue.head, head + 1); -} - #endif /* _URCU_DEFER_STATIC_H */