• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef PREEMPT_H
3 #define PREEMPT_H
4 
5 #include <stdbool.h>
6 
7 #include "bug_on.h"
8 
9 /* This flag contains garbage if preempt_disable_count is 0. */
10 extern __thread int thread_cpu_id;
11 
12 /* Support recursive preemption disabling. */
13 extern __thread int preempt_disable_count;
14 
15 void preempt_disable(void);
16 void preempt_enable(void);
17 
preempt_disable_notrace(void)18 static inline void preempt_disable_notrace(void)
19 {
20 	preempt_disable();
21 }
22 
preempt_enable_no_resched(void)23 static inline void preempt_enable_no_resched(void)
24 {
25 	preempt_enable();
26 }
27 
preempt_enable_notrace(void)28 static inline void preempt_enable_notrace(void)
29 {
30 	preempt_enable();
31 }
32 
preempt_count(void)33 static inline int preempt_count(void)
34 {
35 	return preempt_disable_count;
36 }
37 
preemptible(void)38 static inline bool preemptible(void)
39 {
40 	return !preempt_count();
41 }
42 
get_cpu(void)43 static inline int get_cpu(void)
44 {
45 	preempt_disable();
46 	return thread_cpu_id;
47 }
48 
put_cpu(void)49 static inline void put_cpu(void)
50 {
51 	preempt_enable();
52 }
53 
might_sleep(void)54 static inline void might_sleep(void)
55 {
56 	BUG_ON(preempt_disable_count);
57 }
58 
59 #endif
60