P99
|
◆ P99_LIFO_POP
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_DECLARE_STRUCT(myData);
P99_POINTER_TYPE(myData);
P99_FIFO_DECLARE(myData_ptr);
struct myData {
...
myData_ptr p99_lifo;
...
};
extern P99_LIFO(myData_ptr) head;
Now 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);
}
Definition at line 120 of file p99_lifo.h. |