25d6381bb582df70c89c54f3eb652ddc8e8419ea
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 lfstack.
12 #include <urcu/lfstack.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_lfs_node node
; /* Chaining in stack */
25 int values
[] = { -5, 42, 36, 24, };
26 struct cds_lfs_stack mystack
; /* Stack */
30 cds_lfs_init(&mystack
);
35 for (i
= 0; i
< CAA_ARRAY_SIZE(values
); i
++) {
38 node
= malloc(sizeof(*node
));
44 cds_lfs_node_init(&node
->node
);
45 node
->value
= values
[i
];
46 cds_lfs_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_lfs_node
*snode
;
57 snode
= cds_lfs_pop_blocking(&mystack
);
61 node
= caa_container_of(snode
, struct mynode
, node
);
62 printf(" %d", node
->value
);
67 cds_lfs_destroy(&mystack
);
This page took 0.029925 seconds and 4 git commands to generate.