mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-21 05:21:50 +08:00
posix: Fix mutex auto initialization
Use the once lock to prevent race conditions during auto initialization.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#endif
|
||||
|
||||
#include <rtems/posix/muteximpl.h>
|
||||
#include <rtems/score/apimutex.h>
|
||||
|
||||
static bool _POSIX_Mutex_Check_id_and_auto_init(
|
||||
pthread_mutex_t *mutex,
|
||||
@@ -34,7 +35,15 @@ static bool _POSIX_Mutex_Check_id_and_auto_init(
|
||||
if ( *mutex == PTHREAD_MUTEX_INITIALIZER ) {
|
||||
int eno;
|
||||
|
||||
eno = pthread_mutex_init( mutex, NULL );
|
||||
_Once_Lock();
|
||||
|
||||
if ( *mutex == PTHREAD_MUTEX_INITIALIZER ) {
|
||||
eno = pthread_mutex_init( mutex, NULL );
|
||||
} else {
|
||||
eno = 0;
|
||||
}
|
||||
|
||||
_Once_Unlock();
|
||||
|
||||
if ( eno != 0 ) {
|
||||
*location = OBJECTS_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user