aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kthread.h
diff options
context:
space:
mode:
authorYong Zhang <yong.zhang0@gmail.com>2010-12-22 04:27:53 -0500
committerTejun Heo <tj@kernel.org>2010-12-22 04:27:53 -0500
commit4f32e9b1f812fd6c00cc85a127583fefbdedaedc (patch)
treec0e1d3e1d90758d2f4f3f8cad6beea316d68b5a0 /include/linux/kthread.h
parent90a8a73c06cc32b609a880d48449d7083327e11a (diff)
kthread_work: make lockdep happy
spinlock in kthread_worker and wait_queue_head in kthread_work both should be lockdep sensible, so change the interface to make it suiltable for CONFIG_LOCKDEP. tj: comment update Reported-by: Nicolas <nicolas.mailhot@laposte.net> Signed-off-by: Yong Zhang <yong.zhang0@gmail.com> Signed-off-by: Andy Walls <awalls@md.metrocast.net> Tested-by: Andy Walls <awalls@md.metrocast.net> Cc: Tejun Heo <tj@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'include/linux/kthread.h')
-rw-r--r--include/linux/kthread.h45
1 files changed, 35 insertions, 10 deletions
diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 685ea65eb803..ce0775aa64c3 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -81,16 +81,41 @@ struct kthread_work {
81#define DEFINE_KTHREAD_WORK(work, fn) \ 81#define DEFINE_KTHREAD_WORK(work, fn) \
82 struct kthread_work work = KTHREAD_WORK_INIT(work, fn) 82 struct kthread_work work = KTHREAD_WORK_INIT(work, fn)
83 83
84static inline void init_kthread_worker(struct kthread_worker *worker) 84/*
85{ 85 * kthread_worker.lock and kthread_work.done need their own lockdep class
86 *worker = (struct kthread_worker)KTHREAD_WORKER_INIT(*worker); 86 * keys if they are defined on stack with lockdep enabled. Use the
87} 87 * following macros when defining them on stack.
88 88 */
89static inline void init_kthread_work(struct kthread_work *work, 89#ifdef CONFIG_LOCKDEP
90 kthread_work_func_t fn) 90# define KTHREAD_WORKER_INIT_ONSTACK(worker) \
91{ 91 ({ init_kthread_worker(&worker); worker; })
92 *work = (struct kthread_work)KTHREAD_WORK_INIT(*work, fn); 92# define DEFINE_KTHREAD_WORKER_ONSTACK(worker) \
93} 93 struct kthread_worker worker = KTHREAD_WORKER_INIT_ONSTACK(worker)
94# define KTHREAD_WORK_INIT_ONSTACK(work, fn) \
95 ({ init_kthread_work((&work), fn); work; })
96# define DEFINE_KTHREAD_WORK_ONSTACK(work, fn) \
97 struct kthread_work work = KTHREAD_WORK_INIT_ONSTACK(work, fn)
98#else
99# define DEFINE_KTHREAD_WORKER_ONSTACK(worker) DEFINE_KTHREAD_WORKER(worker)
100# define DEFINE_KTHREAD_WORK_ONSTACK(work, fn) DEFINE_KTHREAD_WORK(work, fn)
101#endif
102
103extern void __init_kthread_worker(struct kthread_worker *worker,
104 const char *name, struct lock_class_key *key);
105
106#define init_kthread_worker(worker) \
107 do { \
108 static struct lock_class_key __key; \
109 __init_kthread_worker((worker), "("#worker")->lock", &__key); \
110 } while (0)
111
112#define init_kthread_work(work, fn) \
113 do { \
114 memset((work), 0, sizeof(struct kthread_work)); \
115 INIT_LIST_HEAD(&(work)->node); \
116 (work)->func = (fn); \
117 init_waitqueue_head(&(work)->done); \
118 } while (0)
94 119
95int kthread_worker_fn(void *worker_ptr); 120int kthread_worker_fn(void *worker_ptr);
96 121