lfstack: implement test
[urcu.git] / urcu / lfstack.h
... / ...
CommitLineData
1#ifndef _URCU_LFSTACK_H
2#define _URCU_LFSTACK_H
3
4/*
5 * lfstack.h
6 *
7 * Userspace RCU library - Lock-Free Stack
8 *
9 * Copyright 2010-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30struct cds_lfs_node {
31 struct cds_lfs_node *next;
32};
33
34struct cds_lfs_stack {
35 struct cds_lfs_node *head;
36};
37
38#ifdef _LGPL_SOURCE
39
40#include <urcu/static/lfstack.h>
41
42#define cds_lfs_node_init _cds_lfs_node_init
43#define cds_lfs_init _cds_lfs_init
44#define cds_lfs_push _cds_lfs_push
45#define cds_lfs_pop _cds_lfs_pop
46
47#else /* !_LGPL_SOURCE */
48
49extern void cds_lfs_node_init(struct cds_lfs_node *node);
50extern void cds_lfs_init(struct cds_lfs_stack *s);
51
52/*
53 * cds_lfs_push: push a node into the stack.
54 *
55 * Does not require any synchronization with other push nor pop.
56 *
57 * Returns 0 if the stack was empty prior to adding the node.
58 * Returns non-zero otherwise.
59 */
60extern int cds_lfs_push(struct cds_lfs_stack *s,
61 struct cds_lfs_node *node);
62
63/*
64 * cds_lfs_pop: pop a node from the stack.
65 *
66 * Returns NULL if stack is empty.
67 *
68 * cds_lfs_pop needs to be synchronized using one of the following
69 * techniques:
70 *
71 * 1) Calling cds_lfs_pop under rcu read lock critical section. The
72 * caller must wait for a grace period to pass before freeing the
73 * returned node or modifying the cds_lfs_node structure.
74 * 2) Using mutual exclusion (e.g. mutexes) to protect cds_lfs_pop
75 * callers.
76 * 3) Ensuring that only ONE thread can call cds_lfs_pop().
77 * (multi-provider/single-consumer scheme).
78 */
79extern struct cds_lfs_node *cds_lfs_pop(struct cds_lfs_stack *s);
80
81#endif /* !_LGPL_SOURCE */
82
83#ifdef __cplusplus
84}
85#endif
86
87#endif /* _URCU_LFSTACK_H */
This page took 0.02554 seconds and 4 git commands to generate.