diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt index 98a7c105e..d01fe6953 100644 --- a/src/wrapped/generated/functions_list.txt +++ b/src/wrapped/generated/functions_list.txt @@ -3660,6 +3660,7 @@ wrappedlibpthread: - pthread_mutex_timedlock - pthread_once - pthread_setname_np + - sem_timedwait - vFppp: - _pthread_cleanup_push - _pthread_cleanup_push_defer diff --git a/src/wrapped/generated/wrappedlibpthreadtypes.h b/src/wrapped/generated/wrappedlibpthreadtypes.h index c606a6422..556ed3e5e 100644 --- a/src/wrapped/generated/wrappedlibpthreadtypes.h +++ b/src/wrapped/generated/wrappedlibpthreadtypes.h @@ -67,6 +67,7 @@ typedef int32_t (*iFpppp_t)(void*, void*, void*, void*); GO(pthread_mutex_timedlock, iFpp_t) \ GO(pthread_once, iFpp_t) \ GO(pthread_setname_np, iFpp_t) \ + GO(sem_timedwait, iFpp_t) \ GO(_pthread_cleanup_push, vFppp_t) \ GO(_pthread_cleanup_push_defer, vFppp_t) \ GO(pthread_setaffinity_np, iFLup_t) \ diff --git a/src/wrapped/wrappedlibpthread.c b/src/wrapped/wrappedlibpthread.c index ee7364b48..e97380666 100755 --- a/src/wrapped/wrappedlibpthread.c +++ b/src/wrapped/wrappedlibpthread.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "wrappedlibs.h" @@ -132,6 +133,27 @@ EXPORT void my___pthread_initialize() // nothing, the lib initialize itself now } +void Timespec2Timespec64(void* dest, const void* source); +EXPORT int my_sem_timedwait(sem_t* sem, struct timespec * t) +{ + // some x86 game are not computing timeout correctly (ex: Anomaly Warzone Earth linux version) + #ifdef __USE_TIME64_REDIRECTS + struct timespec t1; + Timespec2Timespec64(&t1, t); + while(t1.tv_nsec>=1000000000) { + t1.tv_nsec-=1000000000; + t1.tv_sec+=1; + } + return sem_timedwait(sem, &t1); + #else + while(t->tv_nsec>=1000000000) { + t->tv_nsec-=1000000000; + t->tv_sec+=1; + } + return sem_timedwait(sem, t); + #endif +} + #define PRE_INIT\ if(1) \ lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL); \ diff --git a/src/wrapped/wrappedlibpthread_private.h b/src/wrapped/wrappedlibpthread_private.h index 2a8b94de4..9d081bba7 100755 --- a/src/wrapped/wrappedlibpthread_private.h +++ b/src/wrapped/wrappedlibpthread_private.h @@ -202,7 +202,7 @@ GO(sem_getvalue, iFpp) GO(sem_init, iFpiu) GO(sem_open, pFpOM) GO(sem_post, iFp) -GO(sem_timedwait, iFpp) +GOM(sem_timedwait, iFpp) //%noE GO(sem_trywait, iFp) GO(sem_unlink, iFp) GO(sem_wait, iFp)