From 855f16c18b724b0e88b495b78a5a5852617958f9 Mon Sep 17 00:00:00 2001 From: Joel de Vahl Date: Thu, 4 Oct 2007 09:49:38 +0000 Subject: win32 fixes for the lock --- src/engine/system.c | 27 ++++++++++++++++++++++++--- src/engine/system.h | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'src/engine') diff --git a/src/engine/system.c b/src/engine/system.c index 381b7ca3..8c869d53 100644 --- a/src/engine/system.c +++ b/src/engine/system.c @@ -25,6 +25,7 @@ #include #elif defined(CONF_FAMILY_WINDOWS) #define WIN32_LEAN_AND_MEAN + #define _WIN32_WINNT 0x0400 #include #include #include @@ -35,6 +36,10 @@ #error NOT IMPLEMENTED #endif +#if defined(__cplusplus) +extern "C" { +#endif + IOHANDLE logfile = 0; void dbg_assert_imp(const char *filename, int line, int test, const char *msg) @@ -254,26 +259,32 @@ void thread_sleep(int milliseconds) #if defined(CONF_FAMILY_UNIX) typedef pthread_mutex_t LOCKINTERNAL; +#elif defined(CONF_FAMILY_WINDOWS) +typedef CRITICAL_SECTION LOCKINTERNAL; #else #error not implemented on this platform #endif LOCK lock_create() { - LOCKINTERNAL *l = (LOCKINTERNAL*)mem_alloc(sizeof(LOCKINTERNAL), 4); + LOCKINTERNAL *lock = (LOCKINTERNAL*)mem_alloc(sizeof(LOCKINTERNAL), 4); #if defined(CONF_FAMILY_UNIX) - pthread_mutex_init(l, 0x0); + pthread_mutex_init(lock, 0x0); +#elif defined(CONF_FAMILY_WINDOWS) + InitializeCriticalSection((LPCRITICAL_SECTION)lock); #else #error not implemented on this platform #endif - return l; + return lock; } void lock_destroy(LOCK lock) { #if defined(CONF_FAMILY_UNIX) pthread_mutex_destroy(lock); +#elif defined(CONF_FAMILY_WINDOWS) + DeleteCriticalSection((LPCRITICAL_SECTION)lock); #else #error not implemented on this platform #endif @@ -284,6 +295,8 @@ int lock_try(LOCK lock) { #if defined(CONF_FAMILY_UNIX) return pthread_mutex_trylock(lock); +#elif defined(CONF_FAMILY_WINDOWS) + return TryEnterCriticalSection((LPCRITICAL_SECTION)lock); #else #error not implemented on this platform #endif @@ -293,6 +306,8 @@ void lock_wait(LOCK lock) { #if defined(CONF_FAMILY_UNIX) pthread_mutex_lock(lock); +#elif defined(CONF_FAMILY_WINDOWS) + EnterCriticalSection((LPCRITICAL_SECTION)lock); #else #error not implemented on this platform #endif @@ -302,6 +317,8 @@ void lock_release(LOCK lock) { #if defined(CONF_FAMILY_UNIX) pthread_mutex_unlock(lock); +#elif defined(CONF_FAMILY_WINDOWS) + LeaveCriticalSection((LPCRITICAL_SECTION)lock); #else #error not implemented on this platform #endif @@ -650,3 +667,7 @@ void swap_endian(void *data, unsigned elem_size, unsigned num) num--; } } + +#if defined(__cplusplus) +} +#endif diff --git a/src/engine/system.h b/src/engine/system.h index fe866cdc..5c3fa394 100644 --- a/src/engine/system.h +++ b/src/engine/system.h @@ -292,7 +292,7 @@ int thread_wait(); /* NOT IMPLEMENTED */ void thread_sleep(int milliseconds); /**** Group: Locks ****/ -typedef struct LOCKINTERNAL *LOCK; +typedef void* LOCK; LOCK lock_create(); void lock_destroy(LOCK lock); -- cgit 1.4.1