]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/include/kthread.h
LinCAN partial update of thread helper support for 2.6.27+ kernels.
[lincan.git] / lincan / include / kthread.h
1 #ifndef _KTHREAD_H
2 #define _KTHREAD_H
3 #include <linux/version.h>
4 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))
5 #include <linux/config.h>
6 #endif
7
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
10
11 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,40))
12   #include <linux/tqueue.h>
13   #define tasklet_struct tq_struct
14 #else
15   #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))
16     #include <linux/devfs_fs_kernel.h>
17   #endif
18 #endif
19
20 #include <linux/wait.h>
21 #include <linux/interrupt.h>
22
23 #include <asm/unistd.h>
24
25 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27))
26   #include <asm/semaphore.h>
27 #else
28   #include <linux/semaphore.h>
29 #endif
30
31 /* a structure to store all information we need
32    for our thread */
33 typedef struct kthread_struct
34 {
35         /* private data */
36
37         /* Linux task structure of thread */
38         struct task_struct *thread;
39         /* Task queue/Tasklet need to launch thread */
40         struct tasklet_struct tq;
41         /* function to be started as thread */
42         void (*function) (struct kthread_struct *kthread);
43         /* semaphore needed on start and creation of thread. */
44         struct semaphore startstop_sem;
45
46         /* public data */
47
48         /* queue thread is waiting on. Gets initialized by
49            init_kthread, can be used by thread itself.
50         */
51         wait_queue_head_t queue;
52         /* flag to tell thread whether to die or not.
53            When the thread receives a signal, it must check
54            the value of terminate and call exit_kthread and terminate
55            if set.
56         */
57         int terminate;
58         /* additional data to pass to kernel thread */
59         void *arg;
60 } kthread_t;
61
62 /* prototypes */
63
64 /* start new kthread (called by creator) */
65 void start_kthread(void (*func)(kthread_t *), kthread_t *kthread);
66
67 /* stop a running thread (called by "killer") */
68 void stop_kthread(kthread_t *kthread);
69
70 /* setup thread environment (called by new thread) */
71 void init_kthread(kthread_t *kthread, char *name);
72
73 /* cleanup thread environment (called by thread upon receiving termination signal) */
74 void exit_kthread(kthread_t *kthread);
75
76 #endif