]> git.ipfire.org Git - thirdparty/kernel/linux.git/blob - tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[thirdparty/kernel/linux.git] / tools / testing / selftests / rcutorture / formal / srcu-cbmc / src / preempt.h
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
18 static inline void preempt_disable_notrace(void)
19 {
20 preempt_disable();
21 }
22
23 static inline void preempt_enable_no_resched(void)
24 {
25 preempt_enable();
26 }
27
28 static inline void preempt_enable_notrace(void)
29 {
30 preempt_enable();
31 }
32
33 static inline int preempt_count(void)
34 {
35 return preempt_disable_count;
36 }
37
38 static inline bool preemptible(void)
39 {
40 return !preempt_count();
41 }
42
43 static inline int get_cpu(void)
44 {
45 preempt_disable();
46 return thread_cpu_id;
47 }
48
49 static inline void put_cpu(void)
50 {
51 preempt_enable();
52 }
53
54 static inline void might_sleep(void)
55 {
56 BUG_ON(preempt_disable_count);
57 }
58
59 #endif