move utils into subfolder
manager thread (wip)
This commit is contained in:
50
src/utils/mutex.c
Normal file
50
src/utils/mutex.c
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// Created by nicol on 2018-03-18.
|
||||
//
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "mutex.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
mutex_t mutex_create() {
|
||||
mutex_t mutex = malloc(sizeof(CRITICAL_SECTION));
|
||||
InitializeCriticalSection(mutex);
|
||||
return mutex;
|
||||
}
|
||||
|
||||
void mutex_lock(mutex_t mutex) {
|
||||
EnterCriticalSection(mutex);
|
||||
}
|
||||
|
||||
void mutex_unlock(mutex_t mutex) {
|
||||
LeaveCriticalSection(mutex);
|
||||
}
|
||||
|
||||
void mutex_destroy(mutex_t mutex) {
|
||||
DeleteCriticalSection(mutex);
|
||||
}
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
mutex_t mutex_create() {
|
||||
mutex_t mutex = malloc(sizeof(mutex_t));
|
||||
pthread_mutex_init(mutex, 0);
|
||||
return mutex;
|
||||
}
|
||||
|
||||
void mutex_lock(mutex_t mutex) {
|
||||
pthread_mutex_lock(mutex);
|
||||
}
|
||||
|
||||
void mutex_unlock(mutex_t mutex) {
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
|
||||
void mutex_destroy(mutex_t mutex) {
|
||||
pthread_mutex_destroy(mutex);
|
||||
free(mutex);
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user