recalc_sigpending_tsk fixes
[sfrench/cifs-2.6.git] / kernel / power / process.c
index 99eeb119b06db1d350d04de044fdb624f4627a19..e0233d8422b9ed4ec9d62ce1f54bd65165931daa 100644 (file)
@@ -8,7 +8,6 @@
 
 #undef DEBUG
 
-#include <linux/smp_lock.h>
 #include <linux/interrupt.h>
 #include <linux/suspend.h>
 #include <linux/module.h>
 
 static inline int freezeable(struct task_struct * p)
 {
-       if ((p == current) || 
+       if ((p == current) ||
            (p->flags & PF_NOFREEZE) ||
-           (p->exit_state == EXIT_ZOMBIE) ||
-           (p->exit_state == EXIT_DEAD) ||
-           (p->state == TASK_STOPPED))
+           (p->exit_state != 0))
                return 0;
        return 1;
 }
 
+/*
+ * freezing is complete, mark current process as frozen
+ */
+static inline void frozen_process(void)
+{
+       if (!unlikely(current->flags & PF_NOFREEZE)) {
+               current->flags |= PF_FROZEN;
+               wmb();
+       }
+       clear_tsk_thread_flag(current, TIF_FREEZE);
+}
+
 /* Refrigerator is place where frozen processes are stored :-). */
 void refrigerator(void)
 {
        /* Hmm, should we be allowed to suspend when there are realtime
           processes around? */
        long save;
+
+       task_lock(current);
+       if (freezing(current)) {
+               frozen_process();
+               task_unlock(current);
+       } else {
+               task_unlock(current);
+               return;
+       }
        save = current->state;
        pr_debug("%s entered refrigerator\n", current->comm);
 
-       frozen_process(current);
        spin_lock_irq(&current->sighand->siglock);
        recalc_sigpending(); /* We sent fake signal, clean it up */
        spin_unlock_irq(&current->sighand->siglock);
 
-       while (frozen(current)) {
-               current->state = TASK_UNINTERRUPTIBLE;
+       for (;;) {
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               if (!frozen(current))
+                       break;
                schedule();
        }
        pr_debug("%s left refrigerator\n", current->comm);
@@ -61,10 +80,16 @@ static inline void freeze_process(struct task_struct *p)
        unsigned long flags;
 
        if (!freezing(p)) {
-               freeze(p);
-               spin_lock_irqsave(&p->sighand->siglock, flags);
-               signal_wake_up(p, 0);
-               spin_unlock_irqrestore(&p->sighand->siglock, flags);
+               rmb();
+               if (!frozen(p)) {
+                       if (p->state == TASK_STOPPED)
+                               force_sig_specific(SIGSTOP, p);
+
+                       freeze(p);
+                       spin_lock_irqsave(&p->sighand->siglock, flags);
+                       signal_wake_up(p, p->state == TASK_STOPPED);
+                       spin_unlock_irqrestore(&p->sighand->siglock, flags);
+               }
        }
 }
 
@@ -76,7 +101,7 @@ static void cancel_freezing(struct task_struct *p)
                pr_debug("  clean up: %s\n", p->comm);
                do_not_freeze(p);
                spin_lock_irqsave(&p->sighand->siglock, flags);
-               recalc_sigpending_tsk(p);
+               recalc_sigpending_and_wake(p);
                spin_unlock_irqrestore(&p->sighand->siglock, flags);
        }
 }
@@ -103,28 +128,16 @@ static unsigned int try_to_freeze_tasks(int freeze_user_space)
                        if (frozen(p))
                                continue;
 
-                       if (p->state == TASK_TRACED &&
-                           (frozen(p->parent) ||
-                            p->parent->state == TASK_STOPPED)) {
+                       if (p->state == TASK_TRACED && frozen(p->parent)) {
                                cancel_freezing(p);
                                continue;
                        }
-                       if (is_user_space(p)) {
-                               if (!freeze_user_space)
-                                       continue;
-
-                               /* Freeze the task unless there is a vfork
-                                * completion pending
-                                */
-                               if (!p->vfork_done)
-                                       freeze_process(p);
-                       } else {
-                               if (freeze_user_space)
-                                       continue;
-
-                               freeze_process(p);
-                       }
-                       todo++;
+                       if (freeze_user_space && !is_user_space(p))
+                               continue;
+
+                       freeze_process(p);
+                       if (!freezer_should_skip(p))
+                               todo++;
                } while_each_thread(g, p);
                read_unlock(&tasklist_lock);
                yield();                        /* Yield is okay here */
@@ -146,13 +159,16 @@ static unsigned int try_to_freeze_tasks(int freeze_user_space)
                                TIMEOUT / HZ, todo);
                read_lock(&tasklist_lock);
                do_each_thread(g, p) {
-                       if (is_user_space(p) == !freeze_user_space)
+                       if (freeze_user_space && !is_user_space(p))
                                continue;
 
-                       if (freezeable(p) && !frozen(p))
+                       task_lock(p);
+                       if (freezeable(p) && !frozen(p) &&
+                           !freezer_should_skip(p))
                                printk(KERN_ERR " %s\n", p->comm);
 
                        cancel_freezing(p);
+                       task_unlock(p);
                } while_each_thread(g, p);
                read_unlock(&tasklist_lock);
        }
@@ -197,9 +213,7 @@ static void thaw_tasks(int thaw_user_space)
                if (is_user_space(p) == !thaw_user_space)
                        continue;
 
-               if (!thaw_process(p))
-                       printk(KERN_WARNING " Strange, %s not stopped\n",
-                               p->comm );
+               thaw_process(p);
        } while_each_thread(g, p);
        read_unlock(&tasklist_lock);
 }