mkxp-z/subprojects/packagefiles/openal-soft-devkitppc.patch

137 lines
3.7 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 OpenAL Soft use libogc semaphores if POSIX semaphores is not found.
diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -174,6 +174,11 @@ if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
set(INC_PATHS ${INC_PATHS} /usr/include)
set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
endif()
+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()
# When the library is built for static linking, apps should define
# AL_LIBTYPE_STATIC when including the AL headers.
diff --git a/common/alsem.cpp b/common/alsem.cpp
--- a/common/alsem.cpp
+++ b/common/alsem.cpp
@@ -55,8 +55,6 @@ void semaphore::post()
void semaphore::wait() noexcept
{ WaitForSingleObject(static_cast<HANDLE>(mSem), INFINITE); }
-bool semaphore::try_wait() noexcept
-{ return WaitForSingleObject(static_cast<HANDLE>(mSem), 0) == WAIT_OBJECT_0; }
} // namespace al
@@ -83,8 +81,6 @@ void semaphore::post()
void semaphore::wait() noexcept
{ dispatch_semaphore_wait(mSem, DISPATCH_TIME_FOREVER); }
-bool semaphore::try_wait() noexcept
-{ return dispatch_semaphore_wait(mSem, DISPATCH_TIME_NOW) == 0; }
} // namespace al
@@ -96,27 +92,41 @@ namespace al {
semaphore::semaphore(unsigned int initial)
{
+#ifdef MKXPZ_DEVKITPPC
+ if(LWP_SemInit(&mSem, initial, 0xffffffff) != 0)
+#else
if(sem_init(&mSem, 0, initial) != 0)
+#endif
throw std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again));
}
semaphore::~semaphore()
+#ifdef MKXPZ_DEVKITPPC
+{ LWP_SemDestroy(mSem); }
+#else
{ sem_destroy(&mSem); }
+#endif
void semaphore::post()
{
+#ifdef MKXPZ_DEVKITPPC
+ if(LWP_SemPost(mSem) != 0)
+#else
if(sem_post(&mSem) != 0)
+#endif
throw std::system_error(std::make_error_code(std::errc::value_too_large));
}
void semaphore::wait() noexcept
{
+#ifdef MKXPZ_DEVKITPPC
+ LWP_SemWait(mSem);
+#else
while(sem_wait(&mSem) == -1 && errno == EINTR) {
}
+#endif
}
-bool semaphore::try_wait() noexcept
-{ return sem_trywait(&mSem) == 0; }
} // namespace al
diff --git a/common/alsem.h b/common/alsem.h
--- a/common/alsem.h
+++ b/common/alsem.h
@@ -11,7 +11,11 @@
#include <semaphore.h> /* Fallback option for Apple without a working libdispatch */
#endif
#elif !defined(_WIN32)
-#include <semaphore.h>
+# ifdef MKXPZ_DEVKITPPC
+# include <ogc/semaphore.h>
+# else
+# include <semaphore.h>
+# endif
#endif
namespace al {
@@ -35,7 +39,6 @@ public:
void post();
void wait() noexcept;
- bool try_wait() noexcept;
};
} // namespace al
diff --git a/common/althrd_setname.cpp b/common/althrd_setname.cpp
--- a/common/althrd_setname.cpp
+++ b/common/althrd_setname.cpp
@@ -55,13 +55,25 @@ using setname_t4 = int(*)(pthread_t, const char*, void*);
{ func(name); }
[[maybe_unused]] void setname_caller(setname_t2 func, const char *name)
+#ifdef MKXPZ_DEVKITPPC
+{ func(42, name); }
+#else
{ func(pthread_self(), name); }
+#endif
[[maybe_unused]] void setname_caller(setname_t3 func, const char *name)
+#ifdef MKXPZ_DEVKITPPC
+{ func(42, name); }
+#else
{ func(pthread_self(), name); }
+#endif
[[maybe_unused]] void setname_caller(setname_t4 func, const char *name)
+#ifdef MKXPZ_DEVKITPPC
+{ func(42, "%s", const_cast<char*>(name)); /* NOLINT(*-const-cast) */ }
+#else
{ func(pthread_self(), "%s", const_cast<char*>(name)); /* NOLINT(*-const-cast) */ }
+#endif
} // namespace