mkxp-z/subprojects/packagefiles/openal-soft-mkxp-polyfill.patch
2025-06-04 10:18:53 -04:00

589 lines
13 KiB
Diff

# This patch makes OpenAL Soft use mkxp-polyfill.cpp instead of POSIX threads and `std::mutex` for portability reasons.
--- a/al/auxeffectslot.cpp
+++ b/al/auxeffectslot.cpp
@@ -28,7 +28,7 @@
#include <functional>
#include <iterator>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <numeric>
#include <stdexcept>
#include <tuple>
--- a/al/buffer.cpp
+++ b/al/buffer.cpp
@@ -32,7 +32,7 @@
#include <iterator>
#include <limits>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <numeric>
#include <optional>
#include <stdexcept>
--- a/al/debug.cpp
+++ b/al/debug.cpp
@@ -7,7 +7,7 @@
#include <atomic>
#include <cstring>
#include <deque>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <optional>
#include <stdexcept>
#include <string>
--- a/al/effect.cpp
+++ b/al/effect.cpp
@@ -27,7 +27,7 @@
#include <cstring>
#include <iterator>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <numeric>
#include <string>
#include <type_traits>
--- a/al/event.cpp
+++ b/al/event.cpp
@@ -7,7 +7,7 @@
#include <bitset>
#include <exception>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <new>
#include <optional>
#include <string>
--- a/al/filter.cpp
+++ b/al/filter.cpp
@@ -28,7 +28,7 @@
#include <cstdio>
#include <iterator>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <numeric>
#include <unordered_map>
#include <vector>
--- a/al/listener.cpp
+++ b/al/listener.cpp
@@ -24,7 +24,7 @@
#include <algorithm>
#include <cmath>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include "AL/al.h"
#include "AL/alc.h"
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -35,7 +35,7 @@
#include <functional>
#include <limits>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <numeric>
#include <optional>
#include <stdexcept>
--- a/al/state.cpp
+++ b/al/state.cpp
@@ -26,7 +26,7 @@
#include <atomic>
#include <cmath>
#include <deque>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <optional>
#include <stdexcept>
#include <string>
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -48,7 +48,7 @@
#include <iterator>
#include <limits>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <new>
#include <optional>
#include <stdexcept>
@@ -314,7 +314,7 @@ std::atomic<ALCenum> LastNullDeviceError{ALC_NO_ERROR};
bool TrapALCError{false};
/* One-time configuration init control */
-std::once_flag alc_config_once{};
+
/* Flag to specify if alcSuspendContext/alcProcessContext should defer/process
* updates.
@@ -752,7 +752,7 @@ void alc_initconfig()
#endif // ALSOFT_EAX
}
inline void InitConfig()
-{ std::call_once(alc_config_once, [](){alc_initconfig();}); }
+{ alc_initconfig(); }
/************************************************
--- a/alc/alconfig.cpp
+++ b/alc/alconfig.cpp
@@ -37,7 +37,7 @@
#include <fstream>
#include <istream>
#include <limits>
-#include <string>
+#include "../../src/mkxp-polyfill.h"
#include <string_view>
#include <utility>
#include <vector>
--- a/alc/backends/alsa.cpp
+++ b/alc/backends/alsa.cpp
@@ -30,7 +30,7 @@
#include <cstring>
#include <exception>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <string>
#include <string_view>
#include <thread>
--- a/alc/backends/jack.cpp
+++ b/alc/backends/jack.cpp
@@ -27,7 +27,7 @@
#include <cstdio>
#include <cstring>
#include <memory.h>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <thread>
#include <vector>
--- a/alc/backends/opensl.cpp
+++ b/alc/backends/opensl.cpp
@@ -28,7 +28,7 @@
#include <array>
#include <cstdlib>
#include <cstring>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <new>
#include <thread>
#include <functional>
--- a/alc/backends/otherio.cpp
+++ b/alc/backends/otherio.cpp
@@ -49,7 +49,7 @@
#include <cstring>
#include <deque>
#include <future>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <string>
#include <string_view>
#include <thread>
--- a/alc/backends/pipewire.cpp
+++ b/alc/backends/pipewire.cpp
@@ -38,7 +38,7 @@
#include <functional>
#include <iterator>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <optional>
#include <string_view>
#include <thread>
--- a/alc/backends/pulseaudio.cpp
+++ b/alc/backends/pulseaudio.cpp
@@ -33,7 +33,7 @@
#include <cstdint>
#include <cstring>
#include <limits>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <optional>
#include <string>
#include <string_view>
--- a/alc/backends/wasapi.cpp
+++ b/alc/backends/wasapi.cpp
@@ -53,7 +53,7 @@
#include <cstring>
#include <functional>
#include <future>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <string>
#include <string_view>
#include <thread>
--- a/alc/context.h
+++ b/alc/context.h
@@ -8,7 +8,7 @@
#include <cstdint>
#include <deque>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <string>
#include <string_view>
#include <unordered_map>
--- a/alc/device.h
+++ b/alc/device.h
@@ -5,7 +5,7 @@
#include <atomic>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <optional>
#include <string>
#include <unordered_map>
--- a/alc/events.h
+++ b/alc/events.h
@@ -5,7 +5,7 @@
#include "opthelpers.h"
#include <bitset>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <optional>
#include <string_view>
--- a/common/alsem.cpp
+++ b/common/alsem.cpp
@@ -55,8 +55,8 @@ 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 +83,8 @@ 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 +96,27 @@ namespace al {
semaphore::semaphore(unsigned int initial)
{
- if(sem_init(&mSem, 0, initial) != 0)
+ if(mkxp_sem_init(&mSem, initial) != 0)
MKXPZ_THROW(std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again)));
}
semaphore::~semaphore()
-{ sem_destroy(&mSem); }
+{ mkxp_sem_destroy(&mSem); }
void semaphore::post()
{
- if(sem_post(&mSem) != 0)
+ if(mkxp_sem_post(&mSem) != 0)
MKXPZ_THROW(std::system_error(std::make_error_code(std::errc::value_too_large)));
}
void semaphore::wait() noexcept
{
- while(sem_wait(&mSem) == -1 && errno == EINTR) {
+ while(mkxp_sem_wait(&mSem) == -1) {
}
}
-bool semaphore::try_wait() noexcept
-{ return sem_trywait(&mSem) == 0; }
+
+
} // namespace al
--- a/common/alsem.h
+++ b/common/alsem.h
@@ -11,7 +11,7 @@
#include <semaphore.h> /* Fallback option for Apple without a working libdispatch */
#endif
#elif !defined(_WIN32)
-#include <semaphore.h>
+
#endif
namespace al {
@@ -22,7 +22,7 @@ class semaphore {
#elif defined(AL_APPLE_HAVE_DISPATCH)
using native_type = dispatch_semaphore_t;
#else
- using native_type = sem_t;
+ using native_type = mkxp_sem_t;
#endif
native_type mSem{};
@@ -35,7 +35,7 @@ public:
void post();
void wait() noexcept;
- bool try_wait() noexcept;
+
};
} // namespace al
--- a/common/althrd_setname.cpp
+++ b/common/althrd_setname.cpp
@@ -39,39 +39,39 @@ void althrd_setname(const char *name [[maybe_unused]])
#else
-#include <pthread.h>
-#ifdef HAVE_PTHREAD_NP_H
-#include <pthread_np.h>
-#endif
+#include "../../src/mkxp-polyfill.h"
+
+
+
+
namespace {
using setname_t1 = int(*)(const char*);
-using setname_t2 = int(*)(pthread_t, const char*);
-using setname_t3 = void(*)(pthread_t, const char*);
-using setname_t4 = int(*)(pthread_t, const char*, void*);
+using setname_t2 = int(*)(mkxp_thread_id_t, const char*);
+using setname_t3 = void(*)(mkxp_thread_id_t, const char*);
+using setname_t4 = int(*)(mkxp_thread_id_t, const char*, void*);
[[maybe_unused]] void setname_caller(setname_t1 func, const char *name)
{ func(name); }
[[maybe_unused]] void setname_caller(setname_t2 func, const char *name)
-{ func(pthread_self(), name); }
+{ func(mkxp_thread_self(), name); }
[[maybe_unused]] void setname_caller(setname_t3 func, const char *name)
-{ func(pthread_self(), name); }
+{ func(mkxp_thread_self(), name); }
[[maybe_unused]] void setname_caller(setname_t4 func, const char *name)
-{ func(pthread_self(), "%s", const_cast<char*>(name)); /* NOLINT(*-const-cast) */ }
+{ func(mkxp_thread_self(), "%s", const_cast<char*>(name)); /* NOLINT(*-const-cast) */ }
} // namespace
void althrd_setname(const char *name [[maybe_unused]])
{
-#if defined(HAVE_PTHREAD_SET_NAME_NP)
- setname_caller(pthread_set_name_np, name);
-#elif defined(HAVE_PTHREAD_SETNAME_NP)
- setname_caller(pthread_setname_np, name);
-#endif
-}
+
+
+
+
+}
#endif
--- a/common/althreads.h
+++ b/common/althreads.h
@@ -5,7 +5,7 @@
#include <stdexcept>
#include <type_traits>
#include "../../src/mkxp-polyfill.h"
-#ifdef _WIN32
+#if false
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -13,7 +13,7 @@
#include <pthread.h>
-#else
+#elif false
#include <threads.h>
#endif
@@ -54,7 +54,7 @@ class tss {
return static_cast<T>(al::bit_cast<std::uintptr_t>(ptr));
}
-#ifdef _WIN32
+/*
DWORD mTss{TLS_OUT_OF_INDEXES};
public:
@@ -105,32 +105,33 @@ public:
[[nodiscard]]
auto get() const noexcept -> T { return from_ptr(pthread_getspecific(mTss)); }
-#else
+*/
- tss_t mTss{};
+ void **mTss;
public:
tss()
{
- if(int res{tss_create(&mTss, nullptr)}; res != thrd_success)
+ if((mTss = static_cast<void **>(std::malloc(sizeof *mTss))) == nullptr)
MKXPZ_THROW(std::runtime_error{"al::tss::tss()"});
+ *mTss = nullptr;
}
explicit tss(const T &init) : tss{}
{
- if(int res{tss_set(mTss, to_ptr(init))}; res != thrd_success)
+ if((mTss = static_cast<void **>(std::malloc(sizeof *mTss))) == nullptr)
MKXPZ_THROW(std::runtime_error{"al::tss::tss(T)"});
+ *mTss = to_ptr(init);
}
- ~tss() { tss_delete(mTss); }
+ ~tss() { std::free(mTss); }
void set(const T &value) const
{
- if(int res{tss_set(mTss, to_ptr(value))}; res != thrd_success)
- MKXPZ_THROW(std::runtime_error{"al::tss::set(T)"});
+ *mTss = to_ptr(value);
}
[[nodiscard]]
- auto get() const noexcept -> T { return from_ptr(tss_get(mTss)); }
-#endif /* _WIN32 */
+ auto get() const noexcept -> T { return from_ptr(*mTss); }
+
tss(const tss&) = delete;
tss(tss&&) = delete;
--- a/core/context.h
+++ b/core/context.h
@@ -140,7 +140,7 @@ struct ContextBase {
*/
al::atomic_unique_ptr<EffectSlotArray> mActiveAuxSlots;
- std::thread mEventThread;
+
al::semaphore mEventSem;
std::unique_ptr<RingBuffer> mAsyncEvents;
using AsyncEventBitset = std::bitset<al::to_underlying(AsyncEnableBits::Count)>;
--- a/core/converter.cpp
+++ b/core/converter.cpp
@@ -5,7 +5,7 @@
#include <algorithm>
#include <cassert>
-#include <cmath>
+#include "../../src/mkxp-polyfill.h"
#include <cstddef>
#include <cstdint>
#include <iterator>
--- a/core/dbus_wrap.cpp
+++ b/core/dbus_wrap.cpp
@@ -5,7 +5,7 @@
#if HAVE_DYNLOAD
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <type_traits>
#include "logging.h"
--- a/core/dbus_wrap.h
+++ b/core/dbus_wrap.h
@@ -9,7 +9,7 @@
#if HAVE_DYNLOAD
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#define DBUS_FUNCTIONS(MAGIC) \
MAGIC(dbus_error_init) \
--- a/core/helpers.cpp
+++ b/core/helpers.cpp
@@ -12,7 +12,7 @@
#include <cstdlib>
#include <cstring>
#include <limits>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <optional>
#include <string>
#include <string_view>
--- a/core/hrtf.cpp
+++ b/core/hrtf.cpp
@@ -15,7 +15,7 @@
#include <fstream>
#include <iterator>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <numeric>
#include <optional>
#include <tuple>
--- a/core/logging.cpp
+++ b/core/logging.cpp
@@ -7,7 +7,7 @@
#include <cstdarg>
#include <cstdio>
#include <cstring>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <optional>
#include <string>
#include <string_view>
--- a/core/mastering.cpp
+++ b/core/mastering.cpp
@@ -4,7 +4,7 @@
#include "mastering.h"
#include <algorithm>
-#include <cmath>
+#include "../../src/mkxp-polyfill.h"
#include <cstddef>
#include <functional>
#include <iterator>
--- a/examples/alffplay.cpp
+++ b/examples/alffplay.cpp
@@ -20,7 +20,7 @@
#include <functional>
#include <future>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <ratio>
#include <string>
#include <string_view>
--- a/router/alc.cpp
+++ b/router/alc.cpp
@@ -7,7 +7,7 @@
#include <cstdlib>
#include <cstring>
#include <cstdio>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <optional>
#include <string_view>
#include <tuple>
--- a/router/router.h
+++ b/router/router.h
@@ -8,7 +8,7 @@
#include <atomic>
#include <cstdio>
#include <memory>
-#include <mutex>
+#include "../../src/mkxp-polyfill.h"
#include <string>
#include <utility>
#include <vector>