[rtems commit] posix: Fix pthread_setschedparam()

Sebastian Huber sebh at rtems.org
Mon Jun 13 13:20:14 UTC 2016


Module:    rtems
Branch:    master
Commit:    fc30ac5973aae2393fb318b56346368f5e9b4493
Changeset: http://git.rtems.org/rtems/commit/?id=fc30ac5973aae2393fb318b56346368f5e9b4493

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Jun 13 15:10:31 2016 +0200

posix: Fix pthread_setschedparam()

Close #2735.

---

 cpukit/posix/src/pthreadsetschedparam.c |  2 +-
 testsuites/psxtests/psx05/init.c        | 54 +++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
index af8c882..a6882b9 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -112,7 +112,7 @@ int pthread_setschedparam(
     case SCHED_OTHER:
     case SCHED_FIFO:
     case SCHED_RR:
-      _Thread_Set_priority( the_thread, new_priority, &unused, true );
+      _Thread_Set_priority( the_thread, new_priority, &unused, false );
       break;
 
     case SCHED_SPORADIC:
diff --git a/testsuites/psxtests/psx05/init.c b/testsuites/psxtests/psx05/init.c
index d3311fc..6e7229e 100644
--- a/testsuites/psxtests/psx05/init.c
+++ b/testsuites/psxtests/psx05/init.c
@@ -156,6 +156,59 @@ static void test_get_priority( void )
   rtems_test_assert( status == 0 );
 }
 
+static void *counter_task(void *arg)
+{
+  int *counter;
+
+  counter = arg;
+
+  while ( *counter >= 0 ) {
+    ++(*counter);
+
+    sched_yield();
+  }
+
+  return counter;
+}
+
+static void test_set_priority( void )
+{
+  int                 status;
+  int                 policy;
+  struct sched_param  param;
+  pthread_t           thread;
+  int                 counter;
+  void               *exit_code;
+
+  counter = 0;
+
+  status = pthread_getschedparam( pthread_self(), &policy, &param );
+  rtems_test_assert( status == 0 );
+
+  status = pthread_create( &thread, NULL, counter_task, &counter);
+  rtems_test_assert( status == 0 );
+
+  ++param.sched_priority;
+  status = pthread_setschedparam( pthread_self(), policy, &param );
+  rtems_test_assert( status == 0 );
+
+  rtems_test_assert( counter == 0 );
+
+  --param.sched_priority;
+  status = pthread_setschedparam( pthread_self(), policy, &param );
+  rtems_test_assert( status == 0 );
+
+  rtems_test_assert( counter == 1 );
+
+  counter = -1;
+  sched_yield();
+
+  status = pthread_join( thread, &exit_code );
+  rtems_test_assert( status == 0 );
+  rtems_test_assert( exit_code == &counter );
+  rtems_test_assert( counter == -1 );
+}
+
 void *POSIX_Init(
   void *argument
 )
@@ -178,6 +231,7 @@ void *POSIX_Init(
   TEST_BEGIN();
 
   test_get_priority();
+  test_set_priority();
 
   /* set the time of day, and print our buffer in multiple ways */
 



More information about the vc mailing list