update
This commit is contained in:
parent
63fb35c899
commit
667434cadc
3 changed files with 59 additions and 0 deletions
|
|
@ -4,3 +4,10 @@ target_link_libraries(
|
|||
PRIVATE
|
||||
Mw
|
||||
)
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_link_libraries(
|
||||
MDECore
|
||||
PRIVATE
|
||||
pthread
|
||||
)
|
||||
endif()
|
||||
|
|
|
|||
20
core/mutex.c
20
core/mutex.c
|
|
@ -19,4 +19,24 @@ void MDEMutexUnlock(MDEMutex mutex) {
|
|||
SetEvent(mutex);
|
||||
}
|
||||
#else
|
||||
#include <pthread.h>
|
||||
|
||||
MDEMutex MDEMutexCreate(void) {
|
||||
pthread_mutex_t* m = malloc(sizeof(*m));
|
||||
pthread_mutex_init(m, NULL);
|
||||
return m;
|
||||
}
|
||||
|
||||
void MDEMutexDestroy(MDEMutex mutex) {
|
||||
pthread_mutex_destroy(mutex);
|
||||
free(mutex);
|
||||
}
|
||||
|
||||
void MDEMutexLock(MDEMutex mutex) {
|
||||
pthread_mutex_lock(mutex);
|
||||
}
|
||||
|
||||
void MDEMutexUnlock(MDEMutex mutex) {
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -31,4 +31,36 @@ void MDEThreadJoin(MDEThread thread) {
|
|||
WaitForSingleObject(thread, INFINITE);
|
||||
}
|
||||
#else
|
||||
#include <pthread.h>
|
||||
|
||||
static void* call_wrapper(void* param) {
|
||||
void** p = param;
|
||||
void (*call)(void* user_data) = p[0];
|
||||
void* ud = p[1];
|
||||
free(p);
|
||||
|
||||
call(ud);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MDEThread MDEThreadCreate(void (*call)(void* user_data), void* user_data) {
|
||||
void** p = malloc(sizeof(*p) * 2);
|
||||
pthread_t* t = malloc(sizeof(*t));
|
||||
|
||||
p[0] = call;
|
||||
p[1] = user_data;
|
||||
|
||||
pthread_create(t, NULL, call_wrapper, p);
|
||||
return t;
|
||||
}
|
||||
|
||||
void MDEThreadDestroy(MDEThread thread) {
|
||||
free(thread);
|
||||
}
|
||||
|
||||
void MDEThreadJoin(MDEThread thread) {
|
||||
void* p;
|
||||
pthread_join(thread, &p);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue