allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / include / linux / freezer.h
blob5faef846699dc8e6fa07ccddb45f9793b2a67622
1 /* Freezer declarations */
3 #include <linux/sched.h>
5 #ifdef CONFIG_PM
6 /*
7 * Check if a process has been frozen
8 */
9 static inline int frozen(struct task_struct *p)
11 return p->flags & PF_FROZEN;
15 * Check if there is a request to freeze a process
17 static inline int freezing(struct task_struct *p)
19 return test_tsk_thread_flag(p, TIF_FREEZE);
23 * Request that a process be frozen
25 static inline void freeze(struct task_struct *p)
27 set_tsk_thread_flag(p, TIF_FREEZE);
31 * Sometimes we may need to cancel the previous 'freeze' request
33 static inline void do_not_freeze(struct task_struct *p)
35 clear_tsk_thread_flag(p, TIF_FREEZE);
39 * Wake up a frozen process
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.
47 static inline int thaw_process(struct task_struct *p)
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;
56 clear_tsk_thread_flag(p, TIF_FREEZE);
57 task_unlock(p);
58 return 0;
61 extern void refrigerator(void);
62 extern int freeze_processes(void);
63 extern void thaw_processes(void);
65 static inline int try_to_freeze(void)
67 if (freezing(current)) {
68 refrigerator();
69 return 1;
70 } else
71 return 0;
75 * The PF_FREEZER_SKIP flag should be set by a vfork parent right before it
76 * calls wait_for_completion(&vfork) and reset right after it returns from this
77 * function. Next, the parent should call try_to_freeze() to freeze itself
78 * appropriately in case the child has exited before the freezing of tasks is
79 * complete. However, we don't want kernel threads to be frozen in unexpected
80 * places, so we allow them to block freeze_processes() instead or to set
81 * PF_NOFREEZE if needed and PF_FREEZER_SKIP is only set for userland vfork
82 * parents. Fortunately, in the ____call_usermodehelper() case the parent won't
83 * really block freeze_processes(), since ____call_usermodehelper() (the child)
84 * does a little before exec/exit and it can't be frozen before waking up the
85 * parent.
89 * If the current task is a user space one, tell the freezer not to count it as
90 * freezable.
92 static inline void freezer_do_not_count(void)
94 if (current->mm)
95 current->flags |= PF_FREEZER_SKIP;
99 * If the current task is a user space one, tell the freezer to count it as
100 * freezable again and try to freeze it.
102 static inline void freezer_count(void)
104 if (current->mm) {
105 current->flags &= ~PF_FREEZER_SKIP;
106 try_to_freeze();
111 * Check if the task should be counted as freezeable by the freezer
113 static inline int freezer_should_skip(struct task_struct *p)
115 return !!(p->flags & PF_FREEZER_SKIP);
119 * Tell the freezer that the current task should be frozen by it
121 static inline void set_freezable(void)
123 current->flags &= ~PF_NOFREEZE;
126 #else
127 static inline int frozen(struct task_struct *p) { return 0; }
128 static inline int freezing(struct task_struct *p) { return 0; }
129 static inline void freeze(struct task_struct *p) { BUG(); }
130 static inline int thaw_process(struct task_struct *p) { return 1; }
132 static inline void refrigerator(void) {}
133 static inline int freeze_processes(void) { BUG(); return 0; }
134 static inline void thaw_processes(void) {}
136 static inline int try_to_freeze(void) { return 0; }
138 static inline void freezer_do_not_count(void) {}
139 static inline void freezer_count(void) {}
140 static inline int freezer_should_skip(struct task_struct *p) { return 0; }
141 static inline void set_freezable(void) {}
142 #endif