From 63f9a21c4463e16ab7f894c8f7aa5c378a5f6fb4 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 24 Mar 2007 05:42:22 +0000 Subject: [PATCH] Replaced BeOS mutex implementation. Now all platforms have recursive mutexes. --- CHANGELOG.txt | 5 +++++ platform/beos.cpp | 25 +++++-------------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 643f0b4..30fb265 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -2,6 +2,11 @@ * CHANGELOG. */ +03242007 - Replaced BeOS semaphores with BLockers for the mutex implementation. + It's much simpler, it has "benaphores" built in behind the scenes + for faster performance, and it's recursive...also, we were + previously setting the PhysicsFS error state if BeOS mutex grabbing + failed (a big no no!), and that's now fixed. Good wins all around. 03222007 - Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(), which will stack allocate small (128 or less bytes) blocks and Malloc the rest...naturally these now have diff --git a/platform/beos.cpp b/platform/beos.cpp index 06fcc96..aac27eb 100644 --- a/platform/beos.cpp +++ b/platform/beos.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -204,43 +205,27 @@ char *__PHYSFS_platformCurrentDir(void) } /* __PHYSFS_platformCurrentDir */ -/* !!! FIXME: semaphores are not mutexes... */ void *__PHYSFS_platformCreateMutex(void) { - sem_id *retval = (sem_id *) allocator.Malloc(sizeof (sem_id)); - sem_id rc; - - BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); - rc = create_sem(1, "PhysicsFS semaphore"); - if (rc < B_OK) - { - allocator.Free(retval); - BAIL_MACRO(strerror(rc), NULL); - } // if - - *retval = rc; - return(retval); + return(new BLocker("PhysicsFS lock", true)); } /* __PHYSFS_platformCreateMutex */ void __PHYSFS_platformDestroyMutex(void *mutex) { - delete_sem( *((sem_id *) mutex) ); - allocator.Free(mutex); + delete ((BLocker *) mutex); } /* __PHYSFS_platformDestroyMutex */ int __PHYSFS_platformGrabMutex(void *mutex) { - status_t rc = acquire_sem(*((sem_id *) mutex)); - BAIL_IF_MACRO(rc < B_OK, strerror(rc), 0); - return(1); + return ((BLocker *) mutex)->Lock() ? 1 : 0; } /* __PHYSFS_platformGrabMutex */ void __PHYSFS_platformReleaseMutex(void *mutex) { - release_sem(*((sem_id *) mutex)); + ((BLocker *) mutex)->Unlock(); } /* __PHYSFS_platformReleaseMutex */