diff options
Diffstat (limited to 'include/linux/kthread.h')
-rw-r--r-- | include/linux/kthread.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/include/linux/kthread.h b/include/linux/kthread.h index aabc8a13ba71..685ea65eb803 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h | |||
@@ -30,8 +30,73 @@ struct task_struct *kthread_create(int (*threadfn)(void *data), | |||
30 | void kthread_bind(struct task_struct *k, unsigned int cpu); | 30 | void kthread_bind(struct task_struct *k, unsigned int cpu); |
31 | int kthread_stop(struct task_struct *k); | 31 | int kthread_stop(struct task_struct *k); |
32 | int kthread_should_stop(void); | 32 | int kthread_should_stop(void); |
33 | void *kthread_data(struct task_struct *k); | ||
33 | 34 | ||
34 | int kthreadd(void *unused); | 35 | int kthreadd(void *unused); |
35 | extern struct task_struct *kthreadd_task; | 36 | extern struct task_struct *kthreadd_task; |
36 | 37 | ||
38 | /* | ||
39 | * Simple work processor based on kthread. | ||
40 | * | ||
41 | * This provides easier way to make use of kthreads. A kthread_work | ||
42 | * can be queued and flushed using queue/flush_kthread_work() | ||
43 | * respectively. Queued kthread_works are processed by a kthread | ||
44 | * running kthread_worker_fn(). | ||
45 | * | ||
46 | * A kthread_work can't be freed while it is executing. | ||
47 | */ | ||
48 | struct kthread_work; | ||
49 | typedef void (*kthread_work_func_t)(struct kthread_work *work); | ||
50 | |||
51 | struct kthread_worker { | ||
52 | spinlock_t lock; | ||
53 | struct list_head work_list; | ||
54 | struct task_struct *task; | ||
55 | }; | ||
56 | |||
57 | struct kthread_work { | ||
58 | struct list_head node; | ||
59 | kthread_work_func_t func; | ||
60 | wait_queue_head_t done; | ||
61 | atomic_t flushing; | ||
62 | int queue_seq; | ||
63 | int done_seq; | ||
64 | }; | ||
65 | |||
66 | #define KTHREAD_WORKER_INIT(worker) { \ | ||
67 | .lock = SPIN_LOCK_UNLOCKED, \ | ||
68 | .work_list = LIST_HEAD_INIT((worker).work_list), \ | ||
69 | } | ||
70 | |||
71 | #define KTHREAD_WORK_INIT(work, fn) { \ | ||
72 | .node = LIST_HEAD_INIT((work).node), \ | ||
73 | .func = (fn), \ | ||
74 | .done = __WAIT_QUEUE_HEAD_INITIALIZER((work).done), \ | ||
75 | .flushing = ATOMIC_INIT(0), \ | ||
76 | } | ||
77 | |||
78 | #define DEFINE_KTHREAD_WORKER(worker) \ | ||
79 | struct kthread_worker worker = KTHREAD_WORKER_INIT(worker) | ||
80 | |||
81 | #define DEFINE_KTHREAD_WORK(work, fn) \ | ||
82 | struct kthread_work work = KTHREAD_WORK_INIT(work, fn) | ||
83 | |||
84 | static inline void init_kthread_worker(struct kthread_worker *worker) | ||
85 | { | ||
86 | *worker = (struct kthread_worker)KTHREAD_WORKER_INIT(*worker); | ||
87 | } | ||
88 | |||
89 | static inline void init_kthread_work(struct kthread_work *work, | ||
90 | kthread_work_func_t fn) | ||
91 | { | ||
92 | *work = (struct kthread_work)KTHREAD_WORK_INIT(*work, fn); | ||
93 | } | ||
94 | |||
95 | int kthread_worker_fn(void *worker_ptr); | ||
96 | |||
97 | bool queue_kthread_work(struct kthread_worker *worker, | ||
98 | struct kthread_work *work); | ||
99 | void flush_kthread_work(struct kthread_work *work); | ||
100 | void flush_kthread_worker(struct kthread_worker *worker); | ||
101 | |||
37 | #endif /* _LINUX_KTHREAD_H */ | 102 | #endif /* _LINUX_KTHREAD_H */ |