aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/lockdep.h8
-rw-r--r--include/linux/workqueue.h49
2 files changed, 54 insertions, 3 deletions
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index f6279f68a827..4c4d236ded18 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -276,6 +276,14 @@ extern void lockdep_init_map(struct lockdep_map *lock, const char *name,
276 (lock)->dep_map.key, sub) 276 (lock)->dep_map.key, sub)
277 277
278/* 278/*
279 * To initialize a lockdep_map statically use this macro.
280 * Note that _name must not be NULL.
281 */
282#define STATIC_LOCKDEP_MAP_INIT(_name, _key) \
283 { .name = (_name), .key = (void *)(_key), }
284
285
286/*
279 * Acquire a lock. 287 * Acquire a lock.
280 * 288 *
281 * Values for "read": 289 * Values for "read":
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index ce6badc98f6d..7daafdc2514b 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -8,6 +8,7 @@
8#include <linux/timer.h> 8#include <linux/timer.h>
9#include <linux/linkage.h> 9#include <linux/linkage.h>
10#include <linux/bitops.h> 10#include <linux/bitops.h>
11#include <linux/lockdep.h>
11#include <asm/atomic.h> 12#include <asm/atomic.h>
12 13
13struct workqueue_struct; 14struct workqueue_struct;
@@ -28,6 +29,9 @@ struct work_struct {
28#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK) 29#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
29 struct list_head entry; 30 struct list_head entry;
30 work_func_t func; 31 work_func_t func;
32#ifdef CONFIG_LOCKDEP
33 struct lockdep_map lockdep_map;
34#endif
31}; 35};
32 36
33#define WORK_DATA_INIT() ATOMIC_LONG_INIT(0) 37#define WORK_DATA_INIT() ATOMIC_LONG_INIT(0)
@@ -41,10 +45,23 @@ struct execute_work {
41 struct work_struct work; 45 struct work_struct work;
42}; 46};
43 47
48#ifdef CONFIG_LOCKDEP
49/*
50 * NB: because we have to copy the lockdep_map, setting _key
51 * here is required, otherwise it could get initialised to the
52 * copy of the lockdep_map!
53 */
54#define __WORK_INIT_LOCKDEP_MAP(n, k) \
55 .lockdep_map = STATIC_LOCKDEP_MAP_INIT(n, k),
56#else
57#define __WORK_INIT_LOCKDEP_MAP(n, k)
58#endif
59
44#define __WORK_INITIALIZER(n, f) { \ 60#define __WORK_INITIALIZER(n, f) { \
45 .data = WORK_DATA_INIT(), \ 61 .data = WORK_DATA_INIT(), \
46 .entry = { &(n).entry, &(n).entry }, \ 62 .entry = { &(n).entry, &(n).entry }, \
47 .func = (f), \ 63 .func = (f), \
64 __WORK_INIT_LOCKDEP_MAP(#n, &(n)) \
48 } 65 }
49 66
50#define __DELAYED_WORK_INITIALIZER(n, f) { \ 67#define __DELAYED_WORK_INITIALIZER(n, f) { \
@@ -76,12 +93,24 @@ struct execute_work {
76 * assignment of the work data initializer allows the compiler 93 * assignment of the work data initializer allows the compiler
77 * to generate better code. 94 * to generate better code.
78 */ 95 */
96#ifdef CONFIG_LOCKDEP
97#define INIT_WORK(_work, _func) \
98 do { \
99 static struct lock_class_key __key; \
100 \
101 (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
102 lockdep_init_map(&(_work)->lockdep_map, #_work, &__key, 0);\
103 INIT_LIST_HEAD(&(_work)->entry); \
104 PREPARE_WORK((_work), (_func)); \
105 } while (0)
106#else
79#define INIT_WORK(_work, _func) \ 107#define INIT_WORK(_work, _func) \
80 do { \ 108 do { \
81 (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \ 109 (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
82 INIT_LIST_HEAD(&(_work)->entry); \ 110 INIT_LIST_HEAD(&(_work)->entry); \
83 PREPARE_WORK((_work), (_func)); \ 111 PREPARE_WORK((_work), (_func)); \
84 } while (0) 112 } while (0)
113#endif
85 114
86#define INIT_DELAYED_WORK(_work, _func) \ 115#define INIT_DELAYED_WORK(_work, _func) \
87 do { \ 116 do { \
@@ -118,9 +147,23 @@ struct execute_work {
118 clear_bit(WORK_STRUCT_PENDING, work_data_bits(work)) 147 clear_bit(WORK_STRUCT_PENDING, work_data_bits(work))
119 148
120 149
121extern struct workqueue_struct *__create_workqueue(const char *name, 150extern struct workqueue_struct *
122 int singlethread, 151__create_workqueue_key(const char *name, int singlethread,
123 int freezeable); 152 int freezeable, struct lock_class_key *key);
153
154#ifdef CONFIG_LOCKDEP
155#define __create_workqueue(name, singlethread, freezeable) \
156({ \
157 static struct lock_class_key __key; \
158 \
159 __create_workqueue_key((name), (singlethread), \
160 (freezeable), &__key); \
161})
162#else
163#define __create_workqueue(name, singlethread, freezeable) \
164 __create_workqueue_key((name), (singlethread), (freezeable), NULL)
165#endif
166
124#define create_workqueue(name) __create_workqueue((name), 0, 0) 167#define create_workqueue(name) __create_workqueue((name), 0, 0)
125#define create_freezeable_workqueue(name) __create_workqueue((name), 1, 1) 168#define create_freezeable_workqueue(name) __create_workqueue((name), 1, 1)
126#define create_singlethread_workqueue(name) __create_workqueue((name), 1, 0) 169#define create_singlethread_workqueue(name) __create_workqueue((name), 1, 0)