summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-27 08:02:03 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-30 16:16:23 +0200
commit5a598ac99b0de720a04afc5e2ac6764117589b90 (patch)
tree811d57df33c0f4fcc1cce61095cb5c0a33eadd7c /cpukit/rtems/src
parentposix: Delete POSIX_Mutex_Protocol::process_shared (diff)
downloadrtems-5a598ac99b0de720a04afc5e2ac6764117589b90.tar.bz2
score: Add CORE mutex variants
Add CORE_recursive_mutex_Control and CORE_ceiling_mutex_Control to avoid the run-time evaluation of attributes to figure out how a particular mutex methods should behave. Start with the no protocol variants. This eliminates the CORE_MUTEX_DISCIPLINES_FIFO and CORE_MUTEX_DISCIPLINES_PRIORITY disciplines.
Diffstat (limited to 'cpukit/rtems/src')
-rw-r--r--cpukit/rtems/src/semcreate.c59
-rw-r--r--cpukit/rtems/src/semdelete.c8
-rw-r--r--cpukit/rtems/src/semflush.c1
-rw-r--r--cpukit/rtems/src/semobtain.c15
-rw-r--r--cpukit/rtems/src/semrelease.c10
-rw-r--r--cpukit/rtems/src/semsetpriority.c3
6 files changed, 64 insertions, 32 deletions
diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c
index 455182bd90..91f693c6c0 100644
--- a/cpukit/rtems/src/semcreate.c
+++ b/cpukit/rtems/src/semcreate.c
@@ -63,6 +63,7 @@ rtems_status_code rtems_semaphore_create(
{
Semaphore_Control *the_semaphore;
CORE_mutex_Attributes the_mutex_attr;
+ Thread_Control *executing;
Status_Control status;
if ( !rtems_is_name_valid( name ) )
@@ -136,6 +137,7 @@ rtems_status_code rtems_semaphore_create(
#endif
the_semaphore->attribute_set = attribute_set;
+ executing = _Thread_Get_executing();
if ( _Attributes_Is_priority( attribute_set ) ) {
the_semaphore->discipline = SEMAPHORE_DISCIPLINE_PRIORITY;
@@ -163,43 +165,46 @@ rtems_status_code rtems_semaphore_create(
status = _MRSP_Initialize(
&the_semaphore->Core_control.mrsp,
priority_ceiling,
- _Thread_Get_executing(),
+ executing,
count != 1
);
#endif
- } else {
- the_semaphore->variant = SEMAPHORE_VARIANT_MUTEX;
+ } else if (
+ !_Attributes_Is_inherit_priority( attribute_set )
+ && !_Attributes_Is_priority_ceiling( attribute_set )
+ ) {
+ _Assert( _Attributes_Is_binary_semaphore( attribute_set ) );
+ the_semaphore->variant = SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL;
+ _CORE_recursive_mutex_Initialize(
+ &the_semaphore->Core_control.Mutex.Recursive
+ );
+
+ if ( count == 0 ) {
+ _CORE_mutex_Set_owner(
+ &the_semaphore->Core_control.Mutex.Recursive.Mutex,
+ executing
+ );
+ }
+ status = STATUS_SUCCESSFUL;
+ } else {
_Assert( _Attributes_Is_binary_semaphore( attribute_set ) );
+ the_semaphore->variant = SEMAPHORE_VARIANT_MUTEX;
- /*
- * It is either simple binary semaphore or a more powerful mutex
- * style binary semaphore. This is the mutex style.
- */
- if ( _Attributes_Is_priority( attribute_set ) )
- the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY;
- else
- the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_FIFO;
-
- the_mutex_attr.priority_ceiling = _RTEMS_tasks_Priority_to_Core(
- priority_ceiling
- );
+ the_mutex_attr.priority_ceiling =
+ _RTEMS_tasks_Priority_to_Core( priority_ceiling );
the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES;
- the_mutex_attr.only_owner_release = false;
-
- if ( the_mutex_attr.discipline == CORE_MUTEX_DISCIPLINES_PRIORITY ) {
- if ( _Attributes_Is_inherit_priority( attribute_set ) ) {
- the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT;
- the_mutex_attr.only_owner_release = true;
- } else if ( _Attributes_Is_priority_ceiling( attribute_set ) ) {
- the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING;
- the_mutex_attr.only_owner_release = true;
- }
+
+ if ( _Attributes_Is_inherit_priority( attribute_set ) ) {
+ the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT;
+ } else {
+ _Assert( _Attributes_Is_priority_ceiling( attribute_set ) );
+ the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING;
}
status = _CORE_mutex_Initialize(
- &the_semaphore->Core_control.mutex,
- _Thread_Get_executing(),
+ &the_semaphore->Core_control.Mutex.Recursive.Mutex,
+ executing,
&the_mutex_attr,
count != 1
);
diff --git a/cpukit/rtems/src/semdelete.c b/cpukit/rtems/src/semdelete.c
index 34da496b8d..365d895362 100644
--- a/cpukit/rtems/src/semdelete.c
+++ b/cpukit/rtems/src/semdelete.c
@@ -51,7 +51,12 @@ rtems_status_code rtems_semaphore_delete(
switch ( the_semaphore->variant ) {
case SEMAPHORE_VARIANT_MUTEX:
- if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) ) {
+ case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
+ if (
+ _CORE_mutex_Is_locked(
+ &the_semaphore->Core_control.Mutex.Recursive.Mutex
+ )
+ ) {
status = STATUS_RESOURCE_IN_USE;
} else {
status = STATUS_SUCCESSFUL;
@@ -92,6 +97,7 @@ rtems_status_code rtems_semaphore_delete(
default:
_Assert(
the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX
+ || the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL
|| the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
|| the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
);
diff --git a/cpukit/rtems/src/semflush.c b/cpukit/rtems/src/semflush.c
index 0db8c34dfb..6c1f4ddf2c 100644
--- a/cpukit/rtems/src/semflush.c
+++ b/cpukit/rtems/src/semflush.c
@@ -58,6 +58,7 @@ rtems_status_code rtems_semaphore_flush( rtems_id id )
default:
_Assert(
the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX
+ || the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL
|| the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
|| the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
);
diff --git a/cpukit/rtems/src/semobtain.c b/cpukit/rtems/src/semobtain.c
index 5eebfa14b2..a7774d6f91 100644
--- a/cpukit/rtems/src/semobtain.c
+++ b/cpukit/rtems/src/semobtain.c
@@ -29,7 +29,7 @@ THREAD_QUEUE_OBJECT_ASSERT(
THREAD_QUEUE_OBJECT_ASSERT(
Semaphore_Control,
- Core_control.mutex.Wait_queue
+ Core_control.Mutex.Recursive.Mutex.Wait_queue
);
THREAD_QUEUE_OBJECT_ASSERT(
@@ -83,13 +83,24 @@ rtems_status_code rtems_semaphore_obtain(
#endif
case SEMAPHORE_VARIANT_MUTEX:
status = _CORE_mutex_Seize(
- &the_semaphore->Core_control.mutex,
+ &the_semaphore->Core_control.Mutex.Recursive.Mutex,
executing,
wait,
timeout,
&queue_context
);
break;
+ case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
+ status = _CORE_recursive_mutex_Seize_no_protocol(
+ &the_semaphore->Core_control.Mutex.Recursive,
+ _Semaphore_Get_operations( the_semaphore ),
+ executing,
+ wait,
+ timeout,
+ _CORE_recursive_mutex_Seize_nested,
+ &queue_context
+ );
+ break;
default:
_Assert(
the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
diff --git a/cpukit/rtems/src/semrelease.c b/cpukit/rtems/src/semrelease.c
index 3e13334e87..7cd92cfe0d 100644
--- a/cpukit/rtems/src/semrelease.c
+++ b/cpukit/rtems/src/semrelease.c
@@ -57,10 +57,18 @@ rtems_status_code rtems_semaphore_release( rtems_id id )
#endif
case SEMAPHORE_VARIANT_MUTEX:
status = _CORE_mutex_Surrender(
- &the_semaphore->Core_control.mutex,
+ &the_semaphore->Core_control.Mutex.Recursive.Mutex,
&queue_context
);
break;
+ case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
+ _CORE_recursive_mutex_Surrender_no_protocol_classic(
+ &the_semaphore->Core_control.Mutex.Recursive,
+ _Semaphore_Get_operations( the_semaphore ),
+ &queue_context
+ );
+ status = STATUS_SUCCESSFUL;
+ break;
case SEMAPHORE_VARIANT_SIMPLE_BINARY:
status = _CORE_semaphore_Surrender(
&the_semaphore->Core_control.semaphore,
diff --git a/cpukit/rtems/src/semsetpriority.c b/cpukit/rtems/src/semsetpriority.c
index ee6614af0f..0a8c58cde2 100644
--- a/cpukit/rtems/src/semsetpriority.c
+++ b/cpukit/rtems/src/semsetpriority.c
@@ -54,8 +54,9 @@ static rtems_status_code _Semaphore_Set_priority(
} else
#endif
if ( _Attributes_Is_priority_ceiling( attribute_set ) ) {
- CORE_mutex_Control *mutex = &the_semaphore->Core_control.mutex;
+ CORE_mutex_Control *mutex;
+ mutex = &the_semaphore->Core_control.Mutex.Recursive.Mutex;
_CORE_mutex_Acquire_critical( mutex, queue_context );
old_priority = mutex->Attributes.priority_ceiling;