From 5bf090f874efbb3b1fb0b03d78d52356d75ad6d4 Mon Sep 17 00:00:00 2001 From: SarahW Date: Thu, 16 Jan 2020 20:30:35 +0000 Subject: [PATCH] Added pthread mutex implementation for non-Windows hosts. --- src/wx-thread.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/wx-thread.c b/src/wx-thread.c index b96a3c9..b5958ad 100644 --- a/src/wx-thread.c +++ b/src/wx-thread.c @@ -214,4 +214,43 @@ void thread_sleep(int t) { usleep(t * 1000); } + + +typedef struct pt_mutex_t +{ + pthread_mutex_t mutex; +} pt_mutex_t; + +mutex_t *thread_create_mutex(void) +{ + pt_mutex_t *mutex = malloc(sizeof(pt_mutex_t)); + + pthread_mutex_init(&mutex->mutex, NULL); + + return mutex; + +} + +void thread_lock_mutex(mutex_t *_mutex) +{ + pt_mutex_t *mutex = (pt_mutex_t *)_mutex; + + pthread_mutex_lock(&mutex->mutex); +} + +void thread_unlock_mutex(mutex_t *_mutex) +{ + pt_mutex_t *mutex = (pt_mutex_t *)_mutex; + + pthread_mutex_unlock(&mutex->mutex); +} + +void thread_destroy_mutex(mutex_t *_mutex) +{ + pt_mutex_t *mutex = (pt_mutex_t *)_mutex; + + pthread_mutex_destroy(&mutex->mutex); + + free(mutex); +} #endif