POK
thread.h
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Thu Jan 15 23:34:13 2009
15  */
16 
17 #ifndef __POK_THREAD_H__
18 #define __POK_THREAD_H__
19 
20 #include <core/dependencies.h>
21 
22 #ifdef POK_NEEDS_THREADS
23 
24 #include <types.h>
25 #include <errno.h>
26 #include <core/syscall.h>
27 
28 #define POK_THREAD_DEFAULT_PRIORITY 42
29 
30 #define POK_DEFAULT_STACK_SIZE 2048
31 
32 typedef struct
33 {
34  uint8_t priority;
35  void* entry;
36  uint64_t period;
37  uint64_t deadline;
38  uint64_t time_capacity;
39  uint32_t stack_size;
40  uint32_t state;
42 
43 
44 void pok_thread_init (void);
45 pok_ret_t pok_thread_create (uint32_t* thread_id, const pok_thread_attr_t* attr);
46 pok_ret_t pok_thread_sleep (const pok_time_t ms);
47 pok_ret_t pok_thread_sleep_until (const pok_time_t ms);
48 pok_ret_t pok_thread_lock ();
49 pok_ret_t pok_thread_unlock (const uint32_t thread_id);
50 pok_ret_t pok_thread_yield ();
51 unsigned int pok_thread_current (void);
52 void pok_thread_start (void (*entry)(), uint32_t id);
53 void pok_thread_switch (uint32_t elected_id);
54 pok_ret_t pok_thread_wait_infinite ();
55 void pok_thread_wrapper ();
56 pok_ret_t pok_thread_attr_init (pok_thread_attr_t* attr);
57 pok_ret_t pok_thread_period ();
58 pok_ret_t pok_thread_id (uint32_t* thread_id);
59 void pok_thread_init (void);
60 pok_ret_t pok_thread_status(const uint32_t thread_id, pok_thread_attr_t* attr);
61 
62 
63 #define pok_thread_sleep_until(time) pok_syscall2(POK_SYSCALL_THREAD_SLEEP_UNTIL,(uint32_t)time,0)
64 
65 #define pok_thread_wait_infinite() pok_thread_suspend()
66 
67 #define pok_thread_suspend() pok_syscall2(POK_SYSCALL_THREAD_SUSPEND,NULL,NULL)
68 /*
69  * Similar to: pok_ret_t pok_thread_suspend (void);
70  */
71 
72 #define pok_thread_restart(thread_id) pok_syscall2(POK_SYSCALL_THREAD_RESTART,thread_id,0)
73 /*
74  * similar to:
75  * pok_ret_t pok_thread_restart (uint32_t thread_id);
76  */
77 
78 #define pok_thread_stop_self() pok_syscall2(POK_SYSCALL_THREAD_STOPSELF, 0, 0)
79 /*
80  * similar to:
81  * pok_ret_t pok_thread_stop_self ();
82  */
83 
84 #define pok_thread_stop(id) pok_syscall2(POK_SYSCALL_THREAD_STOP,id,NULL)
85 /*
86  * similar to: pok_ret_t pok_thread_stop (const uint32_t tid);
87  */
88 
89 #endif /* __POK_NEEDS_THREADS */
90 #endif /* __POK_THREAD_H__ */