summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-15 16:31:33 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-22 14:00:28 +0200
commit1a4eac500c9a2942f4aff7e27ccdfae3b99c4cb9 (patch)
treef43e5044a2b719a8cfc04cf58a5a31d620bd9eca
parentposix: Make POSIX API aware of scheduler instances (diff)
downloadrtems-1a4eac500c9a2942f4aff7e27ccdfae3b99c4cb9.tar.bz2
posix: Generalize _POSIX_Priority_To_core()
Move POSIX API priority validation into _POSIX_Priority_To_core().
-rw-r--r--cpukit/posix/include/rtems/posix/priorityimpl.h16
-rw-r--r--cpukit/posix/src/mutexinit.c8
-rw-r--r--cpukit/posix/src/mutexsetprioceiling.c9
-rw-r--r--cpukit/posix/src/psxpriorityisvalid.c18
-rw-r--r--cpukit/posix/src/pthreadcreate.c10
-rw-r--r--cpukit/posix/src/pthreadsetschedparam.c10
-rw-r--r--cpukit/posix/src/pthreadsetschedprio.c5
7 files changed, 44 insertions, 32 deletions
diff --git a/cpukit/posix/include/rtems/posix/priorityimpl.h b/cpukit/posix/include/rtems/posix/priorityimpl.h
index d06b600f04..ae2e763fba 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 Converts the POSIX API priority to the corresponding SuperCore
+ * priority and validates it.
*
* According to POSIX, numerically higher values represent higher priorities.
* Thus, SuperCore has priorities run in the opposite sense of the POSIX API.
@@ -65,14 +66,17 @@ 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] priority The POSIX API priority to convert and validate.
+ * @param[out] valid Indicates if the POSIX API priority is valid and a
+ * corresponding SuperCore priority in the specified scheduler instance
+ * exists.
*
- * @retval true The priority is valid.
- * @retval false Otherwise.
+ * @return The corresponding SuperCore priority.
*/
-bool _POSIX_Priority_Is_valid(
+Priority_Control _POSIX_Priority_To_core(
const Scheduler_Control *scheduler,
- int priority
+ int priority,
+ bool *valid
);
/**
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c
index 04c36e11bb..2cda90ea05 100644
--- a/cpukit/posix/src/mutexinit.c
+++ b/cpukit/posix/src/mutexinit.c
@@ -107,7 +107,8 @@ int pthread_mutex_init(
#endif
if ( protocol == POSIX_MUTEX_PRIORITY_CEILING ) {
- int prio_ceiling;
+ int prio_ceiling;
+ bool valid;
scheduler = _Scheduler_Get_own( _Thread_Get_executing() );
prio_ceiling = the_attr->prio_ceiling;
@@ -116,11 +117,10 @@ int pthread_mutex_init(
prio_ceiling = _POSIX_Priority_Get_maximum( scheduler );
}
- if ( !_POSIX_Priority_Is_valid( scheduler, prio_ceiling ) ) {
+ priority = _POSIX_Priority_To_core( scheduler, prio_ceiling, &valid );
+ if ( !valid ) {
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 65b93c7a56..478aafa6e0 100644
--- a/cpukit/posix/src/mutexsetprioceiling.c
+++ b/cpukit/posix/src/mutexsetprioceiling.c
@@ -33,6 +33,8 @@ int pthread_mutex_setprioceiling(
{
POSIX_Mutex_Control *the_mutex;
const Scheduler_Control *scheduler;
+ bool valid;
+ Priority_Control priority;
int error;
int unlock_error;
@@ -59,12 +61,9 @@ 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 );
+ priority = _POSIX_Priority_To_core( scheduler, prioceiling, &valid );
+ if ( valid ) {
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 ea7f6f4382..22c4ac0b87 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(
+Priority_Control _POSIX_Priority_To_core(
const Scheduler_Control *scheduler,
- int priority
+ int posix_priority,
+ bool *valid
)
{
- 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;
+ *valid = ( posix_priority >= POSIX_SCHEDULER_MINIMUM_PRIORITY
+ && core_posix_priority < scheduler->maximum_priority );
+
+ return core_priority;
+}
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index a4b468494a..b266a4cd7f 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -62,6 +62,7 @@ int pthread_create(
const pthread_attr_t *the_attr;
int low_prio;
int high_prio;
+ bool valid;
Priority_Control core_low_prio;
Priority_Control core_high_prio;
Thread_CPU_budget_algorithms budget_algorithm;
@@ -154,17 +155,16 @@ int pthread_create(
scheduler = _Scheduler_Get_own( executing );
- if ( !_POSIX_Priority_Is_valid( scheduler, low_prio ) ) {
+ core_low_prio = _POSIX_Priority_To_core( scheduler, low_prio, &valid );
+ if ( !valid ) {
return EINVAL;
}
- if ( !_POSIX_Priority_Is_valid( scheduler, high_prio ) ) {
+ core_high_prio = _POSIX_Priority_To_core( scheduler, high_prio, &valid );
+ if ( !valid ) {
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 148391dcc4..92560fc79c 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -50,6 +50,7 @@ static bool _POSIX_Set_sched_param_filter(
POSIX_API_Control *api;
int low_prio;
int high_prio;
+ bool valid;
Priority_Control core_low_prio;
Priority_Control core_high_prio;
Priority_Control current_priority;
@@ -66,19 +67,18 @@ static bool _POSIX_Set_sched_param_filter(
high_prio = low_prio;
}
- if ( !_POSIX_Priority_Is_valid( scheduler, low_prio ) ) {
+ core_low_prio = _POSIX_Priority_To_core( scheduler, low_prio, &valid );
+ if ( !valid ) {
context->error = EINVAL;
return false;
}
- if ( !_POSIX_Priority_Is_valid( scheduler, high_prio ) ) {
+ core_high_prio = _POSIX_Priority_To_core( scheduler, high_prio, &valid );
+ if ( !valid ) {
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 dace70ad1f..fd77b6894a 100644
--- a/cpukit/posix/src/pthreadsetschedprio.c
+++ b/cpukit/posix/src/pthreadsetschedprio.c
@@ -33,6 +33,7 @@ static bool _POSIX_Set_sched_prio_filter(
int prio;
const Scheduler_Control *scheduler;
POSIX_API_Control *api;
+ bool valid;
Priority_Control current_priority;
Priority_Control new_priority;
@@ -40,12 +41,12 @@ static bool _POSIX_Set_sched_prio_filter(
prio = context->prio;
scheduler = _Scheduler_Get_own( the_thread );
- if ( !_POSIX_Priority_Is_valid( scheduler, prio ) ) {
+ new_priority = _POSIX_Priority_To_core( scheduler, prio, &valid );
+ if ( !valid ) {
context->error = EINVAL;
return false;
}
- new_priority = _POSIX_Priority_To_core( scheduler, prio );
*new_priority_p = new_priority;
current_priority = the_thread->current_priority;