Blame view

include/linux/rcuwait.h 1.23 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
8f95c90ce   Davidlohr Bueso   sched/wait, RCU: ...
2
3
4
5
6
7
8
  #ifndef _LINUX_RCUWAIT_H_
  #define _LINUX_RCUWAIT_H_
  
  #include <linux/rcupdate.h>
  
  /*
   * rcuwait provides a way of blocking and waking up a single
154abafc6   Eric W. Biederman   tasks, sched/core...
9
   * task in an rcu-safe manner.
8f95c90ce   Davidlohr Bueso   sched/wait, RCU: ...
10
   *
154abafc6   Eric W. Biederman   tasks, sched/core...
11
12
13
   * The only time @task is non-nil is when a user is blocked (or
   * checking if it needs to) on a condition, and reset as soon as we
   * know that the condition has succeeded and are awoken.
8f95c90ce   Davidlohr Bueso   sched/wait, RCU: ...
14
15
   */
  struct rcuwait {
03f4b48ed   Joel Fernandes (Google)   rcuwait: Annotate...
16
  	struct task_struct __rcu *task;
8f95c90ce   Davidlohr Bueso   sched/wait, RCU: ...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  };
  
  #define __RCUWAIT_INITIALIZER(name)		\
  	{ .task = NULL, }
  
  static inline void rcuwait_init(struct rcuwait *w)
  {
  	w->task = NULL;
  }
  
  extern void rcuwait_wake_up(struct rcuwait *w);
  
  /*
   * The caller is responsible for locking around rcuwait_wait_event(),
   * such that writes to @task are properly serialized.
   */
  #define rcuwait_wait_event(w, condition)				\
  ({									\
8f95c90ce   Davidlohr Bueso   sched/wait, RCU: ...
35
36
37
38
  	rcu_assign_pointer((w)->task, current);				\
  	for (;;) {							\
  		/*							\
  		 * Implicit barrier (A) pairs with (B) in		\
7e1f9467d   Davidlohr Bueso   sched/wait, rcuwa...
39
  		 * rcuwait_wake_up().					\
8f95c90ce   Davidlohr Bueso   sched/wait, RCU: ...
40
41
42
43
44
45
46
47
48
49
50
51
52
  		 */							\
  		set_current_state(TASK_UNINTERRUPTIBLE);		\
  		if (condition)						\
  			break;						\
  									\
  		schedule();						\
  	}								\
  									\
  	WRITE_ONCE((w)->task, NULL);					\
  	__set_current_state(TASK_RUNNING);				\
  })
  
  #endif /* _LINUX_RCUWAIT_H_ */