summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-20 21:39:56 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-30 16:16:21 +0200
commit2581a563f9182dc2debdba97f33feee6d797e53a (patch)
tree97883371771f9a2905d159d8e11c0b2e9da0408c
parent3ca6e6185131ab804b2831ab308b44b4b174856a (diff)
score: Add semaphore variants
-rw-r--r--cpukit/posix/include/rtems/posix/semaphoreimpl.h2
-rw-r--r--cpukit/posix/src/semaphorecreatesupp.c6
-rw-r--r--cpukit/posix/src/semaphoredeletesupp.c6
-rw-r--r--cpukit/posix/src/semaphorewaitsupp.c1
-rw-r--r--cpukit/posix/src/sempost.c1
-rw-r--r--cpukit/rtems/include/rtems/rtems/sem.h18
-rw-r--r--cpukit/rtems/include/rtems/rtems/semimpl.h25
-rw-r--r--cpukit/rtems/src/semcreate.c31
-rw-r--r--cpukit/rtems/src/semdelete.c68
-rw-r--r--cpukit/rtems/src/semflush.c54
-rw-r--r--cpukit/rtems/src/semobtain.c60
-rw-r--r--cpukit/rtems/src/semrelease.c44
-rw-r--r--cpukit/score/include/rtems/score/coresem.h17
-rw-r--r--cpukit/score/include/rtems/score/coresemimpl.h54
-rw-r--r--cpukit/score/src/coresem.c11
-rw-r--r--cpukit/score/src/mpci.c11
16 files changed, 227 insertions, 182 deletions
diff --git a/cpukit/posix/include/rtems/posix/semaphoreimpl.h b/cpukit/posix/include/rtems/posix/semaphoreimpl.h
index 1521eade85..17d3f64e92 100644
--- a/cpukit/posix/include/rtems/posix/semaphoreimpl.h
+++ b/cpukit/posix/include/rtems/posix/semaphoreimpl.h
@@ -34,6 +34,8 @@ extern "C" {
*/
extern Objects_Information _POSIX_Semaphore_Information;
+#define POSIX_SEMAPHORE_TQ_OPERATIONS &_Thread_queue_Operations_FIFO
+
RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *
_POSIX_Semaphore_Allocate_unprotected( void )
{
diff --git a/cpukit/posix/src/semaphorecreatesupp.c b/cpukit/posix/src/semaphorecreatesupp.c
index 79db8888d8..d66e1942c9 100644
--- a/cpukit/posix/src/semaphorecreatesupp.c
+++ b/cpukit/posix/src/semaphorecreatesupp.c
@@ -92,11 +92,7 @@ int _POSIX_Semaphore_Create_support(
* thing is certain, no matter what we decide, it won't be
* the same as all other POSIX implementations. :)
*/
- _CORE_semaphore_Initialize(
- &the_semaphore->Semaphore,
- CORE_SEMAPHORE_DISCIPLINES_FIFO,
- value
- );
+ _CORE_semaphore_Initialize( &the_semaphore->Semaphore, value );
/*
* Make the semaphore available for use.
diff --git a/cpukit/posix/src/semaphoredeletesupp.c b/cpukit/posix/src/semaphoredeletesupp.c
index 2d39b2aad5..325e4a6c1b 100644
--- a/cpukit/posix/src/semaphoredeletesupp.c
+++ b/cpukit/posix/src/semaphoredeletesupp.c
@@ -27,7 +27,11 @@ void _POSIX_Semaphore_Delete(
{
if ( !the_semaphore->linked && !the_semaphore->open_count ) {
_Objects_Close( &_POSIX_Semaphore_Information, &the_semaphore->Object );
- _CORE_semaphore_Destroy( &the_semaphore->Semaphore, queue_context );
+ _CORE_semaphore_Destroy(
+ &the_semaphore->Semaphore,
+ POSIX_SEMAPHORE_TQ_OPERATIONS,
+ queue_context
+ );
_POSIX_Semaphore_Free( the_semaphore );
} else {
_CORE_semaphore_Release( &the_semaphore->Semaphore, queue_context );
diff --git a/cpukit/posix/src/semaphorewaitsupp.c b/cpukit/posix/src/semaphorewaitsupp.c
index d8e0d69654..9ba8d55894 100644
--- a/cpukit/posix/src/semaphorewaitsupp.c
+++ b/cpukit/posix/src/semaphorewaitsupp.c
@@ -43,6 +43,7 @@ int _POSIX_Semaphore_Wait_support(
status = _CORE_semaphore_Seize(
&the_semaphore->Semaphore,
+ POSIX_SEMAPHORE_TQ_OPERATIONS,
_Thread_Executing,
blocking,
timeout,
diff --git a/cpukit/posix/src/sempost.c b/cpukit/posix/src/sempost.c
index 322663b5ad..da2b1a5495 100644
--- a/cpukit/posix/src/sempost.c
+++ b/cpukit/posix/src/sempost.c
@@ -40,6 +40,7 @@ int sem_post(
status = _CORE_semaphore_Surrender(
&the_semaphore->Semaphore,
+ POSIX_SEMAPHORE_TQ_OPERATIONS,
SEM_VALUE_MAX,
&queue_context
);
diff --git a/cpukit/rtems/include/rtems/rtems/sem.h b/cpukit/rtems/include/rtems/rtems/sem.h
index 2c99f57deb..fe74f44dfa 100644
--- a/cpukit/rtems/include/rtems/rtems/sem.h
+++ b/cpukit/rtems/include/rtems/rtems/sem.h
@@ -97,6 +97,24 @@ typedef struct {
} Core_control;
/**
+ * @brief The semaphore variant.
+ *
+ * @see Semaphore_Variant.
+ */
+ unsigned int variant : 3;
+
+ /**
+ * @brief The semaphore thread queue discipline.
+ *
+ * @see Semaphore_Discipline.
+ */
+ unsigned int discipline : 1;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ unsigned int is_global : 1;
+#endif
+
+ /**
* This is the Classic API attribute provided to the create directive.
* It is translated into behavioral attributes on the SuperCore Semaphore
* or Mutex instance.
diff --git a/cpukit/rtems/include/rtems/rtems/semimpl.h b/cpukit/rtems/include/rtems/rtems/semimpl.h
index a498927691..813f885d5f 100644
--- a/cpukit/rtems/include/rtems/rtems/semimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/semimpl.h
@@ -26,12 +26,37 @@
extern "C" {
#endif
+typedef enum {
+ SEMAPHORE_VARIANT_MUTEX,
+ SEMAPHORE_VARIANT_COUNTING
+#if defined(RTEMS_SMP)
+ ,
+ SEMAPHORE_VARIANT_MRSP
+#endif
+} Semaphore_Variant;
+
+typedef enum {
+ SEMAPHORE_DISCIPLINE_PRIORITY,
+ SEMAPHORE_DISCIPLINE_FIFO
+} Semaphore_Discipline;
+
/**
* The following defines the information control block used to manage
* this class of objects.
*/
extern Objects_Information _Semaphore_Information;
+RTEMS_INLINE_ROUTINE const Thread_queue_Operations *_Semaphore_Get_operations(
+ const Semaphore_Control *the_semaphore
+)
+{
+ if ( the_semaphore->discipline == SEMAPHORE_DISCIPLINE_PRIORITY ) {
+ return &_Thread_queue_Operations_priority;
+ } else {
+ return &_Thread_queue_Operations_FIFO;
+ }
+}
+
/**
* @brief Allocates a semaphore control block from
* the inactive chain of free semaphore control blocks.
diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c
index 83d46b607e..be8f9f5d3b 100644
--- a/cpukit/rtems/src/semcreate.c
+++ b/cpukit/rtems/src/semcreate.c
@@ -61,10 +61,9 @@ rtems_status_code rtems_semaphore_create(
rtems_id *id
)
{
- Semaphore_Control *the_semaphore;
- CORE_mutex_Attributes the_mutex_attr;
- CORE_semaphore_Disciplines semaphore_discipline;
- Status_Control status;
+ Semaphore_Control *the_semaphore;
+ CORE_mutex_Attributes the_mutex_attr;
+ Status_Control status;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -125,6 +124,8 @@ rtems_status_code rtems_semaphore_create(
}
#if defined(RTEMS_MULTIPROCESSING)
+ the_semaphore->is_global = _Attributes_Is_global( attribute_set );
+
if ( _Attributes_Is_global( attribute_set ) &&
! ( _Objects_MP_Allocate_and_open( &_Semaphore_Information, name,
the_semaphore->Object.id, false ) ) ) {
@@ -136,29 +137,25 @@ rtems_status_code rtems_semaphore_create(
the_semaphore->attribute_set = attribute_set;
+ if ( _Attributes_Is_priority( attribute_set ) ) {
+ the_semaphore->discipline = SEMAPHORE_DISCIPLINE_PRIORITY;
+ } else {
+ the_semaphore->discipline = SEMAPHORE_DISCIPLINE_FIFO;
+ }
+
/*
* Initialize it as a counting semaphore.
*/
if ( _Attributes_Is_counting_semaphore( attribute_set ) ) {
- if ( _Attributes_Is_priority( attribute_set ) )
- semaphore_discipline = CORE_SEMAPHORE_DISCIPLINES_PRIORITY;
- else
- semaphore_discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
-
- /*
- * The following are just to make Purify happy.
- */
- the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES;
- the_mutex_attr.priority_ceiling = PRIORITY_MINIMUM;
-
+ the_semaphore->variant = SEMAPHORE_VARIANT_COUNTING;
_CORE_semaphore_Initialize(
&the_semaphore->Core_control.semaphore,
- semaphore_discipline,
count
);
status = STATUS_SUCCESSFUL;
#if defined(RTEMS_SMP)
} else if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
+ the_semaphore->variant = SEMAPHORE_VARIANT_MRSP;
status = _MRSP_Initialize(
&the_semaphore->Core_control.mrsp,
priority_ceiling,
@@ -167,6 +164,8 @@ rtems_status_code rtems_semaphore_create(
);
#endif
} else {
+ 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.
diff --git a/cpukit/rtems/src/semdelete.c b/cpukit/rtems/src/semdelete.c
index 16889cd6b6..45c356f452 100644
--- a/cpukit/rtems/src/semdelete.c
+++ b/cpukit/rtems/src/semdelete.c
@@ -53,22 +53,27 @@ rtems_status_code rtems_semaphore_delete(
&queue_context.Lock_context
);
+ 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 )
+ ) {
+ status = STATUS_RESOURCE_IN_USE;
+ } else {
+ status = STATUS_SUCCESSFUL;
+ }
+
+ break;
#if defined(RTEMS_SMP)
- if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
- status = _MRSP_Can_destroy( &the_semaphore->Core_control.mrsp );
- } else
+ case SEMAPHORE_VARIANT_MRSP:
+ status = _MRSP_Can_destroy( &the_semaphore->Core_control.mrsp );
+ break;
#endif
- if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
- if (
- _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex )
- && !_Attributes_Is_simple_binary_semaphore( attribute_set )
- ) {
- status = STATUS_RESOURCE_IN_USE;
- } else {
+ default:
+ _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
status = STATUS_SUCCESSFUL;
- }
- } else {
- status = STATUS_SUCCESSFUL;
+ break;
}
if ( status != STATUS_SUCCESSFUL ) {
@@ -82,27 +87,32 @@ rtems_status_code rtems_semaphore_delete(
_Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
+ switch ( the_semaphore->variant ) {
+ case SEMAPHORE_VARIANT_MUTEX:
+ _CORE_mutex_Flush(
+ &the_semaphore->Core_control.mutex,
+ _Thread_queue_Flush_status_object_was_deleted,
+ &queue_context
+ );
+ _CORE_mutex_Destroy( &the_semaphore->Core_control.mutex );
+ break;
#if defined(RTEMS_SMP)
- if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
- _MRSP_Destroy( &the_semaphore->Core_control.mrsp, &queue_context );
- } else
+ case SEMAPHORE_VARIANT_MRSP:
+ _MRSP_Destroy( &the_semaphore->Core_control.mrsp, &queue_context );
+ break;
#endif
- if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
- _CORE_mutex_Flush(
- &the_semaphore->Core_control.mutex,
- _Thread_queue_Flush_status_object_was_deleted,
- &queue_context
- );
- _CORE_mutex_Destroy( &the_semaphore->Core_control.mutex );
- } else {
- _CORE_semaphore_Destroy(
- &the_semaphore->Core_control.semaphore,
- &queue_context
- );
+ default:
+ _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
+ _CORE_semaphore_Destroy(
+ &the_semaphore->Core_control.semaphore,
+ _Semaphore_Get_operations( the_semaphore ),
+ &queue_context
+ );
+ break;
}
#if defined(RTEMS_MULTIPROCESSING)
- if ( _Attributes_Is_global( attribute_set ) ) {
+ if ( the_semaphore->is_global ) {
_Objects_MP_Close( &_Semaphore_Information, id );
diff --git a/cpukit/rtems/src/semflush.c b/cpukit/rtems/src/semflush.c
index 07d4aa98b4..f768bbd4a7 100644
--- a/cpukit/rtems/src/semflush.c
+++ b/cpukit/rtems/src/semflush.c
@@ -19,13 +19,11 @@
#endif
#include <rtems/rtems/semimpl.h>
-#include <rtems/rtems/attrimpl.h>
rtems_status_code rtems_semaphore_flush( rtems_id id )
{
Semaphore_Control *the_semaphore;
Thread_queue_Context queue_context;
- rtems_attribute attribute_set;
the_semaphore = _Semaphore_Get( id, &queue_context );
@@ -39,38 +37,40 @@ rtems_status_code rtems_semaphore_flush( rtems_id id )
return RTEMS_INVALID_ID;
}
- attribute_set = the_semaphore->attribute_set;
-
+ _Thread_queue_Acquire_critical(
+ &the_semaphore->Core_control.Wait_queue,
+ &queue_context.Lock_context
+ );
_Thread_queue_Context_set_MP_callout(
&queue_context,
_Semaphore_MP_Send_object_was_deleted
);
+ switch ( the_semaphore->variant ) {
#if defined(RTEMS_SMP)
- if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
- _ISR_lock_ISR_enable( &queue_context.Lock_context );
- return RTEMS_NOT_DEFINED;
- } else
+ case SEMAPHORE_VARIANT_MRSP:
+ _Thread_queue_Release(
+ &the_semaphore->Core_control.Wait_queue,
+ &queue_context.Lock_context
+ );
+ return RTEMS_NOT_DEFINED;
#endif
- if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
- _CORE_mutex_Acquire_critical(
- &the_semaphore->Core_control.mutex,
- &queue_context
- );
- _CORE_mutex_Flush(
- &the_semaphore->Core_control.mutex,
- _Thread_queue_Flush_status_unavailable,
- &queue_context
- );
- } else {
- _CORE_semaphore_Acquire_critical(
- &the_semaphore->Core_control.semaphore,
- &queue_context
- );
- _CORE_semaphore_Flush(
- &the_semaphore->Core_control.semaphore,
- &queue_context
- );
+ case SEMAPHORE_VARIANT_MUTEX:
+ _CORE_mutex_Flush(
+ &the_semaphore->Core_control.mutex,
+ _Thread_queue_Flush_status_unavailable,
+ &queue_context
+ );
+ break;
+ default:
+ _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
+ _CORE_semaphore_Flush(
+ &the_semaphore->Core_control.semaphore,
+ _Semaphore_Get_operations( the_semaphore ),
+ &queue_context
+ );
+ break;
}
+
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/semobtain.c b/cpukit/rtems/src/semobtain.c
index 8cb195c5a2..93591b87c6 100644
--- a/cpukit/rtems/src/semobtain.c
+++ b/cpukit/rtems/src/semobtain.c
@@ -19,7 +19,6 @@
#endif
#include <rtems/rtems/semimpl.h>
-#include <rtems/rtems/attrimpl.h>
#include <rtems/rtems/optionsimpl.h>
#include <rtems/rtems/statusimpl.h>
@@ -54,7 +53,6 @@ rtems_status_code rtems_semaphore_obtain(
Semaphore_Control *the_semaphore;
Thread_queue_Context queue_context;
Thread_Control *executing;
- rtems_attribute attribute_set;
bool wait;
Status_Control status;
@@ -69,36 +67,40 @@ rtems_status_code rtems_semaphore_obtain(
}
executing = _Thread_Executing;
- attribute_set = the_semaphore->attribute_set;
wait = !_Options_Is_no_wait( option_set );
+
+ switch ( the_semaphore->variant ) {
#if defined(RTEMS_SMP)
- if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
- status = _MRSP_Seize(
- &the_semaphore->Core_control.mrsp,
- executing,
- wait,
- timeout,
- &queue_context
- );
- } else
+ case SEMAPHORE_VARIANT_MRSP:
+ status = _MRSP_Seize(
+ &the_semaphore->Core_control.mrsp,
+ executing,
+ wait,
+ timeout,
+ &queue_context
+ );
+ break;
#endif
- if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
- status = _CORE_mutex_Seize(
- &the_semaphore->Core_control.mutex,
- executing,
- wait,
- timeout,
- &queue_context
- );
- } else {
- /* must be a counting semaphore */
- status = _CORE_semaphore_Seize(
- &the_semaphore->Core_control.semaphore,
- executing,
- wait,
- timeout,
- &queue_context
- );
+ case SEMAPHORE_VARIANT_MUTEX:
+ status = _CORE_mutex_Seize(
+ &the_semaphore->Core_control.mutex,
+ executing,
+ wait,
+ timeout,
+ &queue_context
+ );
+ break;
+ default:
+ _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
+ status = _CORE_semaphore_Seize(
+ &the_semaphore->Core_control.semaphore,
+ _Semaphore_Get_operations( the_semaphore ),
+ executing,
+ wait,
+ timeout,
+ &queue_context
+ );
+ break;
}
return _Status_Get( status );
diff --git a/cpukit/rtems/src/semrelease.c b/cpukit/rtems/src/semrelease.c
index 10fe743480..d18901a40c 100644
--- a/cpukit/rtems/src/semrelease.c
+++ b/cpukit/rtems/src/semrelease.c
@@ -22,14 +22,12 @@
#endif
#include <rtems/rtems/semimpl.h>
-#include <rtems/rtems/attrimpl.h>
#include <rtems/rtems/statusimpl.h>
rtems_status_code rtems_semaphore_release( rtems_id id )
{
Semaphore_Control *the_semaphore;
Thread_queue_Context queue_context;
- rtems_attribute attribute_set;
Status_Control status;
the_semaphore = _Semaphore_Get( id, &queue_context );
@@ -47,27 +45,31 @@ rtems_status_code rtems_semaphore_release( rtems_id id )
_Semaphore_Core_mutex_mp_support
);
- attribute_set = the_semaphore->attribute_set;
+ switch ( the_semaphore->variant ) {
#if defined(RTEMS_SMP)
- if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
- status = _MRSP_Surrender(
- &the_semaphore->Core_control.mrsp,
- _Thread_Executing,
- &queue_context
- );
- } else
+ case SEMAPHORE_VARIANT_MRSP:
+ status = _MRSP_Surrender(
+ &the_semaphore->Core_control.mrsp,
+ _Thread_Executing,
+ &queue_context
+ );
+ break;
#endif
- if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
- status = _CORE_mutex_Surrender(
- &the_semaphore->Core_control.mutex,
- &queue_context
- );
- } else {
- status = _CORE_semaphore_Surrender(
- &the_semaphore->Core_control.semaphore,
- UINT32_MAX,
- &queue_context
- );
+ case SEMAPHORE_VARIANT_MUTEX:
+ status = _CORE_mutex_Surrender(
+ &the_semaphore->Core_control.mutex,
+ &queue_context
+ );
+ break;
+ default:
+ _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
+ status = _CORE_semaphore_Surrender(
+ &the_semaphore->Core_control.semaphore,
+ _Semaphore_Get_operations( the_semaphore ),
+ UINT32_MAX,
+ &queue_context
+ );
+ break;
}
return _Status_Get( status );
diff --git a/cpukit/score/include/rtems/score/coresem.h b/cpukit/score/include/rtems/score/coresem.h
index 84fde0b892..f9d3ac8fd5 100644
--- a/cpukit/score/include/rtems/score/coresem.h
+++ b/cpukit/score/include/rtems/score/coresem.h
@@ -38,18 +38,6 @@ extern "C" {
/**@{*/
/**
- * Blocking disciplines for a semaphore.
- */
-typedef enum {
- /** This specifies that threads will wait for the semaphore in FIFO order. */
- CORE_SEMAPHORE_DISCIPLINES_FIFO,
- /** This specifies that threads will wait for the semaphore in
- * priority order.
- */
- CORE_SEMAPHORE_DISCIPLINES_PRIORITY
-} CORE_semaphore_Disciplines;
-
-/**
* The following defines the control block used to manage each
* counting semaphore.
*/
@@ -59,11 +47,6 @@ typedef struct {
*/
Thread_queue_Control Wait_queue;
- /**
- * @brief The thread queue operations according to the blocking discipline.
- */
- const Thread_queue_Operations *operations;
-
/** This element contains the current count of this semaphore. */
uint32_t count;
} CORE_semaphore_Control;
diff --git a/cpukit/score/include/rtems/score/coresemimpl.h b/cpukit/score/include/rtems/score/coresemimpl.h
index a55089e399..24d8c5114d 100644
--- a/cpukit/score/include/rtems/score/coresemimpl.h
+++ b/cpukit/score/include/rtems/score/coresemimpl.h
@@ -46,13 +46,11 @@ extern "C" {
* This routine initializes the semaphore based on the parameters passed.
*
* @param[in] the_semaphore is the semaphore to initialize
- * @param[in] discipline the blocking discipline
* @param[in] initial_value is the initial count of the semaphore
*/
void _CORE_semaphore_Initialize(
- CORE_semaphore_Control *the_semaphore,
- CORE_semaphore_Disciplines discipline,
- uint32_t initial_value
+ CORE_semaphore_Control *the_semaphore,
+ uint32_t initial_value
);
RTEMS_INLINE_ROUTINE void _CORE_semaphore_Acquire_critical(
@@ -78,13 +76,14 @@ RTEMS_INLINE_ROUTINE void _CORE_semaphore_Release(
}
RTEMS_INLINE_ROUTINE void _CORE_semaphore_Destroy(
- CORE_semaphore_Control *the_semaphore,
- Thread_queue_Context *queue_context
+ CORE_semaphore_Control *the_semaphore,
+ const Thread_queue_Operations *operations,
+ Thread_queue_Context *queue_context
)
{
_Thread_queue_Flush_critical(
&the_semaphore->Wait_queue.Queue,
- the_semaphore->operations,
+ operations,
_Thread_queue_Flush_status_object_was_deleted,
queue_context
);
@@ -99,15 +98,17 @@ RTEMS_INLINE_ROUTINE void _CORE_semaphore_Destroy(
* given to that task. Otherwise, the unit will be returned to the semaphore.
*
* @param[in] the_semaphore is the semaphore to surrender
+ * @param[in] operations The thread queue operations.
* @param[in] queue_context is a temporary variable used to contain the ISR
* disable level cookie
*
* @retval an indication of whether the routine succeeded or failed
*/
RTEMS_INLINE_ROUTINE Status_Control _CORE_semaphore_Surrender(
- CORE_semaphore_Control *the_semaphore,
- uint32_t maximum_count,
- Thread_queue_Context *queue_context
+ CORE_semaphore_Control *the_semaphore,
+ const Thread_queue_Operations *operations,
+ uint32_t maximum_count,
+ Thread_queue_Context *queue_context
)
{
Thread_Control *the_thread;
@@ -119,12 +120,12 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_semaphore_Surrender(
the_thread = _Thread_queue_First_locked(
&the_semaphore->Wait_queue,
- the_semaphore->operations
+ operations
);
if ( the_thread != NULL ) {
_Thread_queue_Extract_critical(
&the_semaphore->Wait_queue.Queue,
- the_semaphore->operations,
+ operations,
the_thread,
queue_context
);
@@ -141,13 +142,14 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_semaphore_Surrender(
}
RTEMS_INLINE_ROUTINE void _CORE_semaphore_Flush(
- CORE_semaphore_Control *the_semaphore,
- Thread_queue_Context *queue_context
+ CORE_semaphore_Control *the_semaphore,
+ const Thread_queue_Operations *operations,
+ Thread_queue_Context *queue_context
)
{
_Thread_queue_Flush_critical(
&the_semaphore->Wait_queue.Queue,
- the_semaphore->operations,
+ operations,
_Thread_queue_Flush_status_unavailable,
queue_context
);
@@ -161,7 +163,7 @@ RTEMS_INLINE_ROUTINE void _CORE_semaphore_Flush(
* @return the current count of this semaphore
*/
RTEMS_INLINE_ROUTINE uint32_t _CORE_semaphore_Get_count(
- CORE_semaphore_Control *the_semaphore
+ const CORE_semaphore_Control *the_semaphore
)
{
return the_semaphore->count;
@@ -174,23 +176,23 @@ RTEMS_INLINE_ROUTINE uint32_t _CORE_semaphore_Get_count(
* available.
*
* @param[in] the_semaphore is the semaphore to obtain
- * @param[in,out] executing The currently executing thread.
+ * @param[in] operations The thread queue operations.
+ * @param[in] executing The currently executing thread.
* @param[in] wait is true if the thread is willing to wait
* @param[in] timeout is the maximum number of ticks to block
* @param[in] queue_context is a temporary variable used to contain the ISR
* disable level cookie
- *
- * @note There is currently no MACRO version of this routine.
*/
RTEMS_INLINE_ROUTINE Status_Control _CORE_semaphore_Seize(
- CORE_semaphore_Control *the_semaphore,
- Thread_Control *executing,
- bool wait,
- Watchdog_Interval timeout,
- Thread_queue_Context *queue_context
+ CORE_semaphore_Control *the_semaphore,
+ const Thread_queue_Operations *operations,
+ Thread_Control *executing,
+ bool wait,
+ Watchdog_Interval timeout,
+ Thread_queue_Context *queue_context
)
{
- /* disabled when you get here */
+ _Assert( _ISR_Get_level() != 0 );
_CORE_semaphore_Acquire_critical( the_semaphore, queue_context );
if ( the_semaphore->count != 0 ) {
@@ -207,7 +209,7 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_semaphore_Seize(
_Thread_queue_Context_set_expected_level( queue_context, 1 );
_Thread_queue_Enqueue_critical(
&the_semaphore->Wait_queue.Queue,
- the_semaphore->operations,
+ operations,
executing,
STATES_WAITING_FOR_SEMAPHORE,
timeout,
diff --git a/cpukit/score/src/coresem.c b/cpukit/score/src/coresem.c
index 2bdd81c76a..e928f3d3a5 100644
--- a/cpukit/score/src/coresem.c
+++ b/cpukit/score/src/coresem.c
@@ -21,18 +21,11 @@
#include <rtems/score/coresemimpl.h>
void _CORE_semaphore_Initialize(
- CORE_semaphore_Control *the_semaphore,
- CORE_semaphore_Disciplines discipline,
- uint32_t initial_value
+ CORE_semaphore_Control *the_semaphore,
+ uint32_t initial_value
)
{
the_semaphore->count = initial_value;
_Thread_queue_Initialize( &the_semaphore->Wait_queue );
-
- if ( discipline == CORE_SEMAPHORE_DISCIPLINES_PRIORITY ) {
- the_semaphore->operations = &_Thread_queue_Operations_priority;
- } else {
- the_semaphore->operations = &_Thread_queue_Operations_FIFO;
- }
}
diff --git a/cpukit/score/src/mpci.c b/cpukit/score/src/mpci.c
index 8c61e23b0f..9eb169ba17 100644
--- a/cpukit/score/src/mpci.c
+++ b/cpukit/score/src/mpci.c
@@ -35,6 +35,8 @@ RTEMS_STATIC_ASSERT(
MPCI_Internal_packet
);
+#define MPCI_SEMAPHORE_TQ_OPERATIONS &_Thread_queue_Operations_FIFO
+
bool _System_state_Is_multiprocessing;
rtems_multiprocessing_table *_Configuration_MP_table;
@@ -119,7 +121,6 @@ static void _MPCI_Handler_initialization( void )
_CORE_semaphore_Initialize(
&_MPCI_Semaphore,
- CORE_SEMAPHORE_DISCIPLINES_FIFO,
0 /* initial_value */
);
}
@@ -335,6 +336,7 @@ void _MPCI_Receive_server(
_ISR_lock_ISR_disable( &queue_context.Lock_context );
_CORE_semaphore_Seize(
&_MPCI_Semaphore,
+ MPCI_SEMAPHORE_TQ_OPERATIONS,
executing,
true,
WATCHDOG_NO_TIMEOUT,
@@ -373,7 +375,12 @@ void _MPCI_Announce ( void )
Thread_queue_Context queue_context;
_ISR_lock_ISR_disable( &queue_context.Lock_context );
- (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, UINT32_MAX, &queue_context );
+ (void) _CORE_semaphore_Surrender(
+ &_MPCI_Semaphore,
+ MPCI_SEMAPHORE_TQ_OPERATIONS,
+ UINT32_MAX,
+ &queue_context
+ );
}
void _MPCI_Internal_packets_Send_process_packet (