summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-03 08:15:21 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-06 12:57:07 +0200
commit3ad5f86cf6803204b98760cdce0c56ef6d79bccd (patch)
treeae018224b2cdda837bd174ad94397a5e043dc2ea /cpukit
parenttftp: Use proper semaphore attr for mutex (diff)
downloadrtems-3ad5f86cf6803204b98760cdce0c56ef6d79bccd.tar.bz2
rtems: Fix no protocol mutex release
The Classic binary semaphores without a locking protocol (RTEMS_BINARY_SEMAPHORE) could be released by everyone, e.g. in contrast to the POSIX mutexes (all variants) or the Classic binary semphores with priority inheritance or ceiling, there was no owner check in the release path. This behaviour was a bit unexpected and not documented. Add an owner check to the release path. Update sptests/sp42 accordingly. This change has nothing to do with the simple binary semaphores (RTEMS_SIMPLE_BINARY_SEMAPHORE) which have no owner at all. Update #2725
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/rtems/src/semrelease.c3
-rw-r--r--cpukit/score/include/rtems/score/coremuteximpl.h54
2 files changed, 13 insertions, 44 deletions
diff --git a/cpukit/rtems/src/semrelease.c b/cpukit/rtems/src/semrelease.c
index ccd4e63d64..39c467da62 100644
--- a/cpukit/rtems/src/semrelease.c
+++ b/cpukit/rtems/src/semrelease.c
@@ -64,9 +64,10 @@ rtems_status_code rtems_semaphore_release( rtems_id id )
);
break;
case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
- _CORE_recursive_mutex_Surrender_no_protocol_classic(
+ _CORE_recursive_mutex_Surrender_no_protocol(
&the_semaphore->Core_control.Mutex.Recursive,
_Semaphore_Get_operations( the_semaphore ),
+ executing,
&queue_context
);
status = STATUS_SUCCESSFUL;
diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h
index decf770eed..956dfa81ee 100644
--- a/cpukit/score/include/rtems/score/coremuteximpl.h
+++ b/cpukit/score/include/rtems/score/coremuteximpl.h
@@ -311,22 +311,29 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize_no_protocol(
);
}
-RTEMS_INLINE_ROUTINE void
-_CORE_recursive_mutex_Surrender_no_protocol_finalize(
+RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Surrender_no_protocol(
CORE_recursive_mutex_Control *the_mutex,
const Thread_queue_Operations *operations,
+ Thread_Control *executing,
Thread_queue_Context *queue_context
)
{
unsigned int nest_level;
Thread_Control *new_owner;
+ _CORE_mutex_Acquire_critical( &the_mutex->Mutex, queue_context );
+
+ if ( !_CORE_mutex_Is_owner( &the_mutex->Mutex, executing ) ) {
+ _CORE_mutex_Release( &the_mutex->Mutex, queue_context );
+ return STATUS_NOT_OWNER;
+ }
+
nest_level = the_mutex->nest_level;
if ( nest_level > 0 ) {
the_mutex->nest_level = nest_level - 1;
_CORE_mutex_Release( &the_mutex->Mutex, queue_context );
- return;
+ return STATUS_SUCCESSFUL;
}
new_owner = _Thread_queue_First_locked(
@@ -337,7 +344,7 @@ _CORE_recursive_mutex_Surrender_no_protocol_finalize(
if ( new_owner == NULL ) {
_CORE_mutex_Release( &the_mutex->Mutex, queue_context );
- return;
+ return STATUS_SUCCESSFUL;
}
_Thread_queue_Extract_critical(
@@ -346,48 +353,9 @@ _CORE_recursive_mutex_Surrender_no_protocol_finalize(
new_owner,
queue_context
);
-}
-
-RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Surrender_no_protocol(
- CORE_recursive_mutex_Control *the_mutex,
- const Thread_queue_Operations *operations,
- Thread_Control *executing,
- Thread_queue_Context *queue_context
-)
-{
- _CORE_mutex_Acquire_critical( &the_mutex->Mutex, queue_context );
-
- if ( !_CORE_mutex_Is_owner( &the_mutex->Mutex, executing ) ) {
- _CORE_mutex_Release( &the_mutex->Mutex, queue_context );
- return STATUS_NOT_OWNER;
- }
-
- _CORE_recursive_mutex_Surrender_no_protocol_finalize(
- the_mutex,
- operations,
- queue_context
- );
return STATUS_SUCCESSFUL;
}
-/*
- * The Classic no protocol recursive mutex has the nice property that everyone
- * can release it.
- */
-RTEMS_INLINE_ROUTINE void _CORE_recursive_mutex_Surrender_no_protocol_classic(
- CORE_recursive_mutex_Control *the_mutex,
- const Thread_queue_Operations *operations,
- Thread_queue_Context *queue_context
-)
-{
- _CORE_mutex_Acquire_critical( &the_mutex->Mutex, queue_context );
- _CORE_recursive_mutex_Surrender_no_protocol_finalize(
- the_mutex,
- operations,
- queue_context
- );
-}
-
RTEMS_INLINE_ROUTINE void _CORE_ceiling_mutex_Initialize(
CORE_ceiling_mutex_Control *the_mutex,
Priority_Control priority_ceiling