diff --git a/include/cia/sync.h b/include/cia/sync.h index 4eb436a..330a2f9 100644 --- a/include/cia/sync.h +++ b/include/cia/sync.h @@ -15,3 +15,4 @@ struct Cia_Mutex { void cia_mutex_init(Cia_Mutex *mutex); void cia_mutex_lock(Cia_Mutex *mutex); void cia_mutex_unlock(Cia_Mutex *mutex); + diff --git a/include/tinyrt.h b/include/tinyrt.h index 09d85eb..6212855 100644 --- a/include/tinyrt.h +++ b/include/tinyrt.h @@ -51,7 +51,6 @@ _Noreturn static void _rt_program_exit(int code); // Thread API struct _RT_Thread typedef _RT_Thread; struct _RT_Thread { - u64 tid; void *handle; }; static _RT_Status _rt_thread_current(_RT_Thread *thread); diff --git a/os/linux/tinyrt-threads.c b/os/linux/tinyrt-threads.c index fc03e51..9e53b41 100644 --- a/os/linux/tinyrt-threads.c +++ b/os/linux/tinyrt-threads.c @@ -10,7 +10,8 @@ extern i64 _cia_start_thread( ); static _RT_Status _rt_thread_current(_RT_Thread *thread) { - return _RT_ERROR_NOT_IMPLEMENTED; + thread->handle = (void *)((u64)__builtin_frame_address(0) & ~(cia_stack_size - 1)); + return _RT_STATUS_OK; } static _RT_Status _rt_thread_create(_RT_Thread *thread, int (*thread_fn)(void *ctx), void *ctx) { @@ -29,6 +30,9 @@ static _RT_Status _rt_thread_create(_RT_Thread *thread, int (*thread_fn)(void *c for(int i = 0; i < cia_tls_image_size; ++i) { tls_base[i] = ((u8 *)cia_tls_image_base)[i]; } + // Initialize the _RT_Thread handle, which would point to + // the TCB + thread->handle = tcb; // Create the new thread u64 flags = 0; // flags |= CLONE_CHILD_CLEARTID;