kthread: add kthread_destroy_worker()
[deliverable/linux.git] / kernel / kthread.c
index d9ba5e229cd33c3095219b631e83bad1119546a7..3dc7f26d84d72198250042ca1539eef03c78175e 100644 (file)
@@ -819,3 +819,26 @@ void kthread_flush_worker(struct kthread_worker *worker)
        wait_for_completion(&fwork.done);
 }
 EXPORT_SYMBOL_GPL(kthread_flush_worker);
+
+/**
+ * kthread_destroy_worker - destroy a kthread worker
+ * @worker: worker to be destroyed
+ *
+ * Flush and destroy @worker.  The simple flush is enough because the kthread
+ * worker API is used only in trivial scenarios.  There are no multi-step state
+ * machines needed.
+ */
+void kthread_destroy_worker(struct kthread_worker *worker)
+{
+       struct task_struct *task;
+
+       task = worker->task;
+       if (WARN_ON(!task))
+               return;
+
+       kthread_flush_worker(worker);
+       kthread_stop(task);
+       WARN_ON(!list_empty(&worker->work_list));
+       kfree(worker);
+}
+EXPORT_SYMBOL(kthread_destroy_worker);
This page took 0.023224 seconds and 5 git commands to generate.