mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-25 08:13:44 +02:00
143 lines
4.4 KiB
Diff
143 lines
4.4 KiB
Diff
# devkitPPC does not provide POSIX semaphores, which OpenAL Soft needs.
|
|
# However, devkitPPC provides an alternative semaphore implementation in an external library, libogc.
|
|
# This patch makes PhysFS use libogc semaphores if POSIX semaphores is not found.
|
|
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -172,11 +172,20 @@ if(PHYSFS_BUILD_STATIC)
|
|
set_target_properties(physfs-static PROPERTIES VS_WINRT_COMPONENT True)
|
|
set_target_properties(physfs-static PROPERTIES STATIC_LIBRARY_FLAGS "/ignore:4264")
|
|
endif()
|
|
+ set(CPP_DEFS)
|
|
+ set(INC_PATHS)
|
|
+ include(CheckSymbolExists)
|
|
+ check_symbol_exists(__DEVKITPPC__ "sys/config.h" DEVKITPPC)
|
|
+ if(DEVKITPPC)
|
|
+ set(CPP_DEFS ${CPP_DEFS} MKXPZ_DEVKITPPC)
|
|
+ set(INC_PATHS ${INC_PATHS} "$ENV{DEVKITPRO}/libogc/include")
|
|
+ endif()
|
|
if(WIN32 OR WINRT OR OS2)
|
|
# no dll exports from the static library
|
|
- target_compile_definitions(physfs-static PRIVATE "PHYSFS_STATIC")
|
|
+ set(CPP_DEFS ${CPP_DEFS} "PHYSFS_STATIC")
|
|
endif()
|
|
- target_include_directories(physfs-static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
|
|
+ target_compile_definitions(physfs-static PRIVATE ${CPP_DEFS})
|
|
+ target_include_directories(physfs-static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>" ${INC_PATHS})
|
|
target_link_libraries(physfs-static PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
|
|
set(PHYSFS_LIB_TARGET physfs-static)
|
|
list(APPEND PHYSFS_INSTALL_TARGETS "physfs-static")
|
|
--- a/src/physfs_platform_posix.c
|
|
+++ b/src/physfs_platform_posix.c
|
|
@@ -19,7 +19,11 @@
|
|
#include <dirent.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
-#include <pthread.h>
|
|
+#ifdef MKXPZ_DEVKITPPC
|
|
+# include <ogc/mutex.h>
|
|
+#else
|
|
+# include <pthread.h>
|
|
+#endif
|
|
|
|
#include "physfs_internal.h"
|
|
|
|
@@ -369,15 +373,23 @@ int __PHYSFS_platformStat(const char *fname, PHYSFS_Stat *st, const int follow)
|
|
|
|
typedef struct
|
|
{
|
|
+#ifdef MKXPZ_DEVKITPPC
|
|
+ mutex_t mutex;
|
|
+#else
|
|
pthread_mutex_t mutex;
|
|
pthread_t owner;
|
|
+#endif
|
|
PHYSFS_uint32 count;
|
|
} PthreadMutex;
|
|
|
|
|
|
void *__PHYSFS_platformGetThreadID(void)
|
|
{
|
|
+#ifdef MKXPZ_DEVKITPPC
|
|
+ return (void *)42;
|
|
+#else
|
|
return ( (void *) ((size_t) pthread_self()) );
|
|
+#endif
|
|
} /* __PHYSFS_platformGetThreadID */
|
|
|
|
|
|
@@ -386,7 +398,11 @@ void *__PHYSFS_platformCreateMutex(void)
|
|
int rc;
|
|
PthreadMutex *m = (PthreadMutex *) allocator.Malloc(sizeof (PthreadMutex));
|
|
BAIL_IF(!m, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
|
|
+#ifdef MKXPZ_DEVKITPPC
|
|
+ rc = LWP_MutexInit(&m->mutex, false);
|
|
+#else
|
|
rc = pthread_mutex_init(&m->mutex, NULL);
|
|
+#endif
|
|
if (rc != 0)
|
|
{
|
|
allocator.Free(m);
|
|
@@ -394,7 +410,9 @@ void *__PHYSFS_platformCreateMutex(void)
|
|
} /* if */
|
|
|
|
m->count = 0;
|
|
+#ifndef MKXPZ_DEVKITPPC
|
|
m->owner = (pthread_t) 0xDEADBEEF;
|
|
+#endif
|
|
return ((void *) m);
|
|
} /* __PHYSFS_platformCreateMutex */
|
|
|
|
@@ -403,11 +421,15 @@ void __PHYSFS_platformDestroyMutex(void *mutex)
|
|
{
|
|
PthreadMutex *m = (PthreadMutex *) mutex;
|
|
|
|
+#ifdef MKXPZ_DEVKITPPC
|
|
+ LWP_MutexDestroy(m->mutex);
|
|
+#else
|
|
/* 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);
|
|
+#endif
|
|
allocator.Free(m);
|
|
} /* __PHYSFS_platformDestroyMutex */
|
|
|
|
@@ -415,6 +437,10 @@ void __PHYSFS_platformDestroyMutex(void *mutex)
|
|
int __PHYSFS_platformGrabMutex(void *mutex)
|
|
{
|
|
PthreadMutex *m = (PthreadMutex *) mutex;
|
|
+#ifdef MKXPZ_DEVKITPPC
|
|
+ if (LWP_MutexLock(m->mutex) != 0)
|
|
+ return 0;
|
|
+#else
|
|
pthread_t tid = pthread_self();
|
|
if (m->owner != tid)
|
|
{
|
|
@@ -422,6 +448,7 @@ int __PHYSFS_platformGrabMutex(void *mutex)
|
|
return 0;
|
|
m->owner = tid;
|
|
} /* if */
|
|
+#endif
|
|
|
|
m->count++;
|
|
return 1;
|
|
@@ -431,6 +458,9 @@ int __PHYSFS_platformGrabMutex(void *mutex)
|
|
void __PHYSFS_platformReleaseMutex(void *mutex)
|
|
{
|
|
PthreadMutex *m = (PthreadMutex *) mutex;
|
|
+#ifdef MKXPZ_DEVKITPPC
|
|
+ LWP_MutexUnlock(m->mutex);
|
|
+#else
|
|
assert(m->owner == pthread_self()); /* catch programming errors. */
|
|
assert(m->count > 0); /* catch programming errors. */
|
|
if (m->owner == pthread_self())
|
|
@@ -441,6 +471,7 @@ void __PHYSFS_platformReleaseMutex(void *mutex)
|
|
pthread_mutex_unlock(&m->mutex);
|
|
} /* if */
|
|
} /* if */
|
|
+#endif
|
|
} /* __PHYSFS_platformReleaseMutex */
|
|
|
|
#endif /* PHYSFS_PLATFORM_POSIX */
|