From 0bce4bb917dc49ebdd5d387fbe8d34553d02c9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 16 Jan 2010 15:19:50 +0000 Subject: [PATCH] * don't destroy an already dead thread. Fixed #5271. Maybe we should only make this check on the sMainThread though. * Implementations of pthread_getschedparam and pthread_setschedparam I had since a while. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35098 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/pthread/pthread.c | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/system/libroot/posix/pthread/pthread.c b/src/system/libroot/posix/pthread/pthread.c index ffd1f5a4d4..c1cfd79b08 100644 --- a/src/system/libroot/posix/pthread/pthread.c +++ b/src/system/libroot/posix/pthread/pthread.c @@ -52,6 +52,10 @@ void __pthread_destroy_thread(void) { pthread_thread* thread = pthread_self(); + + // check if the thread is already dead + if ((atomic_get(&thread->flags) & THREAD_DEAD) != 0) + return; // call cleanup handlers while (true) { @@ -243,6 +247,34 @@ pthread_setconcurrency(int newLevel) } +int +pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param) +{ + thread_info info; + status_t status = _kern_get_thread_info(thread->id, &info); + if (status == B_BAD_THREAD_ID) + return ESRCH; + param->sched_priority = info.priority; + if (policy != NULL) + *policy = SCHED_RR; + return 0; +} + + +int +pthread_setschedparam(pthread_t thread, int policy, + const struct sched_param *param) +{ + status_t status; + if (policy != SCHED_RR) + return ENOTSUP; + status = _kern_set_thread_priority(thread->id, param->sched_priority); + if (status == B_BAD_THREAD_ID) + return ESRCH; + return status; +} + + // #pragma mark - Haiku thread API bridge