diff options
Diffstat (limited to 'src/std/thread.c')
-rw-r--r-- | src/std/thread.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/std/thread.c b/src/std/thread.c index ba67463..350631a 100644 --- a/src/std/thread.c +++ b/src/std/thread.c @@ -109,7 +109,9 @@ int amal_thread_join(amal_thread *self, void **result) { void amal_mutex_init(amal_mutex *self) { pthread_mutex_init(&self->mutex, NULL); + #ifdef AMAL_MUTEX_DEBUG self->lock_identifier = NULL; + #endif self->locked = bool_false; self->owner_thread = 0; } @@ -129,10 +131,11 @@ static long amal_thread_get_id() { int amal_mutex_lock(amal_mutex *self, const char *lock_identifier) { int result; result = pthread_mutex_lock(&self->mutex); - self->lock_identifier = lock_identifier; self->owner_thread = pthread_self(); self->locked = bool_true; + (void)lock_identifier; #ifdef AMAL_MUTEX_DEBUG + self->lock_identifier = lock_identifier; if(result == 0 && self->lock_identifier) { amal_log_debug("amal_mutex_lock: mutex locked by thread %lu (%s), identification: %s", amal_thread_get_id(), @@ -149,6 +152,7 @@ int amal_mutex_unlock(amal_mutex *self) { const char *identifier; identifier = self->lock_identifier; #endif + /* No-op if mutex isn't locked or if another thread owns the mutex lock */ if(!self->locked || pthread_equal(self->owner_thread, pthread_self()) == 0) return 0; self->locked = bool_false; |