Index: src/objc_sync.m ================================================================== --- src/objc_sync.m +++ src/objc_sync.m @@ -26,26 +26,26 @@ #endif #import "OFMacros.h" struct locks_s { - id obj; - size_t count; - size_t recursion; + id obj; + size_t count; + size_t recursion; #ifndef _WIN32 - pthread_t thread; - pthread_mutex_t mutex; + pthread_t thread; + pthread_mutex_t mutex; #else - HANDLE thread; - HANDLE mutex; + DWORD thread; + CRITICAL_SECTION mutex; #endif }; #ifndef _WIN32 static pthread_mutex_t mutex; #else -static HANDLE mutex; +static CRITICAL_SECTION mutex; #endif static struct locks_s *locks = NULL; static size_t num_locks = 0; #ifndef _WIN32 @@ -84,43 +84,47 @@ { return pthread_self(); } #else static OF_INLINE BOOL -mutex_new(HANDLE *m) -{ - return (((*m = CreateMutex(NULL, FALSE, NULL)) != NULL) ? YES : NO); -} - -static OF_INLINE BOOL -mutex_free(HANDLE *m) -{ - return (CloseHandle(*m) ? YES : NO); -} - -static OF_INLINE BOOL -mutex_lock(HANDLE *m) -{ - return (WaitForSingleObject(*m, INFINITE) == WAIT_OBJECT_0 ? YES : NO); -} - -static OF_INLINE BOOL -mutex_unlock(HANDLE *m) -{ - return (ReleaseMutex(*m) ? YES : NO); -} - -static OF_INLINE BOOL -thread_is_current(HANDLE t) -{ - return (t == GetCurrentThread() ? YES : NO); -} - -static OF_INLINE HANDLE -thread_current() -{ - return GetCurrentThread(); +mutex_new(CRITICAL_SECTION *m) +{ + InitializeCriticalSection(m); + return YES; +} + +static OF_INLINE BOOL +mutex_free(CRITICAL_SECTION *m) +{ + DeleteCriticalSection(m); + return YES; +} + +static OF_INLINE BOOL +mutex_lock(CRITICAL_SECTION *m) +{ + EnterCriticalSection(m); + return YES; +} + +static OF_INLINE BOOL +mutex_unlock(CRITICAL_SECTION *m) +{ + LeaveCriticalSection(m); + return YES; +} + +static OF_INLINE BOOL +thread_is_current(DWORD t) +{ + return (t == GetCurrentThreadId() ? YES : NO); +} + +static OF_INLINE DWORD +thread_current() +{ + return GetCurrentThreadId(); } #endif BOOL objc_sync_init()