[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Wed, 11 Nov 2020 17:13:55 +0800
From: qiang.zhang@...driver.com
To: pmladek@...e.com, tj@...nel.org
Cc: akpm@...ux-foundation.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] kthread_worker: Add flush delayed work func
From: Zqiang <qiang.zhang@...driver.com>
Add 'kthread_flush_delayed_work' func, the principle of
this func is wait for a dwork to finish executing the
last queueing.
Signed-off-by: Zqiang <qiang.zhang@...driver.com>
---
kernel/kthread.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/kernel/kthread.c b/kernel/kthread.c
index a5eceecd4513..1afe399ccd02 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -1045,6 +1045,30 @@ void kthread_flush_work(struct kthread_work *work)
}
EXPORT_SYMBOL_GPL(kthread_flush_work);
+/*
+ * kthread_flush_delayed_work - flush a kthread_delayed_work
+ * @dwork: dwork to flush
+ *
+ * wait for a dwork to finish executing the last queueing
+ */
+void kthread_flush_delayed_work(struct kthread_delayed_work *dwork)
+{
+ struct kthread_work *work = &dwork->work;
+ struct kthread_worker *worker = work->worker;
+ unsigned long flags;
+
+ if (del_timer_sync(&dwork->timer)) {
+ raw_spin_lock_irqsave(&worker->lock, flags);
+ list_del_init(&work->node);
+ if (!work->canceling)
+ kthread_insert_work(worker, work, &worker->work_list);
+
+ raw_spin_unlock_irqrestore(&worker->lock, flags);
+ }
+ kthread_flush_work(work);
+}
+EXPORT_SYMBOL_GPL(kthread_flush_delayed_work);
+
/*
* This function removes the work from the worker queue. Also it makes sure
* that it won't get queued later via the delayed work's timer.
--
2.17.1
Powered by blists - more mailing lists