From 0d8bf3a1297bfc8dd3fcbd22db6f56c839932b11 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 22 Mar 2012 00:41:39 -0400 Subject: [PATCH] Windows: Use cross-thread Critical Sections instead of cross-process Mutexes. --- src/platform_windows.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/platform_windows.c b/src/platform_windows.c index d5493ac..94ad75e 100644 --- a/src/platform_windows.c +++ b/src/platform_windows.c @@ -795,32 +795,33 @@ int __PHYSFS_platformDelete(const char *path) } /* __PHYSFS_platformDelete */ -/* - * !!! FIXME: why aren't we using Critical Sections instead of Mutexes? - * !!! FIXME: mutexes on Windows are for cross-process sync. CritSects are - * !!! FIXME: mutexes for threads in a single process and are faster. - */ void *__PHYSFS_platformCreateMutex(void) { - return ((void *) CreateMutex(NULL, FALSE, NULL)); + LPCRITICAL_SECTION lpcs; + lpcs = (LPCRITICAL_SECTION) allocator.Malloc(sizeof (CRITICAL_SECTION)); + BAIL_IF_MACRO(!lpcs, PHYSFS_ERR_OUT_OF_MEMORY, NULL); + InitializeCriticalSection(lpcs); + return lpcs; } /* __PHYSFS_platformCreateMutex */ void __PHYSFS_platformDestroyMutex(void *mutex) { - CloseHandle((HANDLE) mutex); + DeleteCriticalSection((LPCRITICAL_SECTION) mutex); + allocator.Free(mutex); } /* __PHYSFS_platformDestroyMutex */ int __PHYSFS_platformGrabMutex(void *mutex) { - return (WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED); + EnterCriticalSection((LPCRITICAL_SECTION) mutex); + return 1; } /* __PHYSFS_platformGrabMutex */ void __PHYSFS_platformReleaseMutex(void *mutex) { - ReleaseMutex((HANDLE) mutex); + LeaveCriticalSection((LPCRITICAL_SECTION) mutex); } /* __PHYSFS_platformReleaseMutex */