Fixed the mutex problem

This commit is contained in:
Allen Webster 2020-01-19 12:16:54 -08:00
parent 7817f8412d
commit 33aa987589
2 changed files with 2 additions and 5 deletions

View File

@ -301,6 +301,7 @@ mac_to_object(Plat_Handle handle){
function void function void
mac_init_recursive_mutex(pthread_mutex_t *mutex){ mac_init_recursive_mutex(pthread_mutex_t *mutex){
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(mutex, &attr); pthread_mutex_init(mutex, &attr);
} }
@ -1370,4 +1371,4 @@ main(int arg_count, char **args){
// NOTE(yuval): Start the app's run loop // NOTE(yuval): Start the app's run loop
[NSApp run]; [NSApp run];
} }
} }

View File

@ -748,10 +748,8 @@ mac_memory_allocate_extended(void *base, u64 size, String_Const_u8 location){
pthread_mutex_lock(&memory_tracker_mutex); pthread_mutex_lock(&memory_tracker_mutex);
{ {
zdll_assert_good(Memory_Annotation_Tracker_Node, memory_tracker.first);
zdll_push_back(memory_tracker.first, memory_tracker.last, node); zdll_push_back(memory_tracker.first, memory_tracker.last, node);
memory_tracker.count += 1; memory_tracker.count += 1;
zdll_assert_good(Memory_Annotation_Tracker_Node, memory_tracker.first);
} }
pthread_mutex_unlock(&memory_tracker_mutex); pthread_mutex_unlock(&memory_tracker_mutex);
@ -769,10 +767,8 @@ mac_memory_free_extended(void *ptr){
pthread_mutex_lock(&memory_tracker_mutex); pthread_mutex_lock(&memory_tracker_mutex);
{ {
zdll_assert_good(Memory_Annotation_Tracker_Node, memory_tracker.first);
zdll_remove(memory_tracker.first, memory_tracker.last, node); zdll_remove(memory_tracker.first, memory_tracker.last, node);
memory_tracker.count -= 1; memory_tracker.count -= 1;
zdll_assert_good(Memory_Annotation_Tracker_Node, memory_tracker.first);
} }
pthread_mutex_unlock(&memory_tracker_mutex); pthread_mutex_unlock(&memory_tracker_mutex);