aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-08-19 10:34:31 +0100
committergingerBill <bill@gingerbill.org>2018-08-19 10:34:31 +0100
commit3b6523fbd9b4337bb5ecb8b37f5005e9ce5c444a (patch)
tree69a61ac2bc91fa6d5ce6b1553856442dd8dcfc07
parentffc4f014707783b1d690a1b5a38796324a470e2f (diff)
Fix gbMutex for *nix
-rw-r--r--examples/demo/demo.odin2
-rw-r--r--src/gb/gb.h16
2 files changed, 8 insertions, 10 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin
index 05680de16..f16571d56 100644
--- a/examples/demo/demo.odin
+++ b/examples/demo/demo.odin
@@ -752,7 +752,7 @@ bit_set_type :: proc() {
assert(size_of(x) == size_of(u32));
y: bit_set[0..8; u16];
fmt.println(typeid_of(type_of(x))); // bit_set[A..Z]
- fmt.println(typeid_of(type_of(y))); // bit_set[0..8]
+ fmt.println(typeid_of(type_of(y))); // bit_set[0..8l u16]
incl(&x, 'F');
assert('F' in x);
diff --git a/src/gb/gb.h b/src/gb/gb.h
index d52b02d91..b23be9449 100644
--- a/src/gb/gb.h
+++ b/src/gb/gb.h
@@ -937,6 +937,7 @@ typedef struct gbMutex {
CRITICAL_SECTION win32_critical_section;
#else
pthread_mutex_t pthread_mutex;
+ pthread_mutexattr_t pthread_mutexattr;
#endif
} gbMutex;
@@ -4609,8 +4610,9 @@ gb_inline void gb_mutex_init(gbMutex *m) {
#if defined(GB_SYSTEM_WINDOWS)
InitializeCriticalSection(&m->win32_critical_section);
#else
- // IMPORTANT TODO HACK(bill): Enable this
- // pthread_mutex_init(&m->pthread_mutex, NULL);
+ pthread_mutexattr_init(&m->pthread_mutexattr);
+ pthread_mutexattr_settype(&m->pthread_mutexattr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init(&m->pthread_mutex, &m->pthread_mutexattr);
#endif
}
@@ -4618,8 +4620,7 @@ gb_inline void gb_mutex_destroy(gbMutex *m) {
#if defined(GB_SYSTEM_WINDOWS)
DeleteCriticalSection(&m->win32_critical_section);
#else
- // IMPORTANT TODO HACK(bill): Enable this
- // pthread_mutex_destroy(&m->pthread_mutex);
+ pthread_mutex_destroy(&m->pthread_mutex);
#endif
}
@@ -4627,8 +4628,7 @@ gb_inline void gb_mutex_lock(gbMutex *m) {
#if defined(GB_SYSTEM_WINDOWS)
EnterCriticalSection(&m->win32_critical_section);
#else
- // IMPORTANT TODO HACK(bill): Enable this
- // pthread_mutex_lock(&m->pthread_mutex);
+ pthread_mutex_lock(&m->pthread_mutex);
#endif
}
@@ -4636,9 +4636,7 @@ gb_inline b32 gb_mutex_try_lock(gbMutex *m) {
#if defined(GB_SYSTEM_WINDOWS)
return TryEnterCriticalSection(&m->win32_critical_section) != 0;
#else
- // IMPORTANT TODO HACK(bill): Enable this
- // return pthread_mutex_trylock(&m->pthread_mutex) == 0;
- return 1;
+ return pthread_mutex_trylock(&m->pthread_mutex) == 0;
#endif
}