summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/apimutexunlock.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-03-27 13:38:04 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-03-31 08:29:43 +0200
commit346845730cb7cdd3f2a1e9231cced7cdfd046ce1 (patch)
tree3764fe70bfaea1d230d5052982b3bff6b1322e13 /cpukit/score/src/apimutexunlock.c
parentscore: Relax Giant lock usage for API mutexes (diff)
downloadrtems-346845730cb7cdd3f2a1e9231cced7cdfd046ce1.tar.bz2
score: Use thread life protection for API mutexes
This prevents that asynchronous thread deletion can lead to an unusable allocator or once mutex.
Diffstat (limited to 'cpukit/score/src/apimutexunlock.c')
-rw-r--r--cpukit/score/src/apimutexunlock.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/cpukit/score/src/apimutexunlock.c b/cpukit/score/src/apimutexunlock.c
index 43bdfe8bbe..d0432a6f4a 100644
--- a/cpukit/score/src/apimutexunlock.c
+++ b/cpukit/score/src/apimutexunlock.c
@@ -19,19 +19,25 @@
#include "config.h"
#endif
-#include <rtems/system.h>
#include <rtems/score/apimutex.h>
#include <rtems/score/coremuteximpl.h>
-void _API_Mutex_Unlock(
- API_Mutex_Control *the_mutex
-)
+void _API_Mutex_Unlock( API_Mutex_Control *the_mutex )
{
- _Thread_Disable_dispatch();
- _CORE_mutex_Surrender(
- &the_mutex->Mutex,
- the_mutex->Object.id,
- NULL
- );
+ bool previous_thread_life_protection;
+ bool restore_thread_life_protection;
+
+ _Thread_Disable_dispatch();
+
+ previous_thread_life_protection =
+ the_mutex->previous_thread_life_protection;
+ restore_thread_life_protection = the_mutex->Mutex.nest_count == 1;
+
+ _CORE_mutex_Surrender( &the_mutex->Mutex, the_mutex->Object.id, NULL );
+
_Thread_Enable_dispatch();
+
+ if ( restore_thread_life_protection ) {
+ _Thread_Set_life_protection( previous_thread_life_protection );
+ }
}