diff --git a/contrib/pthread-shim.c b/contrib/pthread-shim.c index 920416e887cde216acd7f1c5b95ab11a041c4323..ed7c27a63daafde0b7847e352e59b3f991210b04 100755 --- a/contrib/pthread-shim.c +++ b/contrib/pthread-shim.c @@ -6,7 +6,18 @@ #include "time-shim.h" #include "pthread-shim.h" #ifdef _WIN32 - +#ifdef HAVE_PTHREADS +int pthread_cond_timedwait_ms(pthread_cond_t *cond, pthread_mutex_t *mutex, uint32_t ms) +{ + timespec_t ts; + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t odd = (tv.tv_usec + (ms * 1000)) * 1000; + ts.tv_sec = tv.tv_sec + odd / 1000000000ULL; + ts.tv_nsec = odd % 1000000000ULL; + return pthread_cond_timedwait(cond, mutex, (const struct timespec *)&ts); +} +#else #include int pthread_create(pthread_t *thread, pthread_attr_t *attr, DWORD (__stdcall *start_routine)(LPVOID), void *arg) @@ -304,7 +315,7 @@ int sem_post(sem_t *sem) return 0; } } - +#endif #else #ifdef __APPLE__ diff --git a/contrib/pthread-shim.h b/contrib/pthread-shim.h index f4bcbf7121e493f2a8a8fdf8b60c5f71334e92e9..e596507fbb05b7ece777ecc8619fefd5ef9f33a3 100755 --- a/contrib/pthread-shim.h +++ b/contrib/pthread-shim.h @@ -14,7 +14,11 @@ #include //<-- not used here, but included because otherwise our order is broken. #define _WINSOCKAPI_ # include - +#ifdef HAVE_PTHREADS +#include +# define PTHREAD_START_FUNC(fname,aname) void *fname(void *aname) +RIST_PRIV int pthread_cond_timedwait_ms(pthread_cond_t *cond, pthread_mutex_t *mutex, uint32_t ms); +#else typedef CRITICAL_SECTION pthread_mutex_t; typedef void pthread_mutexattr_t; typedef void pthread_condattr_t; @@ -62,7 +66,7 @@ typedef HANDLE sem_t; RIST_PRIV int sem_init(sem_t *sem, int pshared, unsigned value); RIST_PRIV int sem_post(sem_t *sem); RIST_PRIV int sem_wait(sem_t *sem); - +#endif #else # include # include diff --git a/meson.build b/meson.build index e56fbef6be122254e81220dc927051203545ae6e..26a2e5131b78e9a1c6bf9b51180346c2e9cd60da 100755 --- a/meson.build +++ b/meson.build @@ -48,6 +48,9 @@ if host_machine.system() == 'windows' if get_option('default_library') != 'static' add_project_arguments(['-DLIBRIST_BUILDING_DLL'], language: 'c') endif + if get_option('have_mingw_pthreads') + cdata.set('HAVE_PTHREADS', 1) + endif add_project_arguments(['-DWIN32_LEAN_AND_MEAN'], language: 'c') add_project_arguments(['-D__USE_MINGW_ANSI_STDIO=1'], language: 'c') add_project_arguments(cc.get_supported_arguments(['-wd4996', '-wd4324']), language: 'c') diff --git a/meson_options.txt b/meson_options.txt index 55833e0d0e8ea5ece23610f79d8731c22f07172a..e74148372f5ac92d16183c33c469fa2f3d748623 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -5,4 +5,5 @@ option('builtin_cjson', type: 'boolean', value: false) option('builtin_mbedtls', type: 'boolean', value: false) option('built_tools', type: 'boolean', value: true) option('fallback_builtin', type: 'boolean', value: true) -option('use_mbedtls', type: 'boolean', value: true) \ No newline at end of file +option('use_mbedtls', type: 'boolean', value: true) +option('have_mingw_pthreads', type: 'boolean', value: false) \ No newline at end of file