blob: 1c65e7a9f186cceee83a1e5e199db44b4260daf2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 Torvalds1da177e2005-04-16 15:20:36 -07007struct task_struct *kthread_create(int (*threadfn)(void *data),
8 void *data,
9 const char namefmt[], ...);
10
11/**
Randy Dunlap9e37bd32006-06-25 05:49:19 -070012 * kthread_run - create and wake a thread.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * @threadfn: the function to run until signal_pending(current).
14 * @data: data ptr for @threadfn.
15 * @namefmt: printf-style name for the thread.
16 *
17 * Description: Convenient wrapper for kthread_create() followed by
Randy Dunlap9e37bd32006-06-25 05:49:19 -070018 * wake_up_process(). Returns the kthread or ERR_PTR(-ENOMEM).
19 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#define kthread_run(threadfn, data, namefmt, ...) \
21({ \
22 struct task_struct *__k \
23 = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
24 if (!IS_ERR(__k)) \
25 wake_up_process(__k); \
26 __k; \
27})
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029void kthread_bind(struct task_struct *k, unsigned int cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030int kthread_stop(struct task_struct *k);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031int kthread_should_stop(void);
32
33#endif /* _LINUX_KTHREAD_H */