From 5b801efdb39be1af3ec9a50dac0e3c6994bf8847 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Fri, 7 Jan 2022 10:16:05 +0100 Subject: Use semtimedop() in NamedEvent::Wait() for platforms that support it --- zencore/thread.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'zencore/thread.cpp') 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 #include +#if ZEN_PLATFORM_LINUX +# if !defined(_GNU_SOURCE) +# define _GNU_SOURCE // for semtimedop() +# endif +#endif + #if ZEN_PLATFORM_WINDOWS # include # include @@ -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 } -- cgit v1.2.3