Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * workqueue.h --- work queue handling for Linux. |
| 3 | */ |
| 4 | |
| 5 | #ifndef _LINUX_WORKQUEUE_H |
| 6 | #define _LINUX_WORKQUEUE_H |
| 7 | |
| 8 | #include <linux/timer.h> |
| 9 | #include <linux/linkage.h> |
| 10 | #include <linux/bitops.h> |
| 11 | |
| 12 | struct workqueue_struct; |
| 13 | |
| 14 | struct work_struct { |
| 15 | unsigned long pending; |
| 16 | struct list_head entry; |
| 17 | void (*func)(void *); |
| 18 | void *data; |
| 19 | void *wq_data; |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 20 | }; |
| 21 | |
| 22 | struct delayed_work { |
| 23 | struct work_struct work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | struct timer_list timer; |
| 25 | }; |
| 26 | |
James Bottomley | 1fa44ec | 2006-02-23 12:43:43 -0600 | [diff] [blame] | 27 | struct execute_work { |
| 28 | struct work_struct work; |
| 29 | }; |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #define __WORK_INITIALIZER(n, f, d) { \ |
| 32 | .entry = { &(n).entry, &(n).entry }, \ |
| 33 | .func = (f), \ |
| 34 | .data = (d), \ |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 35 | } |
| 36 | |
| 37 | #define __DELAYED_WORK_INITIALIZER(n, f, d) { \ |
| 38 | .work = __WORK_INITIALIZER((n).work, (f), (d)), \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | .timer = TIMER_INITIALIZER(NULL, 0, 0), \ |
| 40 | } |
| 41 | |
| 42 | #define DECLARE_WORK(n, f, d) \ |
| 43 | struct work_struct n = __WORK_INITIALIZER(n, f, d) |
| 44 | |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 45 | #define DECLARE_DELAYED_WORK(n, f, d) \ |
| 46 | struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, d) |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | /* |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 49 | * initialize a work item's function and data pointers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | */ |
| 51 | #define PREPARE_WORK(_work, _func, _data) \ |
| 52 | do { \ |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 53 | (_work)->func = (_func); \ |
| 54 | (_work)->data = (_data); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } while (0) |
| 56 | |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 57 | #define PREPARE_DELAYED_WORK(_work, _func, _data) \ |
| 58 | PREPARE_WORK(&(_work)->work, (_func), (_data)) |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 61 | * initialize all of a work item in one go |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | */ |
| 63 | #define INIT_WORK(_work, _func, _data) \ |
| 64 | do { \ |
| 65 | INIT_LIST_HEAD(&(_work)->entry); \ |
| 66 | (_work)->pending = 0; \ |
| 67 | PREPARE_WORK((_work), (_func), (_data)); \ |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 68 | } while (0) |
| 69 | |
| 70 | #define INIT_DELAYED_WORK(_work, _func, _data) \ |
| 71 | do { \ |
| 72 | INIT_WORK(&(_work)->work, (_func), (_data)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | init_timer(&(_work)->timer); \ |
| 74 | } while (0) |
| 75 | |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | extern struct workqueue_struct *__create_workqueue(const char *name, |
| 78 | int singlethread); |
| 79 | #define create_workqueue(name) __create_workqueue((name), 0) |
| 80 | #define create_singlethread_workqueue(name) __create_workqueue((name), 1) |
| 81 | |
| 82 | extern void destroy_workqueue(struct workqueue_struct *wq); |
| 83 | |
| 84 | extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work)); |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 85 | extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay)); |
Venkatesh Pallipadi | 7a6bc1c | 2006-06-28 13:50:33 -0700 | [diff] [blame] | 86 | extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 87 | struct delayed_work *work, unsigned long delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq)); |
| 89 | |
| 90 | extern int FASTCALL(schedule_work(struct work_struct *work)); |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 91 | extern int FASTCALL(schedule_delayed_work(struct delayed_work *work, unsigned long delay)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 93 | extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, unsigned long delay); |
Christoph Lameter | 15316ba | 2006-01-08 01:00:43 -0800 | [diff] [blame] | 94 | extern int schedule_on_each_cpu(void (*func)(void *info), void *info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | extern void flush_scheduled_work(void); |
| 96 | extern int current_is_keventd(void); |
| 97 | extern int keventd_up(void); |
| 98 | |
| 99 | extern void init_workqueues(void); |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 100 | void cancel_rearming_delayed_work(struct delayed_work *work); |
James Bottomley | 81ddef7 | 2005-04-16 15:23:59 -0700 | [diff] [blame] | 101 | void cancel_rearming_delayed_workqueue(struct workqueue_struct *, |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 102 | struct delayed_work *); |
James Bottomley | 1fa44ec | 2006-02-23 12:43:43 -0600 | [diff] [blame] | 103 | int execute_in_process_context(void (*fn)(void *), void *, |
| 104 | struct execute_work *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * Kill off a pending schedule_delayed_work(). Note that the work callback |
| 108 | * function may still be running on return from cancel_delayed_work(). Run |
| 109 | * flush_scheduled_work() to wait on it. |
| 110 | */ |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 111 | static inline int cancel_delayed_work(struct delayed_work *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
| 113 | int ret; |
| 114 | |
| 115 | ret = del_timer_sync(&work->timer); |
| 116 | if (ret) |
David Howells | 52bad64 | 2006-11-22 14:54:01 +0000 | [diff] [blame^] | 117 | clear_bit(0, &work->work.pending); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | return ret; |
| 119 | } |
| 120 | |
| 121 | #endif |