blob: 294ebea859c99b51e79038921834b98ca6620bc2 [file] [log] [blame]
Nigel Cunningham7dfb7102006-12-06 20:34:23 -08001/* Freezer declarations */
2
Nigel Cunninghamff395932006-12-06 20:34:28 -08003#define FREEZER_KERNEL_THREADS 0
4#define FREEZER_ALL_THREADS 1
5
Nigel Cunningham7dfb7102006-12-06 20:34:23 -08006#ifdef CONFIG_PM
7/*
8 * Check if a process has been frozen
9 */
10static inline int frozen(struct task_struct *p)
11{
12 return p->flags & PF_FROZEN;
13}
14
15/*
16 * Check if there is a request to freeze a process
17 */
18static inline int freezing(struct task_struct *p)
19{
20 return p->flags & PF_FREEZE;
21}
22
23/*
24 * Request that a process be frozen
25 * FIXME: SMP problem. We may not modify other process' flags!
26 */
27static inline void freeze(struct task_struct *p)
28{
29 p->flags |= PF_FREEZE;
30}
31
32/*
33 * Sometimes we may need to cancel the previous 'freeze' request
34 */
35static inline void do_not_freeze(struct task_struct *p)
36{
37 p->flags &= ~PF_FREEZE;
38}
39
40/*
41 * Wake up a frozen process
42 */
43static inline int thaw_process(struct task_struct *p)
44{
45 if (frozen(p)) {
46 p->flags &= ~PF_FROZEN;
47 wake_up_process(p);
48 return 1;
49 }
50 return 0;
51}
52
53/*
54 * freezing is complete, mark process as frozen
55 */
56static inline void frozen_process(struct task_struct *p)
57{
58 p->flags = (p->flags & ~PF_FREEZE) | PF_FROZEN;
59}
60
61extern void refrigerator(void);
62extern int freeze_processes(void);
Nigel Cunninghamff395932006-12-06 20:34:28 -080063#define thaw_processes() do { thaw_some_processes(FREEZER_ALL_THREADS); } while(0)
64#define thaw_kernel_threads() do { thaw_some_processes(FREEZER_KERNEL_THREADS); } while(0)
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080065
66static inline int try_to_freeze(void)
67{
68 if (freezing(current)) {
69 refrigerator();
70 return 1;
71 } else
72 return 0;
73}
Nigel Cunninghamff395932006-12-06 20:34:28 -080074
75extern void thaw_some_processes(int all);
76
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080077#else
78static inline int frozen(struct task_struct *p) { return 0; }
79static inline int freezing(struct task_struct *p) { return 0; }
80static inline void freeze(struct task_struct *p) { BUG(); }
81static inline int thaw_process(struct task_struct *p) { return 1; }
82static inline void frozen_process(struct task_struct *p) { BUG(); }
83
84static inline void refrigerator(void) {}
85static inline int freeze_processes(void) { BUG(); return 0; }
86static inline void thaw_processes(void) {}
87
88static inline int try_to_freeze(void) { return 0; }
89
90
91#endif