Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932994AbbKRN0n (ORCPT ); Wed, 18 Nov 2015 08:26:43 -0500 Received: from mx2.suse.de ([195.135.220.15]:36343 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932813AbbKRN0k (ORCPT ); Wed, 18 Nov 2015 08:26:40 -0500 From: Petr Mladek To: Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Peter Zijlstra Cc: Steven Rostedt , "Paul E. McKenney" , Josh Triplett , Thomas Gleixner , Linus Torvalds , Jiri Kosina , Borislav Petkov , Michal Hocko , linux-mm@kvack.org, Vlastimil Babka , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v3 06/22] kthread: Add destroy_kthread_worker() Date: Wed, 18 Nov 2015 14:25:11 +0100 Message-Id: <1447853127-3461-7-git-send-email-pmladek@suse.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1447853127-3461-1-git-send-email-pmladek@suse.com> References: <1447853127-3461-1-git-send-email-pmladek@suse.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1995 Lines: 64 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 create_kthread_worker*() that allocates struct kthread_worker. Also note that drain() correctly handles self-queuing works in compare with flush(). Signed-off-by: Petr Mladek --- 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 943900c7ce35..c4a95a3ba500 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -136,4 +136,6 @@ bool queue_kthread_work(struct kthread_worker *worker, void flush_kthread_work(struct kthread_work *work); void flush_kthread_worker(struct kthread_worker *worker); +void destroy_kthread_worker(struct kthread_worker *worker); + #endif /* _LINUX_KTHREAD_H */ diff --git a/kernel/kthread.c b/kernel/kthread.c index a18ad3b58f61..1d41e0faef2d 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -838,3 +838,24 @@ void drain_kthread_worker(struct kthread_worker *worker) spin_unlock_irq(&worker->lock); } EXPORT_SYMBOL(drain_kthread_worker); + +/** + * destroy_kthread_worker - destroy a kthread worker + * @worker: worker to be destroyed + * + * Drain and destroy @worker. It has the same conditions + * for use as drain_kthread_worker(), see above. + */ +void destroy_kthread_worker(struct kthread_worker *worker) +{ + struct task_struct *task; + + task = worker->task; + if (WARN_ON(!task)) + return; + + drain_kthread_worker(worker); + kthread_stop(task); + kfree(worker); +} +EXPORT_SYMBOL(destroy_kthread_worker); -- 1.8.5.6 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/