1 // SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: MIT
6 * This example shows how to pop all nodes from a wfstack.
12 #include <urcu/wfstack.h> /* Wait-free stack */
13 #include <urcu/compiler.h> /* For CAA_ARRAY_SIZE */
16 * Nodes populated into the stack.
19 int value
; /* Node content */
20 struct cds_wfs_node node
; /* Chaining in stack */
25 int values
[] = { -5, 42, 36, 24, };
26 struct cds_wfs_stack mystack
; /* Stack */
29 struct cds_wfs_node
*snode
, *sn
;
30 struct cds_wfs_head
*shead
;
32 cds_wfs_init(&mystack
);
37 for (i
= 0; i
< CAA_ARRAY_SIZE(values
); i
++) {
40 node
= malloc(sizeof(*node
));
46 cds_wfs_node_init(&node
->node
);
47 node
->value
= values
[i
];
48 cds_wfs_push(&mystack
, &node
->node
);
52 * Pop all nodes from mystack into shead. The head can the be
55 shead
= cds_wfs_pop_all_blocking(&mystack
);
58 * Show the stack content, iterate in reverse order of push,
59 * from newest to oldest. Use cds_wfs_for_each_blocking_safe()
60 * so we can free the nodes as we iterate.
62 printf("mystack content:");
63 cds_wfs_for_each_blocking_safe(shead
, snode
, sn
) {
65 caa_container_of(snode
, struct mynode
, node
);
66 printf(" %d", node
->value
);
71 cds_wfs_destroy(&mystack
);
This page took 0.030408 seconds and 4 git commands to generate.