summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-26 22:29:56 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-30 16:16:22 +0200
commit09c5ca4cb4f30ba9e0c3c3915a70af7ff3916ec0 (patch)
tree70b4e6167e38902fce2ffebbf343df6ac8a6fe06
parentscore: Add semaphore variants (diff)
downloadrtems-09c5ca4cb4f30ba9e0c3c3915a70af7ff3916ec0.tar.bz2
score: Simplify CORE mutex
Remove superfluous support for simple binary semaphores. With this we can get rid of the CORE_MUTEX_NESTING_BLOCKS variant.
Diffstat (limited to '')
-rw-r--r--cpukit/rtems/include/rtems/rtems/semimpl.h1
-rw-r--r--cpukit/rtems/src/semcreate.c43
-rw-r--r--cpukit/rtems/src/semdelete.c19
-rw-r--r--cpukit/rtems/src/semflush.c5
-rw-r--r--cpukit/rtems/src/semobtain.c5
-rw-r--r--cpukit/rtems/src/semrelease.c13
-rw-r--r--cpukit/score/include/rtems/score/coremutex.h7
-rw-r--r--cpukit/score/include/rtems/score/coremuteximpl.h2
-rw-r--r--cpukit/score/src/coremutexsurrender.c3
-rw-r--r--testsuites/sptests/spintrcritical22/init.c7
10 files changed, 57 insertions, 48 deletions
diff --git a/cpukit/rtems/include/rtems/rtems/semimpl.h b/cpukit/rtems/include/rtems/rtems/semimpl.h
index 813f885d5f..f3dfa0213a 100644
--- a/cpukit/rtems/include/rtems/rtems/semimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/semimpl.h
@@ -28,6 +28,7 @@ extern "C" {
typedef enum {
SEMAPHORE_VARIANT_MUTEX,
+ SEMAPHORE_VARIANT_SIMPLE_BINARY,
SEMAPHORE_VARIANT_COUNTING
#if defined(RTEMS_SMP)
,
diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c
index be8f9f5d3b..455182bd90 100644
--- a/cpukit/rtems/src/semcreate.c
+++ b/cpukit/rtems/src/semcreate.c
@@ -143,9 +143,6 @@ rtems_status_code rtems_semaphore_create(
the_semaphore->discipline = SEMAPHORE_DISCIPLINE_FIFO;
}
- /*
- * Initialize it as a counting semaphore.
- */
if ( _Attributes_Is_counting_semaphore( attribute_set ) ) {
the_semaphore->variant = SEMAPHORE_VARIANT_COUNTING;
_CORE_semaphore_Initialize(
@@ -153,6 +150,13 @@ rtems_status_code rtems_semaphore_create(
count
);
status = STATUS_SUCCESSFUL;
+ } else if ( _Attributes_Is_simple_binary_semaphore( attribute_set ) ) {
+ the_semaphore->variant = SEMAPHORE_VARIANT_SIMPLE_BINARY;
+ _CORE_semaphore_Initialize(
+ &the_semaphore->Core_control.semaphore,
+ count != 0
+ );
+ status = STATUS_SUCCESSFUL;
#if defined(RTEMS_SMP)
} else if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
the_semaphore->variant = SEMAPHORE_VARIANT_MRSP;
@@ -166,6 +170,8 @@ rtems_status_code rtems_semaphore_create(
} else {
the_semaphore->variant = SEMAPHORE_VARIANT_MUTEX;
+ _Assert( _Attributes_Is_binary_semaphore( attribute_set ) );
+
/*
* It is either simple binary semaphore or a more powerful mutex
* style binary semaphore. This is the mutex style.
@@ -175,25 +181,20 @@ rtems_status_code rtems_semaphore_create(
else
the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_FIFO;
- if ( _Attributes_Is_binary_semaphore( attribute_set ) ) {
- 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;
- }
+ 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;
}
- } else /* must be simple binary semaphore */ {
- the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_BLOCKS;
- the_mutex_attr.only_owner_release = false;
}
status = _CORE_mutex_Initialize(
diff --git a/cpukit/rtems/src/semdelete.c b/cpukit/rtems/src/semdelete.c
index 45c356f452..908c178593 100644
--- a/cpukit/rtems/src/semdelete.c
+++ b/cpukit/rtems/src/semdelete.c
@@ -19,7 +19,6 @@
#endif
#include <rtems/rtems/semimpl.h>
-#include <rtems/rtems/attrimpl.h>
#include <rtems/rtems/statusimpl.h>
rtems_status_code rtems_semaphore_delete(
@@ -28,7 +27,6 @@ rtems_status_code rtems_semaphore_delete(
{
Semaphore_Control *the_semaphore;
Thread_queue_Context queue_context;
- rtems_attribute attribute_set;
Status_Control status;
_Objects_Allocator_lock();
@@ -46,8 +44,6 @@ rtems_status_code rtems_semaphore_delete(
return RTEMS_INVALID_ID;
}
- attribute_set = the_semaphore->attribute_set;
-
_Thread_queue_Acquire_critical(
&the_semaphore->Core_control.Wait_queue,
&queue_context.Lock_context
@@ -55,10 +51,7 @@ rtems_status_code rtems_semaphore_delete(
switch ( the_semaphore->variant ) {
case SEMAPHORE_VARIANT_MUTEX:
- if (
- _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex )
- && !_Attributes_Is_simple_binary_semaphore( attribute_set )
- ) {
+ if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) ) {
status = STATUS_RESOURCE_IN_USE;
} else {
status = STATUS_SUCCESSFUL;
@@ -71,7 +64,10 @@ rtems_status_code rtems_semaphore_delete(
break;
#endif
default:
- _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
+ _Assert(
+ the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
+ || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
+ );
status = STATUS_SUCCESSFUL;
break;
}
@@ -102,7 +98,10 @@ rtems_status_code rtems_semaphore_delete(
break;
#endif
default:
- _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
+ _Assert(
+ the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
+ || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
+ );
_CORE_semaphore_Destroy(
&the_semaphore->Core_control.semaphore,
_Semaphore_Get_operations( the_semaphore ),
diff --git a/cpukit/rtems/src/semflush.c b/cpukit/rtems/src/semflush.c
index f768bbd4a7..2410ed2386 100644
--- a/cpukit/rtems/src/semflush.c
+++ b/cpukit/rtems/src/semflush.c
@@ -63,7 +63,10 @@ rtems_status_code rtems_semaphore_flush( rtems_id id )
);
break;
default:
- _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
+ _Assert(
+ the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
+ || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
+ );
_CORE_semaphore_Flush(
&the_semaphore->Core_control.semaphore,
_Semaphore_Get_operations( the_semaphore ),
diff --git a/cpukit/rtems/src/semobtain.c b/cpukit/rtems/src/semobtain.c
index 93591b87c6..5eebfa14b2 100644
--- a/cpukit/rtems/src/semobtain.c
+++ b/cpukit/rtems/src/semobtain.c
@@ -91,7 +91,10 @@ rtems_status_code rtems_semaphore_obtain(
);
break;
default:
- _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
+ _Assert(
+ the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
+ || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
+ );
status = _CORE_semaphore_Seize(
&the_semaphore->Core_control.semaphore,
_Semaphore_Get_operations( the_semaphore ),
diff --git a/cpukit/rtems/src/semrelease.c b/cpukit/rtems/src/semrelease.c
index d18901a40c..3e13334e87 100644
--- a/cpukit/rtems/src/semrelease.c
+++ b/cpukit/rtems/src/semrelease.c
@@ -61,6 +61,19 @@ rtems_status_code rtems_semaphore_release( rtems_id id )
&queue_context
);
break;
+ case SEMAPHORE_VARIANT_SIMPLE_BINARY:
+ status = _CORE_semaphore_Surrender(
+ &the_semaphore->Core_control.semaphore,
+ _Semaphore_Get_operations( the_semaphore ),
+ 1,
+ &queue_context
+ );
+ _Assert(
+ status == STATUS_SUCCESSFUL
+ || status == STATUS_MAXIMUM_COUNT_EXCEEDED
+ );
+ status = STATUS_SUCCESSFUL;
+ break;
default:
_Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
status = _CORE_semaphore_Surrender(
diff --git a/cpukit/score/include/rtems/score/coremutex.h b/cpukit/score/include/rtems/score/coremutex.h
index 41f1c4f22d..f8694095ac 100644
--- a/cpukit/score/include/rtems/score/coremutex.h
+++ b/cpukit/score/include/rtems/score/coremutex.h
@@ -87,13 +87,6 @@ typedef enum {
*/
CORE_MUTEX_NESTING_IS_ERROR,
#endif
- /**
- * This sequence performs as indicated:
- * + lock(m)
- * + lock(m) - deadlocks or timeouts
- * + unlock(m) - releases
- */
- CORE_MUTEX_NESTING_BLOCKS
} CORE_mutex_Nesting_behaviors;
/**
diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h
index e29d4b7f5d..ccc414827d 100644
--- a/cpukit/score/include/rtems/score/coremuteximpl.h
+++ b/cpukit/score/include/rtems/score/coremuteximpl.h
@@ -238,8 +238,6 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_mutex_Seize_interrupt_trylock(
_CORE_mutex_Release( the_mutex, queue_context );
return STATUS_NESTING_NOT_ALLOWED;
#endif
- case CORE_MUTEX_NESTING_BLOCKS:
- break;
}
}
diff --git a/cpukit/score/src/coremutexsurrender.c b/cpukit/score/src/coremutexsurrender.c
index 1da98276bf..6047409085 100644
--- a/cpukit/score/src/coremutexsurrender.c
+++ b/cpukit/score/src/coremutexsurrender.c
@@ -76,9 +76,6 @@ Status_Control _CORE_mutex_Surrender(
_CORE_mutex_Release( the_mutex, queue_context );
return STATUS_NESTING_NOT_ALLOWED;
#endif
- case CORE_MUTEX_NESTING_BLOCKS:
- /* Currently no API exercises this behavior. */
- break;
}
#else
_CORE_mutex_Release( the_mutex, queue_context );
diff --git a/testsuites/sptests/spintrcritical22/init.c b/testsuites/sptests/spintrcritical22/init.c
index 9b5c5e13be..6c8198b293 100644
--- a/testsuites/sptests/spintrcritical22/init.c
+++ b/testsuites/sptests/spintrcritical22/init.c
@@ -48,12 +48,13 @@ static void release_semaphore(rtems_id timer, void *arg)
/* The arg is NULL */
test_context *ctx = &ctx_instance;
rtems_status_code sc;
- CORE_mutex_Control *mtx = &ctx->semaphore_control->Core_control.mutex;
if (
_Thread_Wait_flags_get(ctx->main_task_control)
== (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK)
) {
+ CORE_semaphore_Control *sem;
+
ctx->done = true;
sc = rtems_semaphore_release(ctx->semaphore_id);
@@ -63,8 +64,8 @@ static void release_semaphore(rtems_id timer, void *arg)
_Thread_Wait_flags_get(ctx->main_task_control)
== (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_READY_AGAIN)
);
- rtems_test_assert(mtx->nest_count == 1);
- rtems_test_assert(mtx->holder == ctx->main_task_control);
+ sem = &ctx->semaphore_control->Core_control.semaphore;
+ rtems_test_assert(sem->count == 0);
} else {
sc = rtems_semaphore_release(ctx->semaphore_id);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);