From bafa759148a8c7d7ee34164591511930cac4e8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 24 Feb 2011 17:28:59 +0000 Subject: [PATCH] now correctly init the thread id in the pthread struct for main thread and threads spawned with spawn_thread(). This definitely helps for #7235. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40665 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/libroot/libroot_private.h | 2 ++ src/system/libroot/libroot_init.c | 1 + src/system/libroot/os/thread.c | 5 ++++- src/system/libroot/posix/pthread/pthread.c | 10 +++++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/headers/private/libroot/libroot_private.h b/headers/private/libroot/libroot_private.h index 20d035a10e..eaa9bf2276 100644 --- a/headers/private/libroot/libroot_private.h +++ b/headers/private/libroot/libroot_private.h @@ -41,6 +41,8 @@ void __init_pwd_backend(void); void __reinit_pwd_backend_after_fork(void); void* __arch_get_caller(void); +void __init_pthread(void); + #ifdef __cplusplus } diff --git a/src/system/libroot/libroot_init.c b/src/system/libroot/libroot_init.c index 7739b01828..4b65efa306 100644 --- a/src/system/libroot/libroot_init.c +++ b/src/system/libroot/libroot_init.c @@ -60,6 +60,7 @@ initialize_before(image_id imageID) __init_env(__gRuntimeLoader->program_args); __init_heap_post_env(); __init_pwd_backend(); + __init_pthread(); } diff --git a/src/system/libroot/os/thread.c b/src/system/libroot/os/thread.c index fc014204f5..7b11cd70d2 100644 --- a/src/system/libroot/os/thread.c +++ b/src/system/libroot/os/thread.c @@ -99,7 +99,10 @@ spawn_thread(thread_func entry, const char *name, int32 priority, void *data) attributes.stack_address = NULL; attributes.stack_size = 0; - return _kern_spawn_thread(&attributes); + thread->id = _kern_spawn_thread(&attributes); + if (thread->id < 0) + free(thread); + return thread->id; } diff --git a/src/system/libroot/posix/pthread/pthread.c b/src/system/libroot/posix/pthread/pthread.c index 5dcabc03b3..b67408c1c9 100644 --- a/src/system/libroot/posix/pthread/pthread.c +++ b/src/system/libroot/posix/pthread/pthread.c @@ -5,7 +5,8 @@ */ -#include "pthread_private.h" +#include +#include #include #include @@ -93,6 +94,13 @@ __allocate_pthread(void *data) } +void +__init_pthread(void) +{ + sMainThread.id = find_thread(NULL); +} + + // #pragma mark - public API