aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/threading/futex.cpp
diff options
context:
space:
mode:
authormonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
committermonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
commit06e5c21a835c0e923506c4ff27929f34e00761c2 (patch)
tree75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/yt/threading/futex.cpp
parent03f024c4412e3aa613bb543cf1660176320ba8f4 (diff)
downloadydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz
fix ya.make
Diffstat (limited to 'library/cpp/yt/threading/futex.cpp')
-rw-r--r--library/cpp/yt/threading/futex.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/library/cpp/yt/threading/futex.cpp b/library/cpp/yt/threading/futex.cpp
new file mode 100644
index 0000000000..c33a054ef0
--- /dev/null
+++ b/library/cpp/yt/threading/futex.cpp
@@ -0,0 +1,63 @@
+#include "futex.h"
+
+#ifdef _linux_
+ #include <linux/futex.h>
+
+ #include <sys/time.h>
+ #include <sys/syscall.h>
+#endif
+
+namespace NYT::NThreading {
+
+////////////////////////////////////////////////////////////////////////////////
+
+#ifdef _linux_
+
+namespace {
+
+int Futex(
+ int* uaddr,
+ int op,
+ int val,
+ const timespec* timeout,
+ int* uaddr2,
+ int val3)
+{
+ return ::syscall(SYS_futex, uaddr, op, val, timeout, uaddr2, val3);
+}
+
+} // namespace
+
+int FutexWait(int* addr, int value, TDuration timeout)
+{
+ struct timespec timeoutSpec;
+ if (timeout != TDuration::Max()) {
+ timeoutSpec.tv_sec = timeout.Seconds();
+ timeoutSpec.tv_nsec = (timeout - TDuration::Seconds(timeout.Seconds())).MicroSeconds() * 1000;
+ }
+
+ return Futex(
+ addr,
+ FUTEX_WAIT_PRIVATE,
+ value,
+ timeout != TDuration::Max() ? &timeoutSpec : nullptr,
+ nullptr,
+ 0);
+}
+
+int FutexWake(int* addr, int count)
+{
+ return Futex(
+ addr,
+ FUTEX_WAKE_PRIVATE,
+ count,
+ nullptr,
+ nullptr,
+ 0);
+}
+
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NThreading