summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-04-19 06:28:03 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-04-21 07:29:39 +0200
commit48b04fc388a60fc6621233ddbb7cd65d89bb63d8 (patch)
treeebbb0661161ebe5b809fcde7627e1887811d1fc7 /cpukit/posix/src
parentscore: Add and use _CORE_mutex_Acquire_critical() (diff)
downloadrtems-48b04fc388a60fc6621233ddbb7cd65d89bb63d8.tar.bz2
posix: Avoid Giant lock for mutexes
Delete _POSIX_Mutex_Get(). Use _POSIX_Mutex_Get_interrupt_disable() instead. Update #2555.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r--cpukit/posix/src/mutexdestroy.c56
-rw-r--r--cpukit/posix/src/mutexget.c24
-rw-r--r--cpukit/posix/src/mutexgetprioceiling.c40
-rw-r--r--cpukit/posix/src/mutexinit.c6
-rw-r--r--cpukit/posix/src/mutexsetprioceiling.c1
5 files changed, 41 insertions, 86 deletions
diff --git a/cpukit/posix/src/mutexdestroy.c b/cpukit/posix/src/mutexdestroy.c
index fb5aee63f9..bebb306027 100644
--- a/cpukit/posix/src/mutexdestroy.c
+++ b/cpukit/posix/src/mutexdestroy.c
@@ -18,14 +18,7 @@
#include "config.h"
#endif
-#include <errno.h>
-#include <pthread.h>
-
-#include <rtems/system.h>
-#include <rtems/score/coremuteximpl.h>
-#include <rtems/score/watchdog.h>
#include <rtems/posix/muteximpl.h>
-#include <rtems/posix/priorityimpl.h>
/*
* 11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87
@@ -35,41 +28,36 @@ int pthread_mutex_destroy(
pthread_mutex_t *mutex
)
{
- register POSIX_Mutex_Control *the_mutex;
- Objects_Locations location;
+ POSIX_Mutex_Control *the_mutex;
+ ISR_lock_Context lock_context;
+ int eno;
_Objects_Allocator_lock();
- the_mutex = _POSIX_Mutex_Get( mutex, &location );
- switch ( location ) {
- case OBJECTS_LOCAL:
- /*
- * XXX: There is an error for the mutex being locked
- * or being in use by a condition variable.
- */
+ the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &lock_context );
+
+ if ( the_mutex != NULL ) {
+ _CORE_mutex_Acquire_critical( &the_mutex->Mutex, &lock_context );
- if ( _CORE_mutex_Is_locked( &the_mutex->Mutex ) ) {
- _Objects_Put( &the_mutex->Object );
- _Objects_Allocator_unlock();
- return EBUSY;
- }
+ /*
+ * XXX: There is an error for the mutex being locked
+ * or being in use by a condition variable.
+ */
+ if ( !_CORE_mutex_Is_locked( &the_mutex->Mutex ) ) {
_Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object );
- _CORE_mutex_Flush( &the_mutex->Mutex, EINVAL, NULL, 0 );
- _Objects_Put( &the_mutex->Object );
+ _CORE_mutex_Release( &the_mutex->Mutex, &lock_context );
+ _CORE_mutex_Destroy( &the_mutex->Mutex );
_POSIX_Mutex_Free( the_mutex );
- _Objects_Allocator_unlock();
-
- return 0;
-
-#if defined(RTEMS_MULTIPROCESSING)
- case OBJECTS_REMOTE:
-#endif
- case OBJECTS_ERROR:
- break;
+ eno = 0;
+ } else {
+ _CORE_mutex_Release( &the_mutex->Mutex, &lock_context );
+ eno = EBUSY;
+ }
+ } else {
+ eno = EINVAL;
}
_Objects_Allocator_unlock();
-
- return EINVAL;
+ return eno;
}
diff --git a/cpukit/posix/src/mutexget.c b/cpukit/posix/src/mutexget.c
index 9ad226a4f9..9d34ecb583 100644
--- a/cpukit/posix/src/mutexget.c
+++ b/cpukit/posix/src/mutexget.c
@@ -21,14 +21,9 @@
#include <rtems/posix/muteximpl.h>
#include <rtems/score/apimutex.h>
-static bool _POSIX_Mutex_Check_id_and_auto_init(
- pthread_mutex_t *mutex,
- Objects_Locations *location
-)
+static bool _POSIX_Mutex_Check_id_and_auto_init( pthread_mutex_t *mutex )
{
if ( mutex == NULL ) {
- *location = OBJECTS_ERROR;
-
return false;
}
@@ -46,8 +41,6 @@ static bool _POSIX_Mutex_Check_id_and_auto_init(
_Once_Unlock();
if ( eno != 0 ) {
- *location = OBJECTS_ERROR;
-
return false;
}
}
@@ -55,19 +48,6 @@ static bool _POSIX_Mutex_Check_id_and_auto_init(
return true;
}
-POSIX_Mutex_Control *_POSIX_Mutex_Get (
- pthread_mutex_t *mutex,
- Objects_Locations *location
-)
-{
- if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex, location ) ) {
- return NULL;
- }
-
- return (POSIX_Mutex_Control *)
- _Objects_Get( &_POSIX_Mutex_Information, (Objects_Id) *mutex, location );
-}
-
POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable(
pthread_mutex_t *mutex,
ISR_lock_Context *lock_context
@@ -75,7 +55,7 @@ POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable(
{
Objects_Locations location;
- if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex, &location ) ) {
+ if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex ) ) {
return NULL;
}
diff --git a/cpukit/posix/src/mutexgetprioceiling.c b/cpukit/posix/src/mutexgetprioceiling.c
index 129f661576..e66e98366e 100644
--- a/cpukit/posix/src/mutexgetprioceiling.c
+++ b/cpukit/posix/src/mutexgetprioceiling.c
@@ -18,12 +18,6 @@
#include "config.h"
#endif
-#include <errno.h>
-#include <pthread.h>
-
-#include <rtems/system.h>
-#include <rtems/score/coremuteximpl.h>
-#include <rtems/score/watchdog.h>
#include <rtems/posix/muteximpl.h>
#include <rtems/posix/priorityimpl.h>
@@ -36,28 +30,26 @@ int pthread_mutex_getprioceiling(
int *prioceiling
)
{
- register POSIX_Mutex_Control *the_mutex;
- Objects_Locations location;
+ POSIX_Mutex_Control *the_mutex;
+ ISR_lock_Context lock_context;
- if ( !prioceiling )
+ if ( prioceiling == NULL ) {
return EINVAL;
+ }
- the_mutex = _POSIX_Mutex_Get( mutex, &location );
- switch ( location ) {
-
- case OBJECTS_LOCAL:
- *prioceiling = _POSIX_Priority_From_core(
- the_mutex->Mutex.Attributes.priority_ceiling
- );
- _Objects_Put( &the_mutex->Object );
- return 0;
+ the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &lock_context );
-#if defined(RTEMS_MULTIPROCESSING)
- case OBJECTS_REMOTE:
-#endif
- case OBJECTS_ERROR:
- break;
+ if ( the_mutex == NULL ) {
+ return EINVAL;
}
- return EINVAL;
+ _CORE_mutex_Acquire_critical( &the_mutex->Mutex, &lock_context );
+
+ *prioceiling = _POSIX_Priority_From_core(
+ the_mutex->Mutex.Attributes.priority_ceiling
+ );
+
+ _CORE_mutex_Release( &the_mutex->Mutex, &lock_context );
+
+ return 0;
}
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c
index db7f6b8466..18886996fe 100644
--- a/cpukit/posix/src/mutexinit.c
+++ b/cpukit/posix/src/mutexinit.c
@@ -18,12 +18,6 @@
#include "config.h"
#endif
-#include <errno.h>
-#include <pthread.h>
-
-#include <rtems/system.h>
-#include <rtems/score/coremuteximpl.h>
-#include <rtems/score/watchdog.h>
#include <rtems/posix/muteximpl.h>
#include <rtems/posix/priorityimpl.h>
diff --git a/cpukit/posix/src/mutexsetprioceiling.c b/cpukit/posix/src/mutexsetprioceiling.c
index 1f9f5164bb..5d50f14857 100644
--- a/cpukit/posix/src/mutexsetprioceiling.c
+++ b/cpukit/posix/src/mutexsetprioceiling.c
@@ -19,6 +19,7 @@
#endif
#include <rtems/posix/muteximpl.h>
+#include <rtems/posix/priorityimpl.h>
/*
* 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131