From 4f308829ad0e81a59971e172284c018cf2bdca3d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 22 Mar 2019 20:48:40 +0100 Subject: Add mutex for lhs expr, add error for missing lhs expr for func, struct TODO: Use mutex in lhs expr and set resolved_type --- src/std/thread.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/std/thread.c') 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; -- cgit v1.2.3