rcupdate.h revision 302408
1/*-
2 * Copyright (c) 2016 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: stable/11/sys/compat/linuxkpi/common/include/linux/rcupdate.h 294837 2016-01-26 15:12:31Z hselasky $
27 */
28#ifndef	_LINUX_RCUPDATE_H_
29#define	_LINUX_RCUPDATE_H_
30
31#include <sys/param.h>
32#include <sys/lock.h>
33#include <sys/sx.h>
34
35extern struct sx linux_global_rcu_lock;
36
37struct rcu_head {
38};
39
40typedef void (*rcu_callback_t)(struct rcu_head *);
41
42static inline void
43call_rcu(struct rcu_head *ptr, rcu_callback_t func)
44{
45	sx_xlock(&linux_global_rcu_lock);
46	func(ptr);
47	sx_xunlock(&linux_global_rcu_lock);
48}
49
50static inline void
51rcu_read_lock(void)
52{
53	sx_slock(&linux_global_rcu_lock);
54}
55
56static inline void
57rcu_read_unlock(void)
58{
59	sx_sunlock(&linux_global_rcu_lock);
60}
61
62static inline void
63rcu_barrier(void)
64{
65	sx_xlock(&linux_global_rcu_lock);
66	sx_xunlock(&linux_global_rcu_lock);
67}
68
69static inline void
70synchronize_rcu(void)
71{
72	sx_xlock(&linux_global_rcu_lock);
73	sx_xunlock(&linux_global_rcu_lock);
74}
75
76#define	hlist_add_head_rcu(n, h)		\
77do {						\
78  	sx_xlock(&linux_global_rcu_lock);	\
79	hlist_add_head(n, h);			\
80	sx_xunlock(&linux_global_rcu_lock);	\
81} while (0)
82
83#define	hlist_del_init_rcu(n)			\
84do {						\
85    	sx_xlock(&linux_global_rcu_lock);	\
86	hlist_del_init(n);			\
87	sx_xunlock(&linux_global_rcu_lock);	\
88} while (0)
89
90#define	hlist_del_rcu(n)			\
91do {						\
92    	sx_xlock(&linux_global_rcu_lock);	\
93	hlist_del(n);				\
94	sx_xunlock(&linux_global_rcu_lock);	\
95} while (0)
96
97#endif					/* _LINUX_RCUPDATE_H_ */
98