uatomic/x86: Remove redundant memory barriers
[urcu.git] / doc / examples / wfstack / cds_wfs_pop.c
CommitLineData
1c87adb3
MJ
1// SPDX-FileCopyrightText: 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2//
3// SPDX-License-Identifier: MIT
4
95bba308 5/*
95bba308
MD
6 * This example shows how to pop nodes from a wfstack.
7 */
8
9#include <stdio.h>
10#include <stdlib.h>
11
12#include <urcu/wfstack.h> /* Wait-free stack */
13#include <urcu/compiler.h> /* For CAA_ARRAY_SIZE */
14
15/*
16 * Nodes populated into the stack.
17 */
18struct mynode {
19 int value; /* Node content */
20 struct cds_wfs_node node; /* Chaining in stack */
21};
22
70469b43 23int main(void)
95bba308
MD
24{
25 int values[] = { -5, 42, 36, 24, };
26 struct cds_wfs_stack mystack; /* Stack */
27 unsigned int i;
28 int ret = 0;
29
30 cds_wfs_init(&mystack);
31
32 /*
33 * Push nodes.
34 */
35 for (i = 0; i < CAA_ARRAY_SIZE(values); i++) {
36 struct mynode *node;
37
38 node = malloc(sizeof(*node));
39 if (!node) {
40 ret = -1;
41 goto end;
42 }
43
44 cds_wfs_node_init(&node->node);
45 node->value = values[i];
46 cds_wfs_push(&mystack, &node->node);
47 }
48
49 /*
50 * Pop nodes from the stack, one by one, from newest to oldest.
51 */
52 printf("pop each mystack node:");
53 for (;;) {
54 struct cds_wfs_node *snode;
55 struct mynode *node;
56
57 snode = cds_wfs_pop_blocking(&mystack);
58 if (!snode) {
59 break;
60 }
61 node = caa_container_of(snode, struct mynode, node);
62 printf(" %d", node->value);
63 free(node);
64 }
65 printf("\n");
66end:
6acc6ad4 67 cds_wfs_destroy(&mystack);
95bba308
MD
68 return ret;
69}
This page took 0.038528 seconds and 4 git commands to generate.