| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_KTHREAD_H | 
|  | 2 | #define _LINUX_KTHREAD_H | 
|  | 3 | /* Simple interface for creating and stopping kernel threads without mess. */ | 
|  | 4 | #include <linux/err.h> | 
|  | 5 | #include <linux/sched.h> | 
|  | 6 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | struct task_struct *kthread_create(int (*threadfn)(void *data), | 
|  | 8 | void *data, | 
| Rusty Russell | ed9559d | 2008-07-25 12:11:09 +1000 | [diff] [blame] | 9 | const char namefmt[], ...) | 
|  | 10 | __attribute__((format(printf, 3, 4))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 |  | 
|  | 12 | /** | 
| Randy Dunlap | 9e37bd3 | 2006-06-25 05:49:19 -0700 | [diff] [blame] | 13 | * kthread_run - create and wake a thread. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * @threadfn: the function to run until signal_pending(current). | 
|  | 15 | * @data: data ptr for @threadfn. | 
|  | 16 | * @namefmt: printf-style name for the thread. | 
|  | 17 | * | 
|  | 18 | * Description: Convenient wrapper for kthread_create() followed by | 
| Randy Dunlap | 9e37bd3 | 2006-06-25 05:49:19 -0700 | [diff] [blame] | 19 | * wake_up_process().  Returns the kthread or ERR_PTR(-ENOMEM). | 
|  | 20 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #define kthread_run(threadfn, data, namefmt, ...)			   \ | 
|  | 22 | ({									   \ | 
|  | 23 | struct task_struct *__k						   \ | 
|  | 24 | = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \ | 
|  | 25 | if (!IS_ERR(__k))						   \ | 
|  | 26 | wake_up_process(__k);					   \ | 
|  | 27 | __k;								   \ | 
|  | 28 | }) | 
|  | 29 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | void kthread_bind(struct task_struct *k, unsigned int cpu); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | int kthread_stop(struct task_struct *k); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | int kthread_should_stop(void); | 
|  | 33 |  | 
| Eric W. Biederman | 73c2799 | 2007-05-09 02:34:32 -0700 | [diff] [blame] | 34 | int kthreadd(void *unused); | 
|  | 35 | extern struct task_struct *kthreadd_task; | 
|  | 36 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #endif /* _LINUX_KTHREAD_H */ |