1 // SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: MIT
6 * This example shows how to add into a linked-list safely against
7 * concurrent RCU traversals.
12 #include <urcu/urcu-memb.h> /* Userspace RCU flavor */
13 #include <urcu/rculist.h> /* RCU list */
14 #include <urcu/compiler.h> /* For CAA_ARRAY_SIZE */
17 * Nodes populated into the list.
20 int value
; /* Node content */
21 struct cds_list_head node
; /* Linked-list chaining */
26 int values
[] = { -5, 42, 36, 24, };
27 CDS_LIST_HEAD(mylist
); /* Defines an empty list head */
33 * Adding nodes to the linked-list. Safe against concurrent
34 * RCU traversals, require mutual exclusion with list updates.
36 for (i
= 0; i
< CAA_ARRAY_SIZE(values
); i
++) {
37 node
= malloc(sizeof(*node
));
42 node
->value
= values
[i
];
43 cds_list_add_rcu(&node
->node
, &mylist
);
47 * Just show the list content. This is _not_ an RCU-safe
48 * iteration on the list.
50 printf("mylist content:");
51 cds_list_for_each_entry(node
, &mylist
, node
) {
52 printf(" %d", node
->value
);
This page took 0.039806 seconds and 5 git commands to generate.