]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/compat/linuxkpi/common/include/linux/rcupdate.h
Update Apache Serf to 1.3.9 to support OpenSSL 1.1.1.
[FreeBSD/FreeBSD.git] / sys / compat / linuxkpi / common / include / linux / rcupdate.h
1 /*-
2  * Copyright (c) 2016-2017 Mellanox Technologies, Ltd.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 #ifndef _LINUX_RCUPDATE_H_
29 #define _LINUX_RCUPDATE_H_
30
31 #include <linux/compiler.h>
32 #include <linux/types.h>
33
34 #include <machine/atomic.h>
35
36 #define LINUX_KFREE_RCU_OFFSET_MAX      4096    /* exclusive */
37
38 #define RCU_INITIALIZER(v)                      \
39         ((__typeof(*(v)) *)(v))
40
41 #define RCU_INIT_POINTER(p, v) do {             \
42         (p) = (v);                              \
43 } while (0)
44
45 #define call_rcu(ptr, func) do {                \
46         linux_call_rcu(ptr, func);              \
47 } while (0)
48
49 #define rcu_barrier(void) do {                  \
50         linux_rcu_barrier();                    \
51 } while (0)
52
53 #define rcu_read_lock(void) do {                \
54         linux_rcu_read_lock();                  \
55 } while (0)
56
57 #define rcu_read_unlock(void) do {              \
58         linux_rcu_read_unlock();                \
59 } while (0)
60
61 #define synchronize_rcu(void) do {      \
62         linux_synchronize_rcu();        \
63 } while (0)
64
65 #define synchronize_rcu_expedited(void) do {    \
66         linux_synchronize_rcu();                \
67 } while (0)
68
69 #define kfree_rcu(ptr, rcu_head) do {                           \
70         CTASSERT(offsetof(__typeof(*(ptr)), rcu_head) <         \
71             LINUX_KFREE_RCU_OFFSET_MAX);                        \
72         call_rcu(&(ptr)->rcu_head, (rcu_callback_t)(uintptr_t)  \
73             offsetof(__typeof(*(ptr)), rcu_head));              \
74 } while (0)
75
76 #define rcu_access_pointer(p)                   \
77         ((__typeof(*p) *)READ_ONCE(p))
78
79 #define rcu_dereference_protected(p, c)         \
80         ((__typeof(*p) *)READ_ONCE(p))
81
82 #define rcu_dereference(p)                      \
83         rcu_dereference_protected(p, 0)
84
85 #define rcu_dereference_raw(p)                  \
86         ((__typeof(*p) *)READ_ONCE(p))
87
88 #define rcu_pointer_handoff(p) (p)
89
90 #define rcu_assign_pointer(p, v) do {                           \
91         atomic_store_rel_ptr((volatile uintptr_t *)&(p),        \
92             (uintptr_t)(v));                                    \
93 } while (0)
94
95 /* prototypes */
96
97 extern void linux_call_rcu(struct rcu_head *ptr, rcu_callback_t func);
98 extern void linux_rcu_barrier(void);
99 extern void linux_rcu_read_lock(void);
100 extern void linux_rcu_read_unlock(void);
101 extern void linux_synchronize_rcu(void);
102
103 #endif                                  /* _LINUX_RCUPDATE_H_ */