aboutsummaryrefslogtreecommitdiff
path: root/zencore/thread.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2022-01-07 10:16:05 +0100
committerMartin Ridgers <[email protected]>2022-01-07 10:20:37 +0100
commit5b801efdb39be1af3ec9a50dac0e3c6994bf8847 (patch)
tree773326c07fb11556d90fb8f5868d5be03e546a39 /zencore/thread.cpp
parentImplemented NamedEvents on Mac using System V semaphores (diff)
downloadzen-5b801efdb39be1af3ec9a50dac0e3c6994bf8847.tar.xz
zen-5b801efdb39be1af3ec9a50dac0e3c6994bf8847.zip
Use semtimedop() in NamedEvent::Wait() for platforms that support it
Diffstat (limited to 'zencore/thread.cpp')
-rw-r--r--zencore/thread.cpp15
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
}