2 * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7 * Permission is hereby granted to use or copy this program for any
8 * purpose, provided the above notices are retained on all copies.
9 * Permission to modify the code and to distribute modified code is
10 * granted, provided the above notices are retained, and a notice that
11 * the code was modified is included with the above copyright notice.
13 * This example shows how to dequeue nodes from a wfcqueue.
19 #include <urcu/wfcqueue.h> /* Wait-free concurrent queue */
20 #include <urcu/compiler.h> /* For CAA_ARRAY_SIZE */
23 * Nodes populated into the queue.
26 int value
; /* Node content */
27 struct cds_wfcq_node node
; /* Chaining in queue */
30 int main(int argc
, char **argv
)
32 int values
[] = { -5, 42, 36, 24, };
33 struct cds_wfcq_head myqueue_head
; /* Queue head */
34 struct cds_wfcq_tail myqueue_tail
; /* Queue tail */
38 cds_wfcq_init(&myqueue_head
, &myqueue_tail
);
43 for (i
= 0; i
< CAA_ARRAY_SIZE(values
); i
++) {
46 node
= malloc(sizeof(*node
));
52 cds_wfcq_node_init(&node
->node
);
53 node
->value
= values
[i
];
54 cds_wfcq_enqueue(&myqueue_head
, &myqueue_tail
,
59 * Dequeue each node from the queue. Those will be dequeued from
60 * the oldest (first enqueued) to the newest (last enqueued).
62 printf("dequeued content:");
64 struct cds_wfcq_node
*qnode
;
67 qnode
= cds_wfcq_dequeue_blocking(&myqueue_head
, &myqueue_tail
);
69 break; /* Queue is empty. */
71 /* Getting the container structure from the node */
72 node
= caa_container_of(qnode
, struct mynode
, node
);
73 printf(" %d", node
->value
);
78 cds_wfcq_destroy(&myqueue_head
, &myqueue_tail
);