DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

UDI_QUEUE_FOREACH(3udi)


Safe mechanism to walk a queue

SYNOPSIS

#include <udi.h>

#define UDI_QUEUE_FOREACH(listhead, element, tmp) \

   for ((element) = UDI_FIRST_ELEMENT(listhead); \

		((tmp) = UDI_NEXT_ELEMENT(element)), \

		((element) != (listhead)); \

		(element) = (tmp)))
 

ARGUMENTS listhead is a pointer to a list head element.

element is a queue element pointer variable that may be uninitialized on entry, and is set successively to each element in the queue.

tmp is a queue element pointer variable for temporary storage in the loop.

DESCRIPTION UDI_QUEUE_FOREACH walks through the elements in the queue specified by listhead, setting element successively to each element in the queue, beginning at the head and continuing to the tail of the queue. This provides a safe mechanism to walk through each element in a queue, and do operations on each element (including removing it from the queue and re-queuing it in another queue) without affecting the traversal to the next element in the queue.

The UDI_QUEUE_FOREACH macro produces an iteration (loop) statement and hence must be followed by a C statement which is the action to take for each iteration through the loop (e.g., an action on each element in the queue). The parameters to this macro must have the following type definitions:

UDI_QUEUE_FOREACH (

		udi_queue_t *listhead,

		udi_queue_t *element,

		udi_queue_t *tmp );
 

EXAMPLES The following code reverses the elements in a queue:

{

   udi_queue_t *elem, *tmp;

   udi_queue_t *head = &region_data->my_queue;

   UDI_QUEUE_FOREACH(head,elem,tmp) {

	UDI_ENQUEUE_HEAD(udi_dequeue(elem))

   }

}
 

REFERENCES udi_queue_t


UDI Core Specification Contents