aboutsummaryrefslogtreecommitdiff
path: root/src/std/thread.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-03-22 20:48:40 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit4f308829ad0e81a59971e172284c018cf2bdca3d (patch)
treeeb11a69a471e31aa7be8e46bce6d1b3ded28e056 /src/std/thread.c
parent5df7f92e715ba764ee57f65d78e73111492bb64c (diff)
Add mutex for lhs expr, add error for missing lhs expr for func, struct
TODO: Use mutex in lhs expr and set resolved_type
Diffstat (limited to 'src/std/thread.c')
-rw-r--r--src/std/thread.c6
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;