29 #ifndef _CSP_THREAD_H_ 30 #define _CSP_THREAD_H_ 40 #if defined(CSP_POSIX) || defined(CSP_MACOSX) 45 #define csp_thread_exit() pthread_exit(NULL) 47 #define csp_thread_kill(thread) pthread_cancel((pthread_t)thread); pthread_join((pthread_t)thread, NULL); 49 typedef pthread_t csp_thread_handle_t;
50 typedef void * csp_thread_return_t;
52 #define CSP_DEFINE_TASK(task_name) csp_thread_return_t task_name(void * param) 53 #define CSP_TASK_RETURN NULL 55 #define csp_sleep_ms(time_ms) usleep(time_ms * 1000); 60 #if defined(CSP_WINDOWS) 66 #define csp_thread_exit() _endthreadex(0) 68 typedef HANDLE csp_thread_handle_t;
69 typedef unsigned int csp_thread_return_t;
71 #define CSP_DEFINE_TASK(task_name) csp_thread_return_t __attribute__((stdcall)) task_name(void * param) 72 #define CSP_TASK_RETURN 0 74 #define csp_sleep_ms(time_ms) Sleep(time_ms); 79 #if defined(CSP_FREERTOS) 84 #if INCLUDE_vTaskDelete 85 #define csp_thread_exit() vTaskDelete(NULL) 87 #define csp_thread_exit() 90 #if INCLUDE_vTaskDelete 91 #define csp_thread_kill(thread) vTaskDelete(NULL) 93 #define csp_thread_kill() 96 typedef xTaskHandle csp_thread_handle_t;
97 typedef void csp_thread_return_t;
99 #define CSP_DEFINE_TASK(task_name) csp_thread_return_t task_name(void * param) 100 #define CSP_TASK_RETURN 102 #define csp_sleep_ms(time_ms) vTaskDelay(time_ms / portTICK_RATE_MS); 104 #endif // CSP_FREERTOS 107 int csp_thread_create(csp_thread_return_t (* routine)(
void *),
const char *
const thread_name,
unsigned short stack_depth,
void * parameters,
unsigned int priority, csp_thread_handle_t * handle);
109 int csp_thread_create(csp_thread_return_t (* routine)(
void *)__attribute__((stdcall)),
const char *
const thread_name,
unsigned short stack_depth,
void * parameters,
unsigned int priority, csp_thread_handle_t * handle);
116 #endif // _CSP_THREAD_H_
int csp_thread_create(csp_thread_return_t(*routine)(void *), const char *const thread_name, unsigned short stack_depth, void *parameters, unsigned int priority, csp_thread_handle_t *handle)