POK
|
00001 /* 00002 * POK header 00003 * 00004 * The following file is a part of the POK project. Any modification should 00005 * made according to the POK licence. You CANNOT use this file or a part of 00006 * this file is this part of a file for your own project 00007 * 00008 * For more information on the POK licence, please see our LICENCE FILE 00009 * 00010 * Please follow the coding guidelines described in doc/CODING_GUIDELINES 00011 * 00012 * Copyright (c) 2007-2009 POK team 00013 * 00014 * Created by julien on Thu Jan 15 23:34:13 2009 00015 */ 00016 00017 #ifndef __POK_THREAD_H__ 00018 #define __POK_THREAD_H__ 00019 00020 #include <core/dependencies.h> 00021 00022 #ifdef POK_NEEDS_THREADS 00023 00024 #include <types.h> 00025 #include <errno.h> 00026 #include <core/syscall.h> 00027 00028 #define POK_THREAD_DEFAULT_PRIORITY 42 00029 00030 #define POK_DEFAULT_STACK_SIZE 2048 00031 00032 typedef struct 00033 { 00034 uint8_t priority; 00035 void* entry; 00036 uint64_t period; 00037 uint64_t deadline; 00038 uint64_t time_capacity; 00039 uint32_t stack_size; 00040 uint32_t state; 00041 } pok_thread_attr_t; 00042 00043 00044 void pok_thread_init (void); 00045 pok_ret_t pok_thread_create (uint32_t* thread_id, const pok_thread_attr_t* attr); 00046 pok_ret_t pok_thread_sleep (const pok_time_t ms); 00047 pok_ret_t pok_thread_sleep_until (const pok_time_t ms); 00048 pok_ret_t pok_thread_lock (); 00049 pok_ret_t pok_thread_unlock (const uint32_t thread_id); 00050 pok_ret_t pok_thread_yield (); 00051 unsigned int pok_thread_current (void); 00052 void pok_thread_start (void (*entry)(), uint32_t id); 00053 void pok_thread_switch (uint32_t elected_id); 00054 pok_ret_t pok_thread_wait_infinite (); 00055 void pok_thread_wrapper (); 00056 pok_ret_t pok_thread_attr_init (pok_thread_attr_t* attr); 00057 pok_ret_t pok_thread_period (); 00058 pok_ret_t pok_thread_id (uint32_t* thread_id); 00059 void pok_thread_init (void); 00060 pok_ret_t pok_thread_status(const uint32_t thread_id, pok_thread_attr_t* attr); 00061 pok_ret_t pok_thread_delayed_start(const uint32_t thread_id, const pok_time_t ms); 00062 pok_ret_t pok_thread_set_priority(const uint32_t thread_id, const uint32_t priority); 00063 pok_ret_t pok_thread_resume(const uint32_t thread_id); 00064 00065 #define pok_thread_sleep_until(time) pok_syscall2(POK_SYSCALL_THREAD_SLEEP_UNTIL,(uint32_t)time,0) 00066 00067 #define pok_thread_wait_infinite() pok_thread_suspend() 00068 00069 #define pok_thread_suspend() pok_syscall2(POK_SYSCALL_THREAD_SUSPEND,NULL,NULL) 00070 00071 #define pok_thread_suspend_target(thread_id) pok_syscall2(POK_SYSCALL_THREAD_SUSPEND_TARGET,thread_id,0) 00072 00073 /* 00074 * Similar to: pok_ret_t pok_thread_suspend (void); 00075 */ 00076 00077 #define pok_thread_restart(thread_id) pok_syscall2(POK_SYSCALL_THREAD_RESTART,thread_id,0) 00078 /* 00079 * similar to: 00080 * pok_ret_t pok_thread_restart (uint32_t thread_id); 00081 */ 00082 00083 #define pok_thread_stop_self() pok_syscall2(POK_SYSCALL_THREAD_STOPSELF, 0, 0) 00084 /* 00085 * similar to: 00086 * pok_ret_t pok_thread_stop_self (); 00087 */ 00088 00089 #define pok_thread_stop(id) pok_syscall2(POK_SYSCALL_THREAD_STOP,id,NULL) 00090 /* 00091 * similar to: pok_ret_t pok_thread_stop (const uint32_t tid); 00092 */ 00093 00094 #endif /* __POK_NEEDS_THREADS */ 00095 #endif /* __POK_THREAD_H__ */