[PATCH 08/16] posix: Generalize _POSIX_Priority_To_core()

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jun 17 10:51:45 UTC 2016


Move POSIX API priority validation into _POSIX_Priority_To_core().
---
 cpukit/posix/include/rtems/posix/priorityimpl.h | 29 +++++++------------------
 cpukit/posix/src/mutexinit.c                    |  4 +---
 cpukit/posix/src/mutexsetprioceiling.c          |  7 ++----
 cpukit/posix/src/psxpriorityisvalid.c           | 18 ++++++++++-----
 cpukit/posix/src/pthreadcreate.c                |  7 ++----
 cpukit/posix/src/pthreadsetschedparam.c         |  7 ++----
 cpukit/posix/src/pthreadsetschedprio.c          |  3 +--
 7 files changed, 29 insertions(+), 46 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/priorityimpl.h b/cpukit/posix/include/rtems/posix/priorityimpl.h
index 7e770f7..54f5c9c 100644
--- a/cpukit/posix/include/rtems/posix/priorityimpl.h
+++ b/cpukit/posix/include/rtems/posix/priorityimpl.h
@@ -51,7 +51,8 @@ extern "C" {
 int _POSIX_Priority_Get_maximum( const Scheduler_Control *scheduler );
 
 /**
- * @brief Check if POSIX priority is valid.
+ * @brief Checks if the POSIX priority is valid and converts it to the
+ * SuperCore priority.
  * 
  * According to POSIX, numerically higher values represent higher priorities.
  * Thus, SuperCore has priorities run in the opposite sense of the POSIX API.
@@ -65,33 +66,19 @@ int _POSIX_Priority_Get_maximum( const Scheduler_Control *scheduler );
  * having N priorities.
  *
  * @param[in] scheduler The scheduler instance.
- * @param[in] priority The POSIX API priority to test.
+ * @param[in] posix_priority The POSIX API priority to test and convert.
+ * @param[out] core_priority_p The corresponding SuperCore API priority.
  *
- * @retval true The priority is valid.
+ * @retval true The priority is valid and the conversion was successful.
  * @retval false Otherwise.
  */
-bool _POSIX_Priority_Is_valid(
+bool _POSIX_Priority_To_core(
   const Scheduler_Control *scheduler,
-  int                      priority
+  int                      posix_priority,
+  Priority_Control        *core_priority_p
 );
 
 /**
- * @brief Converts POSIX priority to SuperCore priority.
- *
- * @param[in] scheduler The scheduler instance.
- * @param[in] priority The POSIX API priority.
- *
- * @return Returns the corresponding SuperCore priority.
- */
-RTEMS_INLINE_ROUTINE Priority_Control _POSIX_Priority_To_core(
-  const Scheduler_Control *scheduler,
-  int                      priority
-)
-{
-  return scheduler->maximum_priority - (Priority_Control) priority;
-}
-
-/**
  * @brief Converts SuperCore priority to POSIX priority.
  *
  * @param[in] scheduler The scheduler instance.
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c
index 04c36e1..7fbb53a 100644
--- a/cpukit/posix/src/mutexinit.c
+++ b/cpukit/posix/src/mutexinit.c
@@ -116,11 +116,9 @@ int pthread_mutex_init(
       prio_ceiling = _POSIX_Priority_Get_maximum( scheduler );
     }
 
-    if ( !_POSIX_Priority_Is_valid( scheduler, prio_ceiling ) ) {
+    if ( !_POSIX_Priority_To_core( scheduler, prio_ceiling, &priority ) ) {
       return EINVAL;
     }
-
-    priority = _POSIX_Priority_To_core( scheduler, prio_ceiling );
   }
 
   the_mutex = _POSIX_Mutex_Allocate();
diff --git a/cpukit/posix/src/mutexsetprioceiling.c b/cpukit/posix/src/mutexsetprioceiling.c
index 65b93c7..f1aa741 100644
--- a/cpukit/posix/src/mutexsetprioceiling.c
+++ b/cpukit/posix/src/mutexsetprioceiling.c
@@ -33,6 +33,7 @@ int pthread_mutex_setprioceiling(
 {
   POSIX_Mutex_Control     *the_mutex;
   const Scheduler_Control *scheduler;
+  Priority_Control         priority;
   int                      error;
   int                      unlock_error;
 
@@ -59,12 +60,8 @@ int pthread_mutex_setprioceiling(
     the_mutex->Mutex.priority_ceiling
   );
 
-  if ( _POSIX_Priority_Is_valid( scheduler, prioceiling ) ) {
-    Priority_Control priority;
-
-    priority = _POSIX_Priority_To_core( scheduler, prioceiling );
+  if ( _POSIX_Priority_To_core( scheduler, prioceiling, &priority ) ) {
     the_mutex->Mutex.priority_ceiling = priority;
-
     error = 0;
   } else {
     error = EINVAL;
diff --git a/cpukit/posix/src/psxpriorityisvalid.c b/cpukit/posix/src/psxpriorityisvalid.c
index ea7f6f4..2d3a0d4 100644
--- a/cpukit/posix/src/psxpriorityisvalid.c
+++ b/cpukit/posix/src/psxpriorityisvalid.c
@@ -29,12 +29,20 @@ int _POSIX_Priority_Get_maximum( const Scheduler_Control *scheduler )
   }
 }
 
-bool _POSIX_Priority_Is_valid(
+bool _POSIX_Priority_To_core(
   const Scheduler_Control *scheduler,
-  int                      priority
+  int                      posix_priority,
+  Priority_Control        *core_priority_p
 )
 {
-  return priority >= POSIX_SCHEDULER_MINIMUM_PRIORITY
-    && (Priority_Control) priority < scheduler->maximum_priority;
-}
+  Priority_Control core_posix_priority;
+  Priority_Control core_priority;
+
+  core_posix_priority = (Priority_Control) posix_priority;
+  core_priority = scheduler->maximum_priority - core_posix_priority;
 
+  *core_priority_p = core_priority;
+
+  return posix_priority >= POSIX_SCHEDULER_MINIMUM_PRIORITY
+    && core_posix_priority < scheduler->maximum_priority;
+}
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index a4b4684..b471625 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -154,17 +154,14 @@ int pthread_create(
 
   scheduler = _Scheduler_Get_own( executing );
 
-  if ( !_POSIX_Priority_Is_valid( scheduler, low_prio ) ) {
+  if ( !_POSIX_Priority_To_core( scheduler, low_prio, &core_low_prio ) ) {
     return EINVAL;
   }
 
-  if ( !_POSIX_Priority_Is_valid( scheduler, high_prio ) ) {
+  if ( !_POSIX_Priority_To_core( scheduler, high_prio, &core_high_prio ) ) {
     return EINVAL;
   }
 
-  core_low_prio = _POSIX_Priority_To_core( scheduler, low_prio );
-  core_high_prio = _POSIX_Priority_To_core( scheduler, high_prio );
-
 #if defined(RTEMS_SMP)
 #if __RTEMS_HAVE_SYS_CPUSET_H__
   status = _CPU_set_Is_valid( the_attr->affinityset, the_attr->affinitysetsize );
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
index 148391d..e6c779c 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -66,19 +66,16 @@ static bool _POSIX_Set_sched_param_filter(
     high_prio = low_prio;
   }
 
-  if ( !_POSIX_Priority_Is_valid( scheduler, low_prio ) ) {
+  if ( !_POSIX_Priority_To_core( scheduler, low_prio, &core_low_prio ) ) {
     context->error = EINVAL;
     return false;
   }
 
-  if ( !_POSIX_Priority_Is_valid( scheduler, high_prio ) ) {
+  if ( !_POSIX_Priority_To_core( scheduler, high_prio, &core_high_prio ) ) {
     context->error = EINVAL;
     return false;
   }
 
-  core_low_prio = _POSIX_Priority_To_core( scheduler, low_prio );
-  core_high_prio = _POSIX_Priority_To_core( scheduler, high_prio );
-
   *new_priority_p = core_high_prio;
 
   current_priority = the_thread->current_priority;
diff --git a/cpukit/posix/src/pthreadsetschedprio.c b/cpukit/posix/src/pthreadsetschedprio.c
index dace70a..25973f7 100644
--- a/cpukit/posix/src/pthreadsetschedprio.c
+++ b/cpukit/posix/src/pthreadsetschedprio.c
@@ -40,12 +40,11 @@ static bool _POSIX_Set_sched_prio_filter(
   prio = context->prio;
   scheduler = _Scheduler_Get_own( the_thread );
 
-  if ( !_POSIX_Priority_Is_valid( scheduler, prio ) ) {
+  if ( !_POSIX_Priority_To_core( scheduler, prio, &new_priority ) ) {
     context->error = EINVAL;
     return false;
   }
 
-  new_priority = _POSIX_Priority_To_core( scheduler, prio );
   *new_priority_p = new_priority;
 
   current_priority = the_thread->current_priority;
-- 
1.8.4.5




More information about the devel mailing list