aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/workqueue.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/workqueue.h')
-rw-r--r--include/linux/workqueue.h77
1 files changed, 53 insertions, 24 deletions
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 25e02c941bac..f584aba78ca9 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -127,12 +127,20 @@ struct execute_work {
127 .timer = TIMER_INITIALIZER(NULL, 0, 0), \ 127 .timer = TIMER_INITIALIZER(NULL, 0, 0), \
128 } 128 }
129 129
130#define __DEFERRED_WORK_INITIALIZER(n, f) { \
131 .work = __WORK_INITIALIZER((n).work, (f)), \
132 .timer = TIMER_DEFERRED_INITIALIZER(NULL, 0, 0), \
133 }
134
130#define DECLARE_WORK(n, f) \ 135#define DECLARE_WORK(n, f) \
131 struct work_struct n = __WORK_INITIALIZER(n, f) 136 struct work_struct n = __WORK_INITIALIZER(n, f)
132 137
133#define DECLARE_DELAYED_WORK(n, f) \ 138#define DECLARE_DELAYED_WORK(n, f) \
134 struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f) 139 struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f)
135 140
141#define DECLARE_DEFERRED_WORK(n, f) \
142 struct delayed_work n = __DEFERRED_WORK_INITIALIZER(n, f)
143
136/* 144/*
137 * initialize a work item's function pointer 145 * initialize a work item's function pointer
138 */ 146 */
@@ -190,7 +198,7 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
190 __INIT_WORK((_work), (_func), 0); \ 198 __INIT_WORK((_work), (_func), 0); \
191 } while (0) 199 } while (0)
192 200
193#define INIT_WORK_ON_STACK(_work, _func) \ 201#define INIT_WORK_ONSTACK(_work, _func) \
194 do { \ 202 do { \
195 __INIT_WORK((_work), (_func), 1); \ 203 __INIT_WORK((_work), (_func), 1); \
196 } while (0) 204 } while (0)
@@ -201,9 +209,9 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
201 init_timer(&(_work)->timer); \ 209 init_timer(&(_work)->timer); \
202 } while (0) 210 } while (0)
203 211
204#define INIT_DELAYED_WORK_ON_STACK(_work, _func) \ 212#define INIT_DELAYED_WORK_ONSTACK(_work, _func) \
205 do { \ 213 do { \
206 INIT_WORK_ON_STACK(&(_work)->work, (_func)); \ 214 INIT_WORK_ONSTACK(&(_work)->work, (_func)); \
207 init_timer_on_stack(&(_work)->timer); \ 215 init_timer_on_stack(&(_work)->timer); \
208 } while (0) 216 } while (0)
209 217
@@ -242,12 +250,13 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
242enum { 250enum {
243 WQ_NON_REENTRANT = 1 << 0, /* guarantee non-reentrance */ 251 WQ_NON_REENTRANT = 1 << 0, /* guarantee non-reentrance */
244 WQ_UNBOUND = 1 << 1, /* not bound to any cpu */ 252 WQ_UNBOUND = 1 << 1, /* not bound to any cpu */
245 WQ_FREEZEABLE = 1 << 2, /* freeze during suspend */ 253 WQ_FREEZABLE = 1 << 2, /* freeze during suspend */
246 WQ_RESCUER = 1 << 3, /* has an rescue worker */ 254 WQ_MEM_RECLAIM = 1 << 3, /* may be used for memory reclaim */
247 WQ_HIGHPRI = 1 << 4, /* high priority */ 255 WQ_HIGHPRI = 1 << 4, /* high priority */
248 WQ_CPU_INTENSIVE = 1 << 5, /* cpu instensive workqueue */ 256 WQ_CPU_INTENSIVE = 1 << 5, /* cpu instensive workqueue */
249 257
250 WQ_DYING = 1 << 6, /* internal: workqueue is dying */ 258 WQ_DYING = 1 << 6, /* internal: workqueue is dying */
259 WQ_RESCUER = 1 << 7, /* internal: workqueue has rescuer */
251 260
252 WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */ 261 WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */
253 WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */ 262 WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */
@@ -277,11 +286,15 @@ enum {
277 * any specific CPU, not concurrency managed, and all queued works are 286 * any specific CPU, not concurrency managed, and all queued works are
278 * executed immediately as long as max_active limit is not reached and 287 * executed immediately as long as max_active limit is not reached and
279 * resources are available. 288 * resources are available.
289 *
290 * system_freezable_wq is equivalent to system_wq except that it's
291 * freezable.
280 */ 292 */
281extern struct workqueue_struct *system_wq; 293extern struct workqueue_struct *system_wq;
282extern struct workqueue_struct *system_long_wq; 294extern struct workqueue_struct *system_long_wq;
283extern struct workqueue_struct *system_nrt_wq; 295extern struct workqueue_struct *system_nrt_wq;
284extern struct workqueue_struct *system_unbound_wq; 296extern struct workqueue_struct *system_unbound_wq;
297extern struct workqueue_struct *system_freezable_wq;
285 298
286extern struct workqueue_struct * 299extern struct workqueue_struct *
287__alloc_workqueue_key(const char *name, unsigned int flags, int max_active, 300__alloc_workqueue_key(const char *name, unsigned int flags, int max_active,
@@ -306,12 +319,30 @@ __alloc_workqueue_key(const char *name, unsigned int flags, int max_active,
306 __alloc_workqueue_key((name), (flags), (max_active), NULL, NULL) 319 __alloc_workqueue_key((name), (flags), (max_active), NULL, NULL)
307#endif 320#endif
308 321
322/**
323 * alloc_ordered_workqueue - allocate an ordered workqueue
324 * @name: name of the workqueue
325 * @flags: WQ_* flags (only WQ_FREEZABLE and WQ_MEM_RECLAIM are meaningful)
326 *
327 * Allocate an ordered workqueue. An ordered workqueue executes at
328 * most one work item at any given time in the queued order. They are
329 * implemented as unbound workqueues with @max_active of one.
330 *
331 * RETURNS:
332 * Pointer to the allocated workqueue on success, %NULL on failure.
333 */
334static inline struct workqueue_struct *
335alloc_ordered_workqueue(const char *name, unsigned int flags)
336{
337 return alloc_workqueue(name, WQ_UNBOUND | flags, 1);
338}
339
309#define create_workqueue(name) \ 340#define create_workqueue(name) \
310 alloc_workqueue((name), WQ_RESCUER, 1) 341 alloc_workqueue((name), WQ_MEM_RECLAIM, 1)
311#define create_freezeable_workqueue(name) \ 342#define create_freezable_workqueue(name) \
312 alloc_workqueue((name), WQ_FREEZEABLE | WQ_UNBOUND | WQ_RESCUER, 1) 343 alloc_workqueue((name), WQ_FREEZABLE | WQ_UNBOUND | WQ_MEM_RECLAIM, 1)
313#define create_singlethread_workqueue(name) \ 344#define create_singlethread_workqueue(name) \
314 alloc_workqueue((name), WQ_UNBOUND | WQ_RESCUER, 1) 345 alloc_workqueue((name), WQ_UNBOUND | WQ_MEM_RECLAIM, 1)
315 346
316extern void destroy_workqueue(struct workqueue_struct *wq); 347extern void destroy_workqueue(struct workqueue_struct *wq);
317 348
@@ -325,7 +356,6 @@ extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
325 356
326extern void flush_workqueue(struct workqueue_struct *wq); 357extern void flush_workqueue(struct workqueue_struct *wq);
327extern void flush_scheduled_work(void); 358extern void flush_scheduled_work(void);
328extern void flush_delayed_work(struct delayed_work *work);
329 359
330extern int schedule_work(struct work_struct *work); 360extern int schedule_work(struct work_struct *work);
331extern int schedule_work_on(int cpu, struct work_struct *work); 361extern int schedule_work_on(int cpu, struct work_struct *work);
@@ -337,8 +367,13 @@ extern int keventd_up(void);
337 367
338int execute_in_process_context(work_func_t fn, struct execute_work *); 368int execute_in_process_context(work_func_t fn, struct execute_work *);
339 369
340extern int flush_work(struct work_struct *work); 370extern bool flush_work(struct work_struct *work);
341extern int cancel_work_sync(struct work_struct *work); 371extern bool flush_work_sync(struct work_struct *work);
372extern bool cancel_work_sync(struct work_struct *work);
373
374extern bool flush_delayed_work(struct delayed_work *dwork);
375extern bool flush_delayed_work_sync(struct delayed_work *work);
376extern bool cancel_delayed_work_sync(struct delayed_work *dwork);
342 377
343extern void workqueue_set_max_active(struct workqueue_struct *wq, 378extern void workqueue_set_max_active(struct workqueue_struct *wq,
344 int max_active); 379 int max_active);
@@ -352,9 +387,9 @@ extern unsigned int work_busy(struct work_struct *work);
352 * it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or 387 * it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or
353 * cancel_work_sync() to wait on it. 388 * cancel_work_sync() to wait on it.
354 */ 389 */
355static inline int cancel_delayed_work(struct delayed_work *work) 390static inline bool cancel_delayed_work(struct delayed_work *work)
356{ 391{
357 int ret; 392 bool ret;
358 393
359 ret = del_timer_sync(&work->timer); 394 ret = del_timer_sync(&work->timer);
360 if (ret) 395 if (ret)
@@ -367,9 +402,9 @@ static inline int cancel_delayed_work(struct delayed_work *work)
367 * if it returns 0 the timer function may be running and the queueing is in 402 * if it returns 0 the timer function may be running and the queueing is in
368 * progress. 403 * progress.
369 */ 404 */
370static inline int __cancel_delayed_work(struct delayed_work *work) 405static inline bool __cancel_delayed_work(struct delayed_work *work)
371{ 406{
372 int ret; 407 bool ret;
373 408
374 ret = del_timer(&work->timer); 409 ret = del_timer(&work->timer);
375 if (ret) 410 if (ret)
@@ -377,10 +412,8 @@ static inline int __cancel_delayed_work(struct delayed_work *work)
377 return ret; 412 return ret;
378} 413}
379 414
380extern int cancel_delayed_work_sync(struct delayed_work *work);
381
382/* Obsolete. use cancel_delayed_work_sync() */ 415/* Obsolete. use cancel_delayed_work_sync() */
383static inline 416static inline __deprecated
384void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq, 417void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq,
385 struct delayed_work *work) 418 struct delayed_work *work)
386{ 419{
@@ -388,7 +421,7 @@ void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq,
388} 421}
389 422
390/* Obsolete. use cancel_delayed_work_sync() */ 423/* Obsolete. use cancel_delayed_work_sync() */
391static inline 424static inline __deprecated
392void cancel_rearming_delayed_work(struct delayed_work *work) 425void cancel_rearming_delayed_work(struct delayed_work *work)
393{ 426{
394 cancel_delayed_work_sync(work); 427 cancel_delayed_work_sync(work);
@@ -409,8 +442,4 @@ extern bool freeze_workqueues_busy(void);
409extern void thaw_workqueues(void); 442extern void thaw_workqueues(void);
410#endif /* CONFIG_FREEZER */ 443#endif /* CONFIG_FREEZER */
411 444
412#ifdef CONFIG_LOCKDEP
413int in_workqueue_context(struct workqueue_struct *wq);
414#endif
415
416#endif 445#endif