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$ 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 35 extern struct sx linux_global_rcu_lock; 36 37 struct rcu_head { 38 }; 39 40 typedef void (*rcu_callback_t)(struct rcu_head *); 41 42 static inline void 43 call_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 50 static inline void 51 rcu_read_lock(void) 52 { 53 sx_slock(&linux_global_rcu_lock); 54 } 55 56 static inline void 57 rcu_read_unlock(void) 58 { 59 sx_sunlock(&linux_global_rcu_lock); 60 } 61 62 static inline void 63 rcu_barrier(void) 64 { 65 sx_xlock(&linux_global_rcu_lock); 66 sx_xunlock(&linux_global_rcu_lock); 67 } 68 69 static inline void 70 synchronize_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) \ 77 do { \ 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) \ 84 do { \ 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) \ 91 do { \ 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