6087bae8b2d4ac524106c847e45c90b71ce057b3
1 // SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: MIT
6 * This example shows how to add into a non-circular linked-list safely
7 * against concurrent RCU traversals.
12 #include <urcu/urcu-memb.h> /* Userspace RCU flavor */
13 #include <urcu/rcuhlist.h> /* RCU hlist */
14 #include <urcu/compiler.h> /* For CAA_ARRAY_SIZE */
17 * Nodes populated into the list.
20 int value
; /* Node content */
21 struct cds_hlist_node node
; /* Linked-list chaining */
26 int values
[] = { -5, 42, 36, 24, };
27 CDS_HLIST_HEAD(mylist
); /* Defines an empty hlist 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_hlist_add_head_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_hlist_for_each_entry_2(node
, &mylist
, node
) {
52 printf(" %d", node
->value
);
This page took 0.03279 seconds and 5 git commands to generate.