[haiku-commits] r33783 - in haiku/trunk: headers/posix src/system/libroot/posix src/system/libroot/posix/pthread

  • From: korli@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 26 Oct 2009 23:56:43 +0100 (CET)

Author: korli
Date: 2009-10-26 23:56:43 +0100 (Mon, 26 Oct 2009)
New Revision: 33783
Changeset: http://dev.haiku-os.org/changeset/33783/haiku

Modified:
   haiku/trunk/headers/posix/pthread.h
   haiku/trunk/headers/posix/sched.h
   haiku/trunk/src/system/libroot/posix/pthread/pthread_attr.c
   haiku/trunk/src/system/libroot/posix/scheduler.cpp
Log:
Patch from Michael Franz (ticket #4696): sched.h and pthreads to allow setting 
of the thread priority


Modified: haiku/trunk/headers/posix/pthread.h
===================================================================
--- haiku/trunk/headers/posix/pthread.h 2009-10-26 22:28:47 UTC (rev 33782)
+++ haiku/trunk/headers/posix/pthread.h 2009-10-26 22:56:43 UTC (rev 33783)
@@ -229,14 +229,14 @@
        int *contentionScope);
 extern int pthread_attr_setscope(pthread_attr_t *attr, int contentionScope);
 
-#if 0  /* Unimplemented attribute functions: */
-
 /* mandatory! */
 extern int pthread_attr_getschedparam(const pthread_attr_t *attr,
        struct sched_param *param);
 extern int pthread_attr_setschedparam(pthread_attr_t *attr,
        const struct sched_param *param);
 
+#if 0   /* Unimplemented attribute functions: */
+
 /* [TPS] */
 extern int pthread_attr_getinheritsched(const pthread_attr_t *attr,
        int *inheritsched);

Modified: haiku/trunk/headers/posix/sched.h
===================================================================
--- haiku/trunk/headers/posix/sched.h   2009-10-26 22:28:47 UTC (rev 33782)
+++ haiku/trunk/headers/posix/sched.h   2009-10-26 22:56:43 UTC (rev 33783)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008, Haiku Inc. All rights reserved.
+ * Copyright 2008-2009, Haiku Inc. All rights reserved.
  * Distributed under the terms of the MIT license.
  */
 #ifndef _SCHED_H_
@@ -9,7 +9,17 @@
 extern "C" {
 #endif
 
+#define SCHED_OTHER    1
+#define SCHED_RR       2
+#define SCHED_FIFO     4
+
+struct sched_param {
+       int sched_priority;
+};
+
 extern int sched_yield(void);
+extern int sched_get_priority_min(int);
+extern int sched_get_priority_max(int);
 
 #ifdef __cplusplus
 }

Modified: haiku/trunk/src/system/libroot/posix/pthread/pthread_attr.c
===================================================================
--- haiku/trunk/src/system/libroot/posix/pthread/pthread_attr.c 2009-10-26 
22:28:47 UTC (rev 33782)
+++ haiku/trunk/src/system/libroot/posix/pthread/pthread_attr.c 2009-10-26 
22:56:43 UTC (rev 33783)
@@ -13,7 +13,6 @@
 
 #include <thread_defs.h>
 
-
 int
 pthread_attr_init(pthread_attr_t *_attr)
 {
@@ -134,3 +133,26 @@
 
        return 0;
 }
+
+int 
+pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param 
*param)
+{
+        if (attr == NULL || param == NULL)
+                return EINVAL;
+
+       (*attr)->sched_priority = param->sched_priority;
+
+       return 0;
+}
+
+int
+pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param 
*param)
+{
+        if (attr == NULL || param == NULL)
+                return EINVAL;
+
+        param->sched_priority = (*attr)->sched_priority;
+
+        return 0;
+}
+

Modified: haiku/trunk/src/system/libroot/posix/scheduler.cpp
===================================================================
--- haiku/trunk/src/system/libroot/posix/scheduler.cpp  2009-10-26 22:28:47 UTC 
(rev 33782)
+++ haiku/trunk/src/system/libroot/posix/scheduler.cpp  2009-10-26 22:56:43 UTC 
(rev 33783)
@@ -1,10 +1,14 @@
 /*
+ * Copyright 2009, Michael Franz
  * Copyright 2008, Andreas Färber, andreas.faerber@xxxxxx
  * Distributed under the terms of the MIT license.
  */
 
+#include <errno.h>
 #include <sched.h>
 
+#include <OS.h>
+
 #include <syscalls.h>
 
 
@@ -15,3 +19,32 @@
        return 0;
 }
 
+
+int
+sched_get_priority_min(int policy)
+{
+       switch (policy) {
+               case SCHED_FIFO:
+               case SCHED_RR:
+               case SCHED_OTHER:
+                       return B_LOW_PRIORITY;
+               default:
+                       errno = EINVAL;
+                       return -1;
+       }
+}
+
+
+int
+sched_get_priority_max(int policy)
+{
+       switch (policy) {
+               case SCHED_FIFO:
+               case SCHED_RR:
+               case SCHED_OTHER:
+                       return B_REAL_TIME_PRIORITY;
+               default:
+                       errno = EINVAL;
+                       return -1;
+       }
+}


Other related posts: