diff options
| author | Joel de Vahl <joel@stalverk80.se> | 2007-10-04 09:49:38 +0000 |
|---|---|---|
| committer | Joel de Vahl <joel@stalverk80.se> | 2007-10-04 09:49:38 +0000 |
| commit | 855f16c18b724b0e88b495b78a5a5852617958f9 (patch) | |
| tree | 5856e3777f63c416f0fb64f0413fea649190d909 | |
| parent | 34005785af5c7bd42ffb48f57b883d4f100aca35 (diff) | |
| download | zcatch-855f16c18b724b0e88b495b78a5a5852617958f9.tar.gz zcatch-855f16c18b724b0e88b495b78a5a5852617958f9.zip | |
win32 fixes for the lock
| -rw-r--r-- | src/engine/system.c | 27 | ||||
| -rw-r--r-- | src/engine/system.h | 2 |
2 files changed, 25 insertions, 4 deletions
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 <unistd.h> #elif defined(CONF_FAMILY_WINDOWS) #define WIN32_LEAN_AND_MEAN + #define _WIN32_WINNT 0x0400 #include <windows.h> #include <winsock2.h> #include <ws2tcpip.h> @@ -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); |