Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * RCU-based infrastructure for lightweight reader-writer locking
0004  *
0005  * Copyright (c) 2015, Red Hat, Inc.
0006  *
0007  * Author: Oleg Nesterov <oleg@redhat.com>
0008  */
0009 
0010 #ifndef _LINUX_RCU_SYNC_H_
0011 #define _LINUX_RCU_SYNC_H_
0012 
0013 #include <linux/wait.h>
0014 #include <linux/rcupdate.h>
0015 
0016 /* Structure to mediate between updaters and fastpath-using readers.  */
0017 struct rcu_sync {
0018     int         gp_state;
0019     int         gp_count;
0020     wait_queue_head_t   gp_wait;
0021 
0022     struct rcu_head     cb_head;
0023 };
0024 
0025 /**
0026  * rcu_sync_is_idle() - Are readers permitted to use their fastpaths?
0027  * @rsp: Pointer to rcu_sync structure to use for synchronization
0028  *
0029  * Returns true if readers are permitted to use their fastpaths.  Must be
0030  * invoked within some flavor of RCU read-side critical section.
0031  */
0032 static inline bool rcu_sync_is_idle(struct rcu_sync *rsp)
0033 {
0034     RCU_LOCKDEP_WARN(!rcu_read_lock_any_held(),
0035              "suspicious rcu_sync_is_idle() usage");
0036     return !READ_ONCE(rsp->gp_state); /* GP_IDLE */
0037 }
0038 
0039 extern void rcu_sync_init(struct rcu_sync *);
0040 extern void rcu_sync_enter_start(struct rcu_sync *);
0041 extern void rcu_sync_enter(struct rcu_sync *);
0042 extern void rcu_sync_exit(struct rcu_sync *);
0043 extern void rcu_sync_dtor(struct rcu_sync *);
0044 
0045 #define __RCU_SYNC_INITIALIZER(name) {                  \
0046         .gp_state = 0,                      \
0047         .gp_count = 0,                      \
0048         .gp_wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.gp_wait), \
0049     }
0050 
0051 #define DEFINE_RCU_SYNC(name)   \
0052     struct rcu_sync name = __RCU_SYNC_INITIALIZER(name)
0053 
0054 #endif /* _LINUX_RCU_SYNC_H_ */