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