From: Martin Quinson Date: Sun, 16 Oct 2022 14:53:27 +0000 (+0200) Subject: Deal with PTHREAD_STATIC_INITIALIZER if it behave as in glibc X-Git-Tag: v3.34~772 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1fbb36afadc7cb35c5f80bc3ee3bb817aeab303e Deal with PTHREAD_STATIC_INITIALIZER if it behave as in glibc --- diff --git a/src/sthread/sthread_impl.cpp b/src/sthread/sthread_impl.cpp index 4ef0265325..efcdcdda83 100644 --- a/src/sthread/sthread_impl.cpp +++ b/src/sthread/sthread_impl.cpp @@ -109,22 +109,38 @@ int sthread_mutex_init(sthread_mutex_t* mutex, const void* /*pthread_mutexattr_t int sthread_mutex_lock(sthread_mutex_t* mutex) { + /* At least in glibc, PTHREAD_STATIC_INITIALIZER sets every fields to 0 */ + if (mutex->mutex == nullptr) + sthread_mutex_init(mutex, nullptr); + static_cast(mutex->mutex)->lock(); return 0; } int sthread_mutex_trylock(sthread_mutex_t* mutex) { + /* At least in glibc, PTHREAD_STATIC_INITIALIZER sets every fields to 0 */ + if (mutex->mutex == nullptr) + sthread_mutex_init(mutex, nullptr); + return static_cast(mutex->mutex)->try_lock(); } int sthread_mutex_unlock(sthread_mutex_t* mutex) { + /* At least in glibc, PTHREAD_STATIC_INITIALIZER sets every fields to 0 */ + if (mutex->mutex == nullptr) + sthread_mutex_init(mutex, nullptr); + static_cast(mutex->mutex)->unlock(); return 0; } int sthread_mutex_destroy(sthread_mutex_t* mutex) { + /* At least in glibc, PTHREAD_STATIC_INITIALIZER sets every fields to 0 */ + if (mutex->mutex == nullptr) + sthread_mutex_init(mutex, nullptr); + intrusive_ptr_release(static_cast(mutex->mutex)); return 0; }