b3c5b933f0cf8b9a0b2aa80ed25aa515b720b83b
1 // SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: MIT
6 * This example shows how to push nodes into a lfstack.
12 #include <urcu/lfstack.h> /* Lock-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 */
29 struct cds_lfs_node
*snode
;
30 struct cds_lfs_head
*shead
;
32 cds_lfs_init(&mystack
);
37 for (i
= 0; i
< CAA_ARRAY_SIZE(values
); i
++) {
40 node
= malloc(sizeof(*node
));
46 cds_lfs_node_init(&node
->node
);
47 node
->value
= values
[i
];
48 cds_lfs_push(&mystack
, &node
->node
);
52 * Show the stack content, iterate in reverse order of push,
53 * from newest to oldest.
55 printf("mystack content:");
56 shead
= cds_lfs_pop_all_blocking(&mystack
);
57 cds_lfs_for_each(shead
, snode
) {
59 caa_container_of(snode
, struct mynode
, node
);
60 printf(" %d", node
->value
);
64 cds_lfs_destroy(&mystack
);
This page took 0.030275 seconds and 4 git commands to generate.