1 // SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: MIT
6 * This example shows how to pop 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 */
30 cds_wfs_init(&mystack
);
35 for (i
= 0; i
< CAA_ARRAY_SIZE(values
); i
++) {
38 node
= malloc(sizeof(*node
));
44 cds_wfs_node_init(&node
->node
);
45 node
->value
= values
[i
];
46 cds_wfs_push(&mystack
, &node
->node
);
50 * Pop nodes from the stack, one by one, from newest to oldest.
52 printf("pop each mystack node:");
54 struct cds_wfs_node
*snode
;
57 snode
= cds_wfs_pop_blocking(&mystack
);
61 node
= caa_container_of(snode
, struct mynode
, node
);
62 printf(" %d", node
->value
);
67 cds_wfs_destroy(&mystack
);
This page took 0.044319 seconds and 5 git commands to generate.