1 // SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: MIT
6 * This example shows how to enqueue nodes into a RCU lock-free queue.
7 * This queue requires using a RCU scheme.
13 #include <urcu/urcu-memb.h> /* RCU flavor */
14 #include <urcu/rculfqueue.h> /* RCU Lock-free queue */
15 #include <urcu/compiler.h> /* For CAA_ARRAY_SIZE */
18 * Nodes populated into the queue.
21 int value
; /* Node content */
22 struct cds_lfq_node_rcu node
; /* Chaining in queue */
27 int values
[] = { -5, 42, 36, 24, };
28 struct cds_lfq_queue_rcu myqueue
; /* Queue */
33 * Each thread need using RCU read-side need to be explicitly
36 urcu_memb_register_thread();
38 cds_lfq_init_rcu(&myqueue
, urcu_memb_call_rcu
);
43 for (i
= 0; i
< CAA_ARRAY_SIZE(values
); i
++) {
46 node
= malloc(sizeof(*node
));
52 cds_lfq_node_init_rcu(&node
->node
);
53 node
->value
= values
[i
];
55 * Both enqueue and dequeue need to be called within RCU
56 * read-side critical section.
58 urcu_memb_read_lock();
59 cds_lfq_enqueue_rcu(&myqueue
, &node
->node
);
60 urcu_memb_read_unlock();
64 urcu_memb_unregister_thread();