blob: d0926d63406ca8e76a3d89ddc3f307a43ef6f391 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __LINUX_PREEMPT_H
2#define __LINUX_PREEMPT_H
3
4/*
5 * include/linux/preempt.h - macros for accessing and manipulating
6 * preempt_count (used for kernel preemption, interrupt count, etc.)
7 */
8
Al Virof0373602005-11-13 16:06:57 -08009#include <linux/thread_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/linkage.h>
11
12#ifdef CONFIG_DEBUG_PREEMPT
13 extern void fastcall add_preempt_count(int val);
14 extern void fastcall sub_preempt_count(int val);
15#else
16# define add_preempt_count(val) do { preempt_count() += (val); } while (0)
17# define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
18#endif
19
20#define inc_preempt_count() add_preempt_count(1)
21#define dec_preempt_count() sub_preempt_count(1)
22
23#define preempt_count() (current_thread_info()->preempt_count)
24
25#ifdef CONFIG_PREEMPT
26
27asmlinkage void preempt_schedule(void);
28
29#define preempt_disable() \
30do { \
31 inc_preempt_count(); \
32 barrier(); \
33} while (0)
34
35#define preempt_enable_no_resched() \
36do { \
37 barrier(); \
38 dec_preempt_count(); \
39} while (0)
40
41#define preempt_check_resched() \
42do { \
43 if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
44 preempt_schedule(); \
45} while (0)
46
47#define preempt_enable() \
48do { \
49 preempt_enable_no_resched(); \
Nicolas Pitred6f02912005-12-21 12:26:25 -050050 barrier(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 preempt_check_resched(); \
52} while (0)
53
54#else
55
56#define preempt_disable() do { } while (0)
57#define preempt_enable_no_resched() do { } while (0)
58#define preempt_enable() do { } while (0)
59#define preempt_check_resched() do { } while (0)
60
61#endif
62
63#endif /* __LINUX_PREEMPT_H */