Generic queue implementation.
More...
|
#define | VTM_SQUEUE_STRUCT(NODE_TYPE) |
|
#define | VTM_SQUEUE_INIT(NAME) |
|
#define | VTM_SQUEUE_ADD(NAME, NODE_PTR) |
|
#define | VTM_SQUEUE_POLL(NAME, NODE_PTR) |
|
#define | VTM_SQUEUE_REMOVE(NAME, NODE_PTR, PREV_PTR, FUNC) |
|
#define | VTM_SQUEUE_IS_EMPTY(NAME) (NAME.head == NULL) |
|
#define | VTM_SQUEUE_FOR_EACH(NAME, NODE_PTR) |
|
#define | VTM_SQUEUE_FOR_EACH_MOD(NAME, NODE_PTR, PREV_PTR, NEXT_PTR) |
|
#define | VTM_SQUEUE_CLEAR(NAME, NODE_TYPE, FUNC) |
|
#define VTM_SQUEUE_STRUCT |
( |
|
NODE_TYPE | ) |
|
Value:struct { \
NODE_TYPE *head; \
NODE_TYPE *tail; \
}
Defines the struct that holds the queue.
The struct definition that represents the items in the queue must have a member called "next" which must be a pointer to a struct instance.
- Parameters
-
NODE_TYPE | name of the struct whose instances are stored as items in the queue |
#define VTM_SQUEUE_INIT |
( |
|
NAME | ) |
|
Value:do { \
NAME.head = NULL; \
NAME.tail = NULL; \
} while (0)
Initializes the queue.
This function must be called, before any of the other functions can be used.
- Parameters
-
NAME | the target queue variable |
#define VTM_SQUEUE_ADD |
( |
|
NAME, |
|
|
|
NODE_PTR |
|
) |
| |
Value:do { \
NODE_PTR->next = NULL; \
if (NAME.tail) \
NAME.tail->next = NODE_PTR; \
NAME.tail = NODE_PTR; \
if (!NAME.head) \
NAME.head = NODE_PTR; \
} while (0)
Adds an item to the queue.
- Parameters
-
NAME | the target queue variable |
NODE_PTR | pointer to struct instance that is added to the queue |
#define VTM_SQUEUE_POLL |
( |
|
NAME, |
|
|
|
NODE_PTR |
|
) |
| |
Value:do { \
NODE_PTR = NAME.head; \
if (NAME.head) { \
NAME.head = NAME.head->next; \
if (NAME.tail == NODE_PTR) \
NAME.tail = NULL; \
} \
} while (0)
Retrieves and removes the head element of the queue.
- Parameters
-
| NAME | the target queue variable |
[out] | NODE_PTR | stores the retrieved element |
#define VTM_SQUEUE_REMOVE |
( |
|
NAME, |
|
|
|
NODE_PTR, |
|
|
|
PREV_PTR, |
|
|
|
FUNC |
|
) |
| |
Value:do { \
if (PREV_PTR) \
PREV_PTR->next = NODE_PTR->next; \
else \
NAME.head = NODE_PTR->next; \
if (NODE_PTR == NAME.tail) \
NAME.tail = PREV_PTR; \
FUNC(NODE_PTR); \
} while (0)
Removes the given item from the queue.
- Parameters
-
NAME | the target queue variable |
NODE_PTR | the item that should be removed |
PREV_PTR | the predecessor of the item that should be removed |
FUNC | function pointer that is called with the removed element |
#define VTM_SQUEUE_IS_EMPTY |
( |
|
NAME | ) |
(NAME.head == NULL) |
Checks wether the queue is empty.
- Parameters
-
NAME | the target queue variable |
#define VTM_SQUEUE_FOR_EACH |
( |
|
NAME, |
|
|
|
NODE_PTR |
|
) |
| |
Value:for (NODE_PTR = NAME.head; NODE_PTR != NULL; \
NODE_PTR = NODE_PTR->next)
Iterates through the queue.
- Parameters
-
| NAME | the target queue variable |
[out] | NODE_PTR | will point to current item |
#define VTM_SQUEUE_FOR_EACH_MOD |
( |
|
NAME, |
|
|
|
NODE_PTR, |
|
|
|
PREV_PTR, |
|
|
|
NEXT_PTR |
|
) |
| |
Value:for (NODE_PTR = NAME.head, \
PREV_PTR = NULL, \
NEXT_PTR = NODE_PTR ? NODE_PTR->next : NULL; \
NODE_PTR != NULL; \
PREV_PTR = NODE_PTR, \
NODE_PTR = NEXT_PTR, \
NEXT_PTR = NEXT_PTR ? NEXT_PTR->next : NULL)
Iterates through the queue and allows possible modification.
- Parameters
-
| NAME | the target queue variable |
[out] | NODE_PTR | will point to current item |
[out] | PREV_PTR | will point to previous item, can be NULL |
[out] | NEXT_PTR | will point to next item, can be NULL |
#define VTM_SQUEUE_CLEAR |
( |
|
NAME, |
|
|
|
NODE_TYPE, |
|
|
|
FUNC |
|
) |
| |
Value:do { \
NODE_TYPE *node; \
NODE_TYPE *prev; \
FUNC(node); \
} \
NAME.head = NULL; \
NAME.tail = NULL; \
} while (0)
#define VTM_UNUSED(VAR)
Definition: macros.h:26
#define VTM_SQUEUE_FOR_EACH_MOD(NAME, NODE_PTR, PREV_PTR, NEXT_PTR)
Definition: squeue.h:124
Removes all items from the queue.
- Parameters
-
NAME | the target queue variable |
NODE_TYPE | name of the struct whose instances are stored as items in the queue |
FUNC | function pointer that is called with each removed element |