From 65497160f755c3d656902aaac2e318169dac63fe Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 25 Jul 2011 11:29:44 -0700 Subject: [PATCH] Removed deprecated Mac OS X APIs. --- src/platform_macosx.c | 38 ------------------ src/platform_posix.c | 93 +++++++++++++++++++++++++++++++++++++++++++ src/platform_unix.c | 91 ------------------------------------------ 3 files changed, 93 insertions(+), 129 deletions(-) diff --git a/src/platform_macosx.c b/src/platform_macosx.c index 3fa6185a..17ffb9a6 100644 --- a/src/platform_macosx.c +++ b/src/platform_macosx.c @@ -375,44 +375,6 @@ int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a) return 1; /* return non-zero: we're supplying custom allocator. */ } /* __PHYSFS_platformSetDefaultAllocator */ - -void *__PHYSFS_platformGetThreadID(void) -{ - return ( (void *) ((size_t) MPCurrentTaskID()) ); -} /* __PHYSFS_platformGetThreadID */ - - -void *__PHYSFS_platformCreateMutex(void) -{ - MPCriticalRegionID m = NULL; - if (osxerr(MPCreateCriticalRegion(&m)) != noErr) - return NULL; - return m; -} /* __PHYSFS_platformCreateMutex */ - - -void __PHYSFS_platformDestroyMutex(void *mutex) -{ - MPCriticalRegionID m = (MPCriticalRegionID) mutex; - MPDeleteCriticalRegion(m); -} /* __PHYSFS_platformDestroyMutex */ - - -int __PHYSFS_platformGrabMutex(void *mutex) -{ - MPCriticalRegionID m = (MPCriticalRegionID) mutex; - if (MPEnterCriticalRegion(m, kDurationForever) != noErr) - return 0; - return 1; -} /* __PHYSFS_platformGrabMutex */ - - -void __PHYSFS_platformReleaseMutex(void *mutex) -{ - MPCriticalRegionID m = (MPCriticalRegionID) mutex; - MPExitCriticalRegion(m); -} /* __PHYSFS_platformReleaseMutex */ - #endif /* PHYSFS_PLATFORM_MACOSX */ /* end of macosx.c ... */ diff --git a/src/platform_posix.c b/src/platform_posix.c index fcd05dc4..0170f082 100644 --- a/src/platform_posix.c +++ b/src/platform_posix.c @@ -20,6 +20,10 @@ #include #include +#if ((!defined PHYSFS_NO_THREAD_SUPPORT) && (!defined PHYSFS_PLATFORM_BEOS)) +#include +#endif + #ifdef PHYSFS_HAVE_LLSEEK #include #endif @@ -433,6 +437,95 @@ int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *st) return 1; } /* __PHYSFS_platformStat */ + +#ifndef PHYSFS_PLATFORM_BEOS /* BeOS has its own code in platform_beos.cpp */ +#if (defined PHYSFS_NO_THREAD_SUPPORT) + +void *__PHYSFS_platformGetThreadID(void) { return ((void *) 0x0001); } +void *__PHYSFS_platformCreateMutex(void) { return ((void *) 0x0001); } +void __PHYSFS_platformDestroyMutex(void *mutex) {} +int __PHYSFS_platformGrabMutex(void *mutex) { return 1; } +void __PHYSFS_platformReleaseMutex(void *mutex) {} + +#else + +typedef struct +{ + pthread_mutex_t mutex; + pthread_t owner; + PHYSFS_uint32 count; +} PthreadMutex; + + +void *__PHYSFS_platformGetThreadID(void) +{ + return ( (void *) ((size_t) pthread_self()) ); +} /* __PHYSFS_platformGetThreadID */ + + +void *__PHYSFS_platformCreateMutex(void) +{ + int rc; + PthreadMutex *m = (PthreadMutex *) allocator.Malloc(sizeof (PthreadMutex)); + BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, NULL); + rc = pthread_mutex_init(&m->mutex, NULL); + if (rc != 0) + { + allocator.Free(m); + BAIL_MACRO(strerror(rc), NULL); + } /* if */ + + m->count = 0; + m->owner = (pthread_t) 0xDEADBEEF; + return ((void *) m); +} /* __PHYSFS_platformCreateMutex */ + + +void __PHYSFS_platformDestroyMutex(void *mutex) +{ + PthreadMutex *m = (PthreadMutex *) mutex; + + /* Destroying a locked mutex is a bug, but we'll try to be helpful. */ + if ((m->owner == pthread_self()) && (m->count > 0)) + pthread_mutex_unlock(&m->mutex); + + pthread_mutex_destroy(&m->mutex); + allocator.Free(m); +} /* __PHYSFS_platformDestroyMutex */ + + +int __PHYSFS_platformGrabMutex(void *mutex) +{ + PthreadMutex *m = (PthreadMutex *) mutex; + pthread_t tid = pthread_self(); + if (m->owner != tid) + { + if (pthread_mutex_lock(&m->mutex) != 0) + return 0; + m->owner = tid; + } /* if */ + + m->count++; + return 1; +} /* __PHYSFS_platformGrabMutex */ + + +void __PHYSFS_platformReleaseMutex(void *mutex) +{ + PthreadMutex *m = (PthreadMutex *) mutex; + if (m->owner == pthread_self()) + { + if (--m->count == 0) + { + m->owner = (pthread_t) 0xDEADBEEF; + pthread_mutex_unlock(&m->mutex); + } /* if */ + } /* if */ +} /* __PHYSFS_platformReleaseMutex */ + +#endif /* !PHYSFS_NO_THREAD_SUPPORT */ +#endif /* !PHYSFS_PLATFORM_BEOS */ + #endif /* PHYSFS_PLATFORM_POSIX */ /* end of posix.c ... */ diff --git a/src/platform_unix.c b/src/platform_unix.c index 4dcd366d..aa9be7c3 100644 --- a/src/platform_unix.c +++ b/src/platform_unix.c @@ -21,10 +21,6 @@ #include #include -#if (!defined PHYSFS_NO_THREAD_SUPPORT) -#include -#endif - #ifdef PHYSFS_HAVE_SYS_UCRED_H # ifdef PHYSFS_HAVE_MNTENT_H # undef PHYSFS_HAVE_MNTENT_H /* don't do both... */ @@ -355,93 +351,6 @@ int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a) return 0; /* just use malloc() and friends. */ } /* __PHYSFS_platformSetDefaultAllocator */ - -#if (defined PHYSFS_NO_THREAD_SUPPORT) - -void *__PHYSFS_platformGetThreadID(void) { return ((void *) 0x0001); } -void *__PHYSFS_platformCreateMutex(void) { return ((void *) 0x0001); } -void __PHYSFS_platformDestroyMutex(void *mutex) {} -int __PHYSFS_platformGrabMutex(void *mutex) { return 1; } -void __PHYSFS_platformReleaseMutex(void *mutex) {} - -#else - -typedef struct -{ - pthread_mutex_t mutex; - pthread_t owner; - PHYSFS_uint32 count; -} PthreadMutex; - - -void *__PHYSFS_platformGetThreadID(void) -{ - return ( (void *) ((size_t) pthread_self()) ); -} /* __PHYSFS_platformGetThreadID */ - - -void *__PHYSFS_platformCreateMutex(void) -{ - int rc; - PthreadMutex *m = (PthreadMutex *) allocator.Malloc(sizeof (PthreadMutex)); - BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, NULL); - rc = pthread_mutex_init(&m->mutex, NULL); - if (rc != 0) - { - allocator.Free(m); - BAIL_MACRO(strerror(rc), NULL); - } /* if */ - - m->count = 0; - m->owner = (pthread_t) 0xDEADBEEF; - return ((void *) m); -} /* __PHYSFS_platformCreateMutex */ - - -void __PHYSFS_platformDestroyMutex(void *mutex) -{ - PthreadMutex *m = (PthreadMutex *) mutex; - - /* Destroying a locked mutex is a bug, but we'll try to be helpful. */ - if ((m->owner == pthread_self()) && (m->count > 0)) - pthread_mutex_unlock(&m->mutex); - - pthread_mutex_destroy(&m->mutex); - allocator.Free(m); -} /* __PHYSFS_platformDestroyMutex */ - - -int __PHYSFS_platformGrabMutex(void *mutex) -{ - PthreadMutex *m = (PthreadMutex *) mutex; - pthread_t tid = pthread_self(); - if (m->owner != tid) - { - if (pthread_mutex_lock(&m->mutex) != 0) - return 0; - m->owner = tid; - } /* if */ - - m->count++; - return 1; -} /* __PHYSFS_platformGrabMutex */ - - -void __PHYSFS_platformReleaseMutex(void *mutex) -{ - PthreadMutex *m = (PthreadMutex *) mutex; - if (m->owner == pthread_self()) - { - if (--m->count == 0) - { - m->owner = (pthread_t) 0xDEADBEEF; - pthread_mutex_unlock(&m->mutex); - } /* if */ - } /* if */ -} /* __PHYSFS_platformReleaseMutex */ - -#endif /* !PHYSFS_NO_THREAD_SUPPORT */ - #endif /* PHYSFS_PLATFORM_UNIX */ /* end of unix.c ... */