Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / kernel / kthread.c
index 43fa039..c18d7c7 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/unistd.h>
 #include <linux/file.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <asm/semaphore.h>
 
 /*
@@ -41,7 +42,7 @@ struct kthread_stop_info
 
 /* Thread stopping is done by setthing this var: lock serializes
  * multiple kthread_stop calls. */
-static DECLARE_MUTEX(kthread_stop_lock);
+static DEFINE_MUTEX(kthread_stop_lock);
 static struct kthread_stop_info kthread_stop_info;
 
 int kthread_should_stop(void)
@@ -114,7 +115,9 @@ static void keventd_create_kthread(void *_create)
                create->result = ERR_PTR(pid);
        } else {
                wait_for_completion(&create->started);
+               read_lock(&tasklist_lock);
                create->result = find_task_by_real_pid(pid);
+               read_unlock(&tasklist_lock);
        }
        complete(&create->done);
 }
@@ -164,10 +167,16 @@ void kthread_bind(struct task_struct *k, unsigned int cpu)
 EXPORT_SYMBOL(kthread_bind);
 
 int kthread_stop(struct task_struct *k)
+{
+       return kthread_stop_sem(k, NULL);
+}
+EXPORT_SYMBOL(kthread_stop);
+
+int kthread_stop_sem(struct task_struct *k, struct semaphore *s)
 {
        int ret;
 
-       down(&kthread_stop_lock);
+       mutex_lock(&kthread_stop_lock);
 
        /* It could exit after stop_info.k set, but before wake_up_process. */
        get_task_struct(k);
@@ -178,18 +187,21 @@ int kthread_stop(struct task_struct *k)
 
        /* Now set kthread_should_stop() to true, and wake it up. */
        kthread_stop_info.k = k;
-       wake_up_process(k);
+       if (s)
+               up(s);
+       else
+               wake_up_process(k);
        put_task_struct(k);
 
        /* Once it dies, reset stop ptr, gather result and we're done. */
        wait_for_completion(&kthread_stop_info.done);
        kthread_stop_info.k = NULL;
        ret = kthread_stop_info.err;
-       up(&kthread_stop_lock);
+       mutex_unlock(&kthread_stop_lock);
 
        return ret;
 }
-EXPORT_SYMBOL(kthread_stop);
+EXPORT_SYMBOL(kthread_stop_sem);
 
 static __init int helper_init(void)
 {