diff options
Diffstat (limited to 'zencore/thread.cpp')
| -rw-r--r-- | zencore/thread.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/zencore/thread.cpp b/zencore/thread.cpp index 063b060c9..f01cba7a8 100644 --- a/zencore/thread.cpp +++ b/zencore/thread.cpp @@ -8,6 +8,12 @@ #include <zencore/string.h> #include <zencore/testing.h> +#if ZEN_PLATFORM_LINUX +# if !defined(_GNU_SOURCE) +# define _GNU_SOURCE // for semtimedop() +# endif +#endif + #if ZEN_PLATFORM_WINDOWS # include <shellapi.h> # include <Shlobj.h> @@ -459,6 +465,14 @@ NamedEvent::Wait(int TimeoutMs) return Result == 0; } +#if defined(_GNU_SOURCE) + struct timespec TimeoutValue = { + .tv_sec = TimeoutMs >> 10, + .tv_nsec = (TimeoutMs & 0x3ff) << 20, + }; + int Result = semtimedop(Sem, &SemOp, 1, &TimeoutValue); + return Result == 0; +#else const int SleepTimeMs = 10; SemOp.sem_flg = IPC_NOWAIT; do @@ -475,6 +489,7 @@ NamedEvent::Wait(int TimeoutMs) while (TimeoutMs > 0); return Result == 0; +#endif // _GNU_SOURCE #endif } |