diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/linux/kthread.h |
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'include/linux/kthread.h')
-rw-r--r-- | include/linux/kthread.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/include/linux/kthread.h b/include/linux/kthread.h new file mode 100644 index 00000000000..3fa786448db --- /dev/null +++ b/include/linux/kthread.h | |||
@@ -0,0 +1,81 @@ | |||
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 | |||
7 | /** | ||
8 | * kthread_create: create a kthread. | ||
9 | * @threadfn: the function to run until signal_pending(current). | ||
10 | * @data: data ptr for @threadfn. | ||
11 | * @namefmt: printf-style name for the thread. | ||
12 | * | ||
13 | * Description: This helper function creates and names a kernel | ||
14 | * thread. The thread will be stopped: use wake_up_process() to start | ||
15 | * it. See also kthread_run(), kthread_create_on_cpu(). | ||
16 | * | ||
17 | * When woken, the thread will run @threadfn() with @data as its | ||
18 | * argument. @threadfn can either call do_exit() directly if it is a | ||
19 | * standalone thread for which noone will call kthread_stop(), or | ||
20 | * return when 'kthread_should_stop()' is true (which means | ||
21 | * kthread_stop() has been called). The return value should be zero | ||
22 | * or a negative error number: it will be passed to kthread_stop(). | ||
23 | * | ||
24 | * Returns a task_struct or ERR_PTR(-ENOMEM). | ||
25 | */ | ||
26 | struct task_struct *kthread_create(int (*threadfn)(void *data), | ||
27 | void *data, | ||
28 | const char namefmt[], ...); | ||
29 | |||
30 | /** | ||
31 | * kthread_run: create and wake a thread. | ||
32 | * @threadfn: the function to run until signal_pending(current). | ||
33 | * @data: data ptr for @threadfn. | ||
34 | * @namefmt: printf-style name for the thread. | ||
35 | * | ||
36 | * Description: Convenient wrapper for kthread_create() followed by | ||
37 | * wake_up_process(). Returns the kthread, or ERR_PTR(-ENOMEM). */ | ||
38 | #define kthread_run(threadfn, data, namefmt, ...) \ | ||
39 | ({ \ | ||
40 | struct task_struct *__k \ | ||
41 | = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \ | ||
42 | if (!IS_ERR(__k)) \ | ||
43 | wake_up_process(__k); \ | ||
44 | __k; \ | ||
45 | }) | ||
46 | |||
47 | /** | ||
48 | * kthread_bind: bind a just-created kthread to a cpu. | ||
49 | * @k: thread created by kthread_create(). | ||
50 | * @cpu: cpu (might not be online, must be possible) for @k to run on. | ||
51 | * | ||
52 | * Description: This function is equivalent to set_cpus_allowed(), | ||
53 | * except that @cpu doesn't need to be online, and the thread must be | ||
54 | * stopped (ie. just returned from kthread_create(). | ||
55 | */ | ||
56 | void kthread_bind(struct task_struct *k, unsigned int cpu); | ||
57 | |||
58 | /** | ||
59 | * kthread_stop: stop a thread created by kthread_create(). | ||
60 | * @k: thread created by kthread_create(). | ||
61 | * | ||
62 | * Sets kthread_should_stop() for @k to return true, wakes it, and | ||
63 | * waits for it to exit. Your threadfn() must not call do_exit() | ||
64 | * itself if you use this function! This can also be called after | ||
65 | * kthread_create() instead of calling wake_up_process(): the thread | ||
66 | * will exit without calling threadfn(). | ||
67 | * | ||
68 | * Returns the result of threadfn(), or -EINTR if wake_up_process() | ||
69 | * was never called. */ | ||
70 | int kthread_stop(struct task_struct *k); | ||
71 | |||
72 | /** | ||
73 | * kthread_should_stop: should this kthread return now? | ||
74 | * | ||
75 | * When someone calls kthread_stop on your kthread, it will be woken | ||
76 | * and this will return true. You should then return, and your return | ||
77 | * value will be passed through to kthread_stop(). | ||
78 | */ | ||
79 | int kthread_should_stop(void); | ||
80 | |||
81 | #endif /* _LINUX_KTHREAD_H */ | ||