rcu_sync.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * RCU-based infrastructure for lightweight reader-writer locking
  4. *
  5. * Copyright (c) 2015, Red Hat, Inc.
  6. *
  7. * Author: Oleg Nesterov <[email protected]>
  8. */
  9. #ifndef _LINUX_RCU_SYNC_H_
  10. #define _LINUX_RCU_SYNC_H_
  11. #include <linux/wait.h>
  12. #include <linux/rcupdate.h>
  13. /* Structure to mediate between updaters and fastpath-using readers. */
  14. struct rcu_sync {
  15. int gp_state;
  16. int gp_count;
  17. wait_queue_head_t gp_wait;
  18. struct rcu_head cb_head;
  19. };
  20. /**
  21. * rcu_sync_is_idle() - Are readers permitted to use their fastpaths?
  22. * @rsp: Pointer to rcu_sync structure to use for synchronization
  23. *
  24. * Returns true if readers are permitted to use their fastpaths. Must be
  25. * invoked within some flavor of RCU read-side critical section.
  26. */
  27. static inline bool rcu_sync_is_idle(struct rcu_sync *rsp)
  28. {
  29. RCU_LOCKDEP_WARN(!rcu_read_lock_any_held(),
  30. "suspicious rcu_sync_is_idle() usage");
  31. return !READ_ONCE(rsp->gp_state); /* GP_IDLE */
  32. }
  33. extern void rcu_sync_init(struct rcu_sync *);
  34. extern void rcu_sync_enter_start(struct rcu_sync *);
  35. extern void rcu_sync_enter(struct rcu_sync *);
  36. extern void rcu_sync_exit(struct rcu_sync *);
  37. extern void rcu_sync_dtor(struct rcu_sync *);
  38. #define __RCU_SYNC_INITIALIZER(name) { \
  39. .gp_state = 0, \
  40. .gp_count = 0, \
  41. .gp_wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.gp_wait), \
  42. }
  43. #define DEFINE_RCU_SYNC(name) \
  44. struct rcu_sync name = __RCU_SYNC_INITIALIZER(name)
  45. #endif /* _LINUX_RCU_SYNC_H_ */