P99

◆ P99_FIFO_CLEAR

#define P99_FIFO_CLEAR (   L)
Value:
({ \
/* first evaluate the macro argument such that there can't be */ \
/* a name conflict */ \
register const P99_MACRO_VAR(p00_l, (L)); \
register const P99_MACRO_VAR(p00_h, &p00_l->p00_head); \
register const P99_MACRO_VAR(p00_t, &p00_l->p00_tail); \
P99_MACRO_VAR(p00_head, atomic_load_explicit(p00_h, memory_order_relaxed)); \
for (;;) { \
if (p00_head) { \
/* spin lock the whole fifo */ \
if (atomic_compare_exchange_weak_explicit(p00_h, &p00_head, 0, memory_order_acq_rel, memory_order_consume)) { \
atomic_store_explicit(p00_t, 0, memory_order_release); \
break; \
} \
} else { \
register const P99_MACRO_VAR(p00_tail, atomic_load_explicit(p00_t, memory_order_consume)); \
if (!p00_tail) break; \
p00_head = atomic_load_explicit(p00_h, memory_order_relaxed); \
} \
} \
/* make sure that the result can not be used as an lvalue */ \
register const __typeof__(p00_head = p00_head) p00_r = p00_head; \
p00_r; \
})

Atomically clear an atomic FIFO L and return a pointer to the start of the list that it previously contained.

See also
P99_FIFO
P99_FIFO_DECLARE
P99_FIFO_APPEND
P00_FIFO_EL
Remarks
argument 0 maybe evaluated several times for its type but only once for its value

Definition at line 179 of file p99_fifo.h.

P99_MACRO_VAR
#define P99_MACRO_VAR(NAME, EXPR, QUAL)
Define a variable with NAME that has the type and value of EXPR.
Definition: p99_for.h:1268
p99_extension
#define p99_extension
Mark an expression as using a compiler extension.
Definition: p99_compiler.h:210