summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/preempt.h
blob: f8b762cd214cb59520e447548014cd8220b72f24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef PREEMPT_H
#define PREEMPT_H

#include <stdbool.h>

#include "bug_on.h"

/* This flag contains garbage if preempt_disable_count is 0. */
extern __thread int thread_cpu_id;

/* Support recursive preemption disabling. */
extern __thread int preempt_disable_count;

void preempt_disable(void);
void preempt_enable(void);

static inline void preempt_disable_notrace(void)
{
	preempt_disable();
}

static inline void preempt_enable_no_resched(void)
{
	preempt_enable();
}

static inline void preempt_enable_notrace(void)
{
	preempt_enable();
}

static inline int preempt_count(void)
{
	return preempt_disable_count;
}

static inline bool preemptible(void)
{
	return !preempt_count();
}

static inline int get_cpu(void)
{
	preempt_disable();
	return thread_cpu_id;
}

static inline void put_cpu(void)
{
	preempt_enable();
}

static inline void might_sleep(void)
{
	BUG_ON(preempt_disable_count);
}

#endif