]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/linux/freezer.h
freezer: close potential race between refrigerator and thaw_tasks
[linux-2.6-omap-h63xx.git] / include / linux / freezer.h
1 /* Freezer declarations */
2
3 #include <linux/sched.h>
4
5 #ifdef CONFIG_PM
6 /*
7  * Check if a process has been frozen
8  */
9 static inline int frozen(struct task_struct *p)
10 {
11         return p->flags & PF_FROZEN;
12 }
13
14 /*
15  * Check if there is a request to freeze a process
16  */
17 static inline int freezing(struct task_struct *p)
18 {
19         return test_tsk_thread_flag(p, TIF_FREEZE);
20 }
21
22 /*
23  * Request that a process be frozen
24  */
25 static inline void freeze(struct task_struct *p)
26 {
27         set_tsk_thread_flag(p, TIF_FREEZE);
28 }
29
30 /*
31  * Sometimes we may need to cancel the previous 'freeze' request
32  */
33 static inline void do_not_freeze(struct task_struct *p)
34 {
35         clear_tsk_thread_flag(p, TIF_FREEZE);
36 }
37
38 /*
39  * Wake up a frozen process
40  *
41  * task_lock() is taken to prevent the race with refrigerator() which may
42  * occur if the freezing of tasks fails.  Namely, without the lock, if the
43  * freezing of tasks failed, thaw_tasks() might have run before a task in
44  * refrigerator() could call frozen_process(), in which case the task would be
45  * frozen and no one would thaw it.
46  */
47 static inline int thaw_process(struct task_struct *p)
48 {
49         task_lock(p);
50         if (frozen(p)) {
51                 p->flags &= ~PF_FROZEN;
52                 task_unlock(p);
53                 wake_up_process(p);
54                 return 1;
55         }
56         clear_tsk_thread_flag(p, TIF_FREEZE);
57         task_unlock(p);
58         return 0;
59 }
60
61 /*
62  * freezing is complete, mark process as frozen
63  */
64 static inline void frozen_process(struct task_struct *p)
65 {
66         p->flags |= PF_FROZEN;
67         wmb();
68         clear_tsk_thread_flag(p, TIF_FREEZE);
69 }
70
71 extern void refrigerator(void);
72 extern int freeze_processes(void);
73 extern void thaw_processes(void);
74
75 static inline int try_to_freeze(void)
76 {
77         if (freezing(current)) {
78                 refrigerator();
79                 return 1;
80         } else
81                 return 0;
82 }
83
84 extern void thaw_some_processes(int all);
85
86 #else
87 static inline int frozen(struct task_struct *p) { return 0; }
88 static inline int freezing(struct task_struct *p) { return 0; }
89 static inline void freeze(struct task_struct *p) { BUG(); }
90 static inline int thaw_process(struct task_struct *p) { return 1; }
91 static inline void frozen_process(struct task_struct *p) { BUG(); }
92
93 static inline void refrigerator(void) {}
94 static inline int freeze_processes(void) { BUG(); return 0; }
95 static inline void thaw_processes(void) {}
96
97 static inline int try_to_freeze(void) { return 0; }
98
99
100 #endif