mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-10 19:33:28 +00:00
add mutex
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@691 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -1,26 +1,28 @@
|
||||
/* $Id$ */
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
void* MwDynamicOpen(const char* path) {
|
||||
#ifdef _WIN32
|
||||
return LoadLibrary(path);
|
||||
#else
|
||||
return dlopen(path, RTLD_LAZY | RTLD_LOCAL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* MwDynamicSymbol(void* handle, const char* symbol) {
|
||||
#ifdef _WIN32
|
||||
return GetProcAddress(handle, symbol);
|
||||
#else
|
||||
return dlsym(handle, symbol);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MwDynamicClose(void* handle) {
|
||||
#ifdef _WIN32
|
||||
FreeLibrary(handle);
|
||||
#else
|
||||
dlclose(handle);
|
||||
#endif
|
||||
}
|
||||
#elif defined(__unix__)
|
||||
void* MwDynamicOpen(const char* path) {
|
||||
return dlopen(path, RTLD_LOCAL | RTLD_LAZY);
|
||||
}
|
||||
|
||||
void* MwDynamicSymbol(void* handle, const char* symbol) {
|
||||
return dlsym(handle, symbol);
|
||||
}
|
||||
|
||||
void MwDynamicClose(void* handle) {
|
||||
dlclose(handle);
|
||||
}
|
||||
#endif
|
||||
|
||||
44
src/abstract/mutex.c
Normal file
44
src/abstract/mutex.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* $Id$ */
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
void* MwMutexCreate(void) {
|
||||
return CreateEvent(NULL, FALSE, TRUE, NULL);
|
||||
}
|
||||
|
||||
void MwMutexDestroy(void* handle) {
|
||||
CloseHandle(handle);
|
||||
}
|
||||
|
||||
void MwMutexLock(void* handle) {
|
||||
WaitForSingleObject(handle, INFINITE);
|
||||
}
|
||||
|
||||
void MwMutexUnlock(void* handle) {
|
||||
SetEvent(handle);
|
||||
}
|
||||
#elif defined(__unix__)
|
||||
#include <pthread.h>
|
||||
|
||||
void* MwMutexCreate(void) {
|
||||
pthread_mutex_t* m = malloc(sizeof(*m));
|
||||
|
||||
pthread_mutex_init(m, NULL);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
void MwMutexDestroy(void* handle) {
|
||||
pthread_mutex_destroy(handle);
|
||||
|
||||
free(handle);
|
||||
}
|
||||
|
||||
void MwMutexLock(void* handle) {
|
||||
pthread_mutex_lock(handle);
|
||||
}
|
||||
|
||||
void MwMutexUnlock(void* handle) {
|
||||
pthread_mutex_unlock(handle);
|
||||
}
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
/* $Id$ */
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32)
|
||||
long MwTimeGetTick(void) {
|
||||
return GetTickCount();
|
||||
}
|
||||
@@ -9,7 +9,7 @@ long MwTimeGetTick(void) {
|
||||
void MwTimeSleep(int ms) {
|
||||
Sleep(ms);
|
||||
}
|
||||
#else
|
||||
#elif defined(__unix__)
|
||||
long MwTimeGetTick(void) {
|
||||
struct timespec ts;
|
||||
long n = 0;
|
||||
|
||||
Reference in New Issue
Block a user