[haiku-commits] r35098 - haiku/trunk/src/system/libroot/posix/pthread

  • From: korli@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 16 Jan 2010 16:19:50 +0100 (CET)

Author: korli
Date: 2010-01-16 16:19:50 +0100 (Sat, 16 Jan 2010)
New Revision: 35098
Changeset: http://dev.haiku-os.org/changeset/35098/haiku
Ticket: http://dev.haiku-os.org/ticket/5271

Modified:
   haiku/trunk/src/system/libroot/posix/pthread/pthread.c
Log:
* 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.


Modified: haiku/trunk/src/system/libroot/posix/pthread/pthread.c
===================================================================
--- haiku/trunk/src/system/libroot/posix/pthread/pthread.c      2010-01-16 
13:56:59 UTC (rev 35097)
+++ haiku/trunk/src/system/libroot/posix/pthread/pthread.c      2010-01-16 
15:19:50 UTC (rev 35098)
@@ -52,6 +52,10 @@
 __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 @@
 }
 
 
+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
 
 


Other related posts: