Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1423957 > unrolled thread

[PATCH v9 07/12] kthread: Add kthread_destroy_worker()

Started byPetr Mladek <pmladek@suse.com>
First post2016-06-16 13:20 +0200
Last post2016-06-20 22:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v9 07/12] kthread: Add kthread_destroy_worker() Petr Mladek <pmladek@suse.com> - 2016-06-16 13:20 +0200
    Re: [PATCH v9 07/12] kthread: Add kthread_destroy_worker() Tejun Heo <tj@kernel.org> - 2016-06-20 22:00 +0200

#1423957 — [PATCH v9 07/12] kthread: Add kthread_destroy_worker()

FromPetr Mladek <pmladek@suse.com>
Date2016-06-16 13:20 +0200
Subject[PATCH v9 07/12] kthread: Add kthread_destroy_worker()
Message-ID<rKDv4-7Hj-23@gated-at.bofh.it>
The current kthread worker users call flush() and stop() explicitly.
This function drains the worker, stops it, and frees the kthread_worker
struct in one call.

It is supposed to be used together with kthread_create_worker*() that
allocates struct kthread_worker.

Also note that drain() correctly handles self-queuing works in compare
with flush().

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 include/linux/kthread.h |  2 ++
 kernel/kthread.c        | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index c889b653f8cb..b2c4dcea8f51 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -137,4 +137,6 @@ void kthread_flush_work(struct kthread_work *work);
 void kthread_flush_worker(struct kthread_worker *worker);
 void kthread_drain_worker(struct kthread_worker *worker);
 
+void kthread_destroy_worker(struct kthread_worker *worker);
+
 #endif /* _LINUX_KTHREAD_H */
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 4454b1267718..567ec49b4872 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -853,3 +853,24 @@ void kthread_drain_worker(struct kthread_worker *worker)
 	spin_unlock_irq(&worker->lock);
 }
 EXPORT_SYMBOL(kthread_drain_worker);
+
+/**
+ * kthread_destroy_worker - destroy a kthread worker
+ * @worker: worker to be destroyed
+ *
+ * Drain and destroy @worker.  It has the same conditions
+ * for use as kthread_drain_worker(), see above.
+ */
+void kthread_destroy_worker(struct kthread_worker *worker)
+{
+	struct task_struct *task;
+
+	task = worker->task;
+	if (WARN_ON(!task))
+		return;
+
+	kthread_drain_worker(worker);
+	kthread_stop(task);
+	kfree(worker);
+}
+EXPORT_SYMBOL(kthread_destroy_worker);
-- 
1.8.5.6

[toc] | [next] | [standalone]


#1426984

FromTejun Heo <tj@kernel.org>
Date2016-06-20 22:00 +0200
Message-ID<rMdwu-44L-45@gated-at.bofh.it>
In reply to#1423957
On Thu, Jun 16, 2016 at 01:17:26PM +0200, Petr Mladek wrote:
> The current kthread worker users call flush() and stop() explicitly.
> This function drains the worker, stops it, and frees the kthread_worker
> struct in one call.
> 
> It is supposed to be used together with kthread_create_worker*() that
> allocates struct kthread_worker.
> 
> Also note that drain() correctly handles self-queuing works in compare
> with flush().
> 
> Signed-off-by: Petr Mladek <pmladek@suse.com>

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web