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