summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems/src/semcreate.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-21 17:12:40 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-22 14:00:28 +0200
commitc82835a231351377866ceb82826010ba0485255d (patch)
treea6a891207d89e37f01bc54cf276e4c6cac9c6236 /cpukit/rtems/src/semcreate.c
parentposix: Generalize _POSIX_Priority_To_core() (diff)
downloadrtems-c82835a231351377866ceb82826010ba0485255d.tar.bz2
rtems: Rework RTEMS API to SuperCore priority
Use same structure as POSIX API for thread priority conversion to/from SuperCore.
Diffstat (limited to 'cpukit/rtems/src/semcreate.c')
-rw-r--r--cpukit/rtems/src/semcreate.c82
1 files changed, 50 insertions, 32 deletions
diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c
index bb1c6b4e61..f03475ee33 100644
--- a/cpukit/rtems/src/semcreate.c
+++ b/cpukit/rtems/src/semcreate.c
@@ -22,6 +22,7 @@
#include <rtems/rtems/attrimpl.h>
#include <rtems/rtems/statusimpl.h>
#include <rtems/rtems/tasksimpl.h>
+#include <rtems/score/schedulerimpl.h>
#include <rtems/score/sysstate.h>
#define SEMAPHORE_KIND_MASK ( RTEMS_SEMAPHORE_CLASS | RTEMS_INHERIT_PRIORITY \
@@ -35,12 +36,15 @@ rtems_status_code rtems_semaphore_create(
rtems_id *id
)
{
- Semaphore_Control *the_semaphore;
- Thread_Control *executing;
- Status_Control status;
- rtems_attribute maybe_global;
- rtems_attribute mutex_with_protocol;
- Semaphore_Variant variant;
+ Semaphore_Control *the_semaphore;
+ Thread_Control *executing;
+ Status_Control status;
+ rtems_attribute maybe_global;
+ rtems_attribute mutex_with_protocol;
+ Semaphore_Variant variant;
+ const Scheduler_Control *scheduler;
+ bool valid;
+ Priority_Control priority;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -122,7 +126,6 @@ rtems_status_code rtems_semaphore_create(
}
#endif
- priority_ceiling = _RTEMS_tasks_Priority_to_Core( priority_ceiling );
executing = _Thread_Get_executing();
the_semaphore->variant = variant;
@@ -154,42 +157,57 @@ rtems_status_code rtems_semaphore_create(
status = STATUS_SUCCESSFUL;
break;
case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
- _CORE_ceiling_mutex_Initialize(
- &the_semaphore->Core_control.Mutex,
- priority_ceiling
- );
-
- if ( count == 0 ) {
- Thread_queue_Context queue_context;
+ scheduler = _Scheduler_Get_own( executing );
+ priority = _RTEMS_Priority_To_core( scheduler, priority_ceiling, &valid );
- _Thread_queue_Context_initialize( &queue_context );
- _ISR_lock_ISR_disable( &queue_context.Lock_context );
- _CORE_mutex_Acquire_critical(
- &the_semaphore->Core_control.Mutex.Recursive.Mutex,
- &queue_context
- );
- status = _CORE_ceiling_mutex_Set_owner(
+ if ( valid ) {
+ _CORE_ceiling_mutex_Initialize(
&the_semaphore->Core_control.Mutex,
- executing,
- &queue_context
+ priority
);
- if ( status != STATUS_SUCCESSFUL ) {
- _Thread_queue_Destroy( &the_semaphore->Core_control.Wait_queue );
+ if ( count == 0 ) {
+ Thread_queue_Context queue_context;
+
+ _Thread_queue_Context_initialize( &queue_context );
+ _ISR_lock_ISR_disable( &queue_context.Lock_context );
+ _CORE_mutex_Acquire_critical(
+ &the_semaphore->Core_control.Mutex.Recursive.Mutex,
+ &queue_context
+ );
+ status = _CORE_ceiling_mutex_Set_owner(
+ &the_semaphore->Core_control.Mutex,
+ executing,
+ &queue_context
+ );
+
+ if ( status != STATUS_SUCCESSFUL ) {
+ _Thread_queue_Destroy( &the_semaphore->Core_control.Wait_queue );
+ }
+ } else {
+ status = STATUS_SUCCESSFUL;
}
} else {
- status = STATUS_SUCCESSFUL;
+ status = STATUS_INVALID_PRIORITY;
}
break;
#if defined(RTEMS_SMP)
case SEMAPHORE_VARIANT_MRSP:
- status = _MRSP_Initialize(
- &the_semaphore->Core_control.MRSP,
- priority_ceiling,
- executing,
- count == 0
- );
+ scheduler = _Scheduler_Get_own( executing );
+ priority = _RTEMS_Priority_To_core( scheduler, priority_ceiling, &valid );
+
+ if ( valid ) {
+ status = _MRSP_Initialize(
+ &the_semaphore->Core_control.MRSP,
+ priority,
+ executing,
+ count == 0
+ );
+ } else {
+ status = STATUS_INVALID_PRIORITY;
+ }
+
break;
#endif
default: