ppc.h: use mftb on ppc
[urcu.git] / include / urcu / rcuhlist.h
CommitLineData
d3d3857f
MJ
1// SPDX-FileCopyrightText: 2002 Free Software Foundation, Inc.
2// SPDX-FileCopyrightText: 2009 Pierre-Marc Fournier
3// SPDX-FileCopyrightText: 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4//
5// SPDX-License-Identifier: LGPL-2.1-or-later
6
a00718e7 7/*
a00718e7
MD
8 * (originally part of the GNU C Library)
9 * Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
a00718e7 10 */
5db941e8
MD
11
12#ifndef _URCU_RCUHLIST_H
13#define _URCU_RCUHLIST_H
14
15#include <urcu/hlist.h>
16#include <urcu/arch.h>
17#include <urcu-pointer.h>
18
6734fec1
MD
19/* Add new element at the head of the list. */
20static inline
21void cds_hlist_add_head_rcu(struct cds_hlist_node *newp,
22 struct cds_hlist_head *head)
5db941e8
MD
23{
24 newp->next = head->next;
16aa9ee8 25 newp->prev = (struct cds_hlist_node *)head;
5db941e8
MD
26 if (head->next)
27 head->next->prev = newp;
90bdf188 28 rcu_assign_pointer(head->next, newp);
5db941e8
MD
29}
30
31/* Remove element from list. */
6734fec1
MD
32static inline
33void cds_hlist_del_rcu(struct cds_hlist_node *elem)
5db941e8
MD
34{
35 if (elem->next)
36 elem->next->prev = elem->prev;
90bdf188 37 CMM_STORE_SHARED(elem->prev->next, elem->next);
5db941e8
MD
38}
39
6734fec1
MD
40/*
41 * Iterate through elements of the list.
5db941e8
MD
42 * This must be done while rcu_read_lock() is held.
43 */
d7a0f2fe 44#define cds_hlist_for_each_rcu(pos, head) \
2b6f565a
MD
45 for (pos = rcu_dereference((head)->next); (pos) != NULL; \
46 pos = rcu_dereference((pos)->next))
d7a0f2fe
MD
47
48/*
49 * cds_hlist_for_each_entry_rcu takes 4 arguments, while the Linux
50 * kernel API only takes 3.
51 * We implement cds_hlist_for_each_entry_rcu_2() to follow the Linux
52 * kernel APIs.
53 */
6734fec1
MD
54#define cds_hlist_for_each_entry_rcu(entry, pos, head, member) \
55 for (pos = rcu_dereference((head)->next), \
2b6f565a
MD
56 entry = cds_hlist_entry(pos, __typeof__(*(entry)), member); \
57 (pos) != NULL; \
58 pos = rcu_dereference((pos)->next), \
59 entry = cds_hlist_entry(pos, __typeof__(*(entry)), member))
5db941e8 60
d7a0f2fe 61#define cds_hlist_for_each_entry_rcu_2(entry, head, member) \
a0b5ef68 62 for (entry = cds_hlist_entry_safe(rcu_dereference((head)->next), \
2b6f565a
MD
63 __typeof__(*(entry)), member); \
64 (entry) != NULL; \
65 entry = cds_hlist_entry_safe(rcu_dereference((entry)->member.next), \
66 __typeof__(*(entry)), member))
d7a0f2fe 67
5db941e8 68#endif /* _URCU_RCUHLIST_H */
This page took 0.051748 seconds and 4 git commands to generate.