This commit is contained in:
Nishi 2025-11-25 17:57:52 +09:00
commit 667434cadc
Signed by: nishi
GPG key ID: 27EF69B208EB9343
3 changed files with 59 additions and 0 deletions

View file

@ -4,3 +4,10 @@ target_link_libraries(
PRIVATE
Mw
)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(
MDECore
PRIVATE
pthread
)
endif()

View file

@ -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

View file

@ -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