Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 1 | /* Freezer declarations */ |
| 2 | |
Randy Dunlap | 5c543ef | 2006-12-10 02:18:58 -0800 | [diff] [blame] | 3 | #include <linux/sched.h> |
| 4 | |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 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 | { |
Rafael J. Wysocki | 8a102ee | 2006-12-13 00:34:30 -0800 | [diff] [blame] | 19 | return test_tsk_thread_flag(p, TIF_FREEZE); |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | /* |
| 23 | * Request that a process be frozen |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 24 | */ |
| 25 | static inline void freeze(struct task_struct *p) |
| 26 | { |
Rafael J. Wysocki | 8a102ee | 2006-12-13 00:34:30 -0800 | [diff] [blame] | 27 | set_tsk_thread_flag(p, TIF_FREEZE); |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 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 | { |
Rafael J. Wysocki | 8a102ee | 2006-12-13 00:34:30 -0800 | [diff] [blame] | 35 | clear_tsk_thread_flag(p, TIF_FREEZE); |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | /* |
| 39 | * Wake up a frozen process |
| 40 | */ |
| 41 | static inline int thaw_process(struct task_struct *p) |
| 42 | { |
| 43 | if (frozen(p)) { |
| 44 | p->flags &= ~PF_FROZEN; |
| 45 | wake_up_process(p); |
| 46 | return 1; |
| 47 | } |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * freezing is complete, mark process as frozen |
| 53 | */ |
| 54 | static inline void frozen_process(struct task_struct *p) |
| 55 | { |
Rafael J. Wysocki | 8a102ee | 2006-12-13 00:34:30 -0800 | [diff] [blame] | 56 | p->flags |= PF_FROZEN; |
| 57 | wmb(); |
| 58 | clear_tsk_thread_flag(p, TIF_FREEZE); |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | extern void refrigerator(void); |
| 62 | extern int freeze_processes(void); |
Rafael J. Wysocki | a9b6f56 | 2006-12-06 20:34:37 -0800 | [diff] [blame] | 63 | extern void thaw_processes(void); |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 64 | |
| 65 | static inline int try_to_freeze(void) |
| 66 | { |
| 67 | if (freezing(current)) { |
| 68 | refrigerator(); |
| 69 | return 1; |
| 70 | } else |
| 71 | return 0; |
| 72 | } |
Nigel Cunningham | ff39593 | 2006-12-06 20:34:28 -0800 | [diff] [blame] | 73 | |
| 74 | extern void thaw_some_processes(int all); |
| 75 | |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 76 | #else |
| 77 | static inline int frozen(struct task_struct *p) { return 0; } |
| 78 | static inline int freezing(struct task_struct *p) { return 0; } |
| 79 | static inline void freeze(struct task_struct *p) { BUG(); } |
| 80 | static inline int thaw_process(struct task_struct *p) { return 1; } |
| 81 | static inline void frozen_process(struct task_struct *p) { BUG(); } |
| 82 | |
| 83 | static inline void refrigerator(void) {} |
| 84 | static inline int freeze_processes(void) { BUG(); return 0; } |
| 85 | static inline void thaw_processes(void) {} |
| 86 | |
| 87 | static inline int try_to_freeze(void) { return 0; } |
| 88 | |
| 89 | |
| 90 | #endif |