P99

◆ P99_LIFO_POP

#define P99_LIFO_POP (   L)
Value:
({ \
register const P99_MACRO_VAR(p00_l, (L)); \
P99_TP_TYPE_STATE(p00_l) p00_state = P99_TP_STATE_INITIALIZER(p00_l, 0); \
/* be sure that the result can not be used as an lvalue */ \
register P99_TP_TYPE(p00_l)* p00_r = P99_TP_STATE_GET(&p00_state); \
for (; p00_r; p00_r = P99_TP_STATE_GET(&p00_state)) { \
P99_TP_STATE_SET(&p00_state, p00_r->p99_lifo); \
if (P99_TP_STATE_COMMIT(&p00_state)) \
break; \
} \
if (p00_r) p00_r->p99_lifo = 0; \
p00_r; \
})

Pop the top element from an atomic LIFO L.

This implements a generic interface to an atomic LIFO (Last In - First Out) data structure. To use it you just have do some preparatory declarations and add a p99_lifo field to your data structure:

P99_FIFO_DECLARE(myData_ptr);
struct myData {
...
myData_ptr p99_lifo;
...
};
extern P99_LIFO(myData_ptr) head;

Now head can be used as the head of a LIFO:

myData_ptr el = P99_NEW(myData, \/\* your initializer arguments \*\/);
P99_LIFO_PUSH(&head, el);
...
for (myData_ptr el = P99_LIFO_POP(&head);
el;
el = P99_LIFO_POP(&head)) {
// do something with el and then
free(el);
}
See also
P99_LIFO_CLEAR
P99_LIFO
P99_LIFO_DECLARE
P99_LIFO_PUSH
Remarks
argument 0 maybe evaluated several times for its type but only once for its value

Definition at line 120 of file p99_lifo.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_LIFO_PUSH
#define P99_LIFO_PUSH(L, EL)
Push element EL into an atomic LIFO L.
Definition: p99_lifo.h:68
P99_TP_STATE_GET
#define P99_TP_STATE_GET(TPS)
p99_extension
#define p99_extension
Mark an expression as using a compiler extension.
Definition: p99_compiler.h:210
P99_NEW
#define P99_NEW(...)
Allocate an element of type T as given by the first argument and initialize it with the remaining arg...
Definition: p99_new.h:314
P99_TP_STATE_INITIALIZER
#define P99_TP_STATE_INITIALIZER(TP, P)
P99_DECLARE_STRUCT
#define P99_DECLARE_STRUCT(NAME)
forward declaration of a struct NAME
Definition: p99_type.h:59
P99_POINTER_TYPE
#define P99_POINTER_TYPE(T)
Declare derived pointer types with endings "_ptr" and "_cptr".
Definition: p99_type.h:132
P99_LIFO
#define P99_LIFO(T)
Definition: p99_lifo.h:42
P99_LIFO_POP
#define P99_LIFO_POP(L)
Pop the top element from an atomic LIFO L.
Definition: p99_lifo.h:120
P99_FIFO_DECLARE
#define P99_FIFO_DECLARE(T)
Definition: p99_fifo.h:40
P99_TP_TYPE
#define P99_TP_TYPE(TP)
P99_TP_STATE_COMMIT
#define P99_TP_STATE_COMMIT(TPS)