rcupdate.h revision 1.2 1 /* $NetBSD: rcupdate.h,v 1.2 2021/12/19 01:46:01 riastradh Exp $ */
2
3 /*-
4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _LINUX_RCUPDATE_H_
33 #define _LINUX_RCUPDATE_H_
34
35 #include <sys/atomic.h>
36 #include <sys/cdefs.h>
37 #include <sys/systm.h>
38
39 #define __rcu
40
41 #define RCU_INIT_POINTER(P, V) ((P) = (V))
42
43 #define rcu_assign_pointer(P, V) do { \
44 __typeof__(*(P)) *__rcu_assign_pointer_tmp = (V); \
45 membar_exit(); \
46 (P) = __rcu_assign_pointer_tmp; \
47 } while (0)
48
49 #define rcu_dereference(P) ({ \
50 __typeof__(*(P)) *__rcu_dereference_tmp = (P); \
51 membar_datadep_consumer(); \
52 __rcu_dereference_tmp; \
53 })
54
55 #define rcu_dereference_raw rcu_dereference
56
57 #define rcu_dereference_protected(P, C) ({ \
58 WARN_ON(!(C)); \
59 (P); \
60 })
61
62 #define rcu_access_pointer(P) ({ \
63 __typeof__(*(P)) *__rcu_access_pointer_tmp = (P); \
64 __insn_barrier(); \
65 __rcu_access_pointer_tmp; \
66 })
67
68 /* kill_dependency */
69 #define rcu_pointer_handoff(P) (P)
70
71 struct rcu_head {
72 union {
73 void (*callback)(struct rcu_head *);
74 void *obj;
75 } rcuh_u;
76 struct rcu_head *rcuh_next;
77 };
78
79 #define _kfree_rcu linux__kfree_rcu
80 #define call_rcu linux_call_rcu
81 #define rcu_barrier linux_rcu_barrier
82 #define synchronize_rcu linux_synchronize_rcu
83
84 int linux_rcu_gc_init(void);
85 void linux_rcu_gc_fini(void);
86
87 void call_rcu(struct rcu_head *, void (*)(struct rcu_head *));
88 void rcu_barrier(void);
89 void synchronize_rcu(void);
90
91 void _kfree_rcu(struct rcu_head *, void *);
92
93 static inline void
94 rcu_read_lock(void)
95 {
96
97 kpreempt_disable(); /* implies __insn_barrier */
98 }
99
100 static inline void
101 rcu_read_unlock(void)
102 {
103
104 kpreempt_enable(); /* implies __insn_barrier */
105 }
106
107 #define kfree_rcu(P, F) \
108 _kfree_rcu(&(P)->F, (P))
109
110 #endif /* _LINUX_RCUPDATE_H_ */
111