mkxp-z/subprojects/packagefiles/fluidsynth-mkxp-polyfill.patch

138 lines
2.9 KiB
Diff

# This patch makes FluidSynth use mkxp-polyfill.cpp instead of POSIX threads and `std::mutex` for portability reasons.
--- a/src/utils/fluid_sys.c
+++ b/src/utils/fluid_sys.c
@@ -342,7 +342,7 @@ char *fluid_strtok(char **str, char *delim)
*/
void fluid_msleep(unsigned int msecs)
{
- _thread_sleep(msecs * 1000);
+ fputs("sleeping is not supported by this build of fluidsynth", stderr); abort();
}
/**
@@ -969,7 +969,7 @@ new_fluid_thread(const char *name, fluid_thread_func_t func, void *data, int pri
{
_thread *thread = FLUID_NEW(_thread);
fluid_thread_info_t *info = NULL;
-
+ return NULL;
fluid_return_val_if_fail(func != NULL, NULL);
if(prio_level > 0)
@@ -985,17 +985,17 @@ new_fluid_thread(const char *name, fluid_thread_func_t func, void *data, int pri
info->func = func;
info->data = data;
info->prio_level = prio_level;
- _thread_create(thread, fluid_thread_high_prio, info);
+
}
else
{
- _thread_create(thread, func, data);
+
}
if(detach)
{
- _thread_detach(thread); // Release thread reference, if caller wants to detach
+
}
return thread;
@@ -1008,7 +1008,7 @@ new_fluid_thread(const char *name, fluid_thread_func_t func, void *data, int pri
void
delete_fluid_thread(fluid_thread_t *thread)
{
- _thread_detach(thread);
+
free(thread);
}
@@ -1020,7 +1020,7 @@ delete_fluid_thread(fluid_thread_t *thread)
int
fluid_thread_join(fluid_thread_t *thread)
{
- _thread_join(thread);
+
return FLUID_OK;
}
--- a/src/utils/fluid_threading.cpp
+++ b/src/utils/fluid_threading.cpp
@@ -3,10 +3,10 @@
#include <functional>
#include <chrono>
#include <thread>
-#include <mutex>
-#include <atomic>
+#include "../../../src/mkxp-polyfill.h"
+
#include <ratio>
-#include <condition_variable>
+
thread_local void* privs[16];
bool occupied[16]={false};
void _mutex_init(_mutex *mutex)
@@ -84,33 +84,33 @@ void _private_set(_private *priv,void *val)
for(int i=0;i<16;++i)if(!occupied[i]){priv->id=i+1;break;}
if(priv->id)privs[priv->id-1]=val;
}
-unsigned _thread_get_id(void)
-{
- std::hash<std::thread::id>h;
- return h(std::this_thread::get_id());
-}
-void _thread_create(_thread *th,_thread_func_t func,void* data)
-{
- th->thrd=(void*)(new std::thread(func,data));
-}
-void _thread_detach(_thread *th)
-{
- if(!th->thrd)return;
- ((std::thread*)(th->thrd))->detach();
- delete (std::thread*)(th->thrd);
- th->thrd=nullptr;
-}
-void _thread_join(_thread *th)
-{
- if(!th->thrd)return;
- ((std::thread*)(th->thrd))->join();
- delete (std::thread*)(th->thrd);
- th->thrd=nullptr;
-}
-void _thread_sleep(unsigned long us)
-{
- std::this_thread::sleep_for(std::chrono::microseconds(us));
-}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
double _monotonic_time()
{
return std::chrono::duration_cast<std::chrono::duration<double,std::micro>>(std::chrono::steady_clock::now().time_since_epoch()).count();