Home | History | Annotate | Line # | Download | only in linux
rcupdate.h revision 1.3
      1 /*	$NetBSD: rcupdate.h,v 1.3 2021/12/19 09:48:29 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 #include <linux/bug.h>
     40 
     41 #define	__rcu
     42 
     43 #define	RCU_INIT_POINTER(P, V)	((P) = (V))
     44 
     45 #define	rcu_assign_pointer(P, V) do {					      \
     46 	__typeof__(*(P)) *__rcu_assign_pointer_tmp = (V);		      \
     47 	membar_exit();							      \
     48 	(P) = __rcu_assign_pointer_tmp;					      \
     49 } while (0)
     50 
     51 #define	rcu_dereference(P) ({						      \
     52 	__typeof__(*(P)) *__rcu_dereference_tmp = (P);			      \
     53 	membar_datadep_consumer();					      \
     54 	__rcu_dereference_tmp;						      \
     55 })
     56 
     57 #define	rcu_dereference_raw	rcu_dereference
     58 
     59 #define	rcu_dereference_protected(P, C) ({				      \
     60 	WARN_ON(!(C));							      \
     61 	(P);								      \
     62 })
     63 
     64 #define	rcu_access_pointer(P) ({					      \
     65 	__typeof__(*(P)) *__rcu_access_pointer_tmp = (P);		      \
     66 	__insn_barrier();						      \
     67 	__rcu_access_pointer_tmp;					      \
     68 })
     69 
     70 /* kill_dependency */
     71 #define	rcu_pointer_handoff(P)	(P)
     72 
     73 struct rcu_head {
     74 	union {
     75 		void		(*callback)(struct rcu_head *);
     76 		void		*obj;
     77 	}		rcuh_u;
     78 	struct rcu_head	*rcuh_next;
     79 };
     80 
     81 #define	_kfree_rcu		linux__kfree_rcu
     82 #define	call_rcu		linux_call_rcu
     83 #define	rcu_barrier		linux_rcu_barrier
     84 #define	synchronize_rcu		linux_synchronize_rcu
     85 
     86 int	linux_rcu_gc_init(void);
     87 void	linux_rcu_gc_fini(void);
     88 
     89 void	call_rcu(struct rcu_head *, void (*)(struct rcu_head *));
     90 void	rcu_barrier(void);
     91 void	synchronize_rcu(void);
     92 
     93 void	_kfree_rcu(struct rcu_head *, void *);
     94 
     95 static inline void
     96 rcu_read_lock(void)
     97 {
     98 
     99 	kpreempt_disable();	/* implies __insn_barrier */
    100 }
    101 
    102 static inline void
    103 rcu_read_unlock(void)
    104 {
    105 
    106 	kpreempt_enable();	/* implies __insn_barrier */
    107 }
    108 
    109 #define	kfree_rcu(P, F)							      \
    110 	_kfree_rcu(&(P)->F, (P))
    111 
    112 #endif  /* _LINUX_RCUPDATE_H_ */
    113