| 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; | 
 | 20 | 	struct timer_list timer; | 
 | 21 | }; | 
 | 22 |  | 
| James Bottomley | 1fa44ec | 2006-02-23 12:43:43 -0600 | [diff] [blame] | 23 | struct execute_work { | 
 | 24 | 	struct work_struct work; | 
 | 25 | }; | 
 | 26 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #define __WORK_INITIALIZER(n, f, d) {				\ | 
 | 28 |         .entry	= { &(n).entry, &(n).entry },			\ | 
 | 29 | 	.func = (f),						\ | 
 | 30 | 	.data = (d),						\ | 
 | 31 | 	.timer = TIMER_INITIALIZER(NULL, 0, 0),			\ | 
 | 32 | 	} | 
 | 33 |  | 
 | 34 | #define DECLARE_WORK(n, f, d)					\ | 
 | 35 | 	struct work_struct n = __WORK_INITIALIZER(n, f, d) | 
 | 36 |  | 
 | 37 | /* | 
 | 38 |  * initialize a work-struct's func and data pointers: | 
 | 39 |  */ | 
 | 40 | #define PREPARE_WORK(_work, _func, _data)			\ | 
 | 41 | 	do {							\ | 
 | 42 | 		(_work)->func = _func;				\ | 
 | 43 | 		(_work)->data = _data;				\ | 
 | 44 | 	} while (0) | 
 | 45 |  | 
 | 46 | /* | 
 | 47 |  * initialize all of a work-struct: | 
 | 48 |  */ | 
 | 49 | #define INIT_WORK(_work, _func, _data)				\ | 
 | 50 | 	do {							\ | 
 | 51 | 		INIT_LIST_HEAD(&(_work)->entry);		\ | 
 | 52 | 		(_work)->pending = 0;				\ | 
 | 53 | 		PREPARE_WORK((_work), (_func), (_data));	\ | 
 | 54 | 		init_timer(&(_work)->timer);			\ | 
 | 55 | 	} while (0) | 
 | 56 |  | 
 | 57 | extern struct workqueue_struct *__create_workqueue(const char *name, | 
 | 58 | 						    int singlethread); | 
 | 59 | #define create_workqueue(name) __create_workqueue((name), 0) | 
 | 60 | #define create_singlethread_workqueue(name) __create_workqueue((name), 1) | 
 | 61 |  | 
 | 62 | extern void destroy_workqueue(struct workqueue_struct *wq); | 
 | 63 |  | 
 | 64 | extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work)); | 
 | 65 | extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct work_struct *work, unsigned long delay)); | 
 | 66 | extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq)); | 
 | 67 |  | 
 | 68 | extern int FASTCALL(schedule_work(struct work_struct *work)); | 
 | 69 | extern int FASTCALL(schedule_delayed_work(struct work_struct *work, unsigned long delay)); | 
 | 70 |  | 
 | 71 | extern int schedule_delayed_work_on(int cpu, struct work_struct *work, unsigned long delay); | 
| Christoph Lameter | 15316ba | 2006-01-08 01:00:43 -0800 | [diff] [blame] | 72 | extern int schedule_on_each_cpu(void (*func)(void *info), void *info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | extern void flush_scheduled_work(void); | 
 | 74 | extern int current_is_keventd(void); | 
 | 75 | extern int keventd_up(void); | 
 | 76 |  | 
 | 77 | extern void init_workqueues(void); | 
 | 78 | void cancel_rearming_delayed_work(struct work_struct *work); | 
| James Bottomley | 81ddef7 | 2005-04-16 15:23:59 -0700 | [diff] [blame] | 79 | void cancel_rearming_delayed_workqueue(struct workqueue_struct *, | 
 | 80 | 				       struct work_struct *); | 
| James Bottomley | 1fa44ec | 2006-02-23 12:43:43 -0600 | [diff] [blame] | 81 | int execute_in_process_context(void (*fn)(void *), void *, | 
 | 82 | 			       struct execute_work *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 |  | 
 | 84 | /* | 
 | 85 |  * Kill off a pending schedule_delayed_work().  Note that the work callback | 
 | 86 |  * function may still be running on return from cancel_delayed_work().  Run | 
 | 87 |  * flush_scheduled_work() to wait on it. | 
 | 88 |  */ | 
 | 89 | static inline int cancel_delayed_work(struct work_struct *work) | 
 | 90 | { | 
 | 91 | 	int ret; | 
 | 92 |  | 
 | 93 | 	ret = del_timer_sync(&work->timer); | 
 | 94 | 	if (ret) | 
 | 95 | 		clear_bit(0, &work->pending); | 
 | 96 | 	return ret; | 
 | 97 | } | 
 | 98 |  | 
 | 99 | #endif |