[libcxx-commits] [PATCH] D94909: [libc++][VE] Support futex system call on VE

Kazushi Marukawa via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 8 04:22:18 PST 2021


kaz7 updated this revision to Diff 392710.
kaz7 added a comment.

Modifies code following suggestions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94909/new/

https://reviews.llvm.org/D94909

Files:
  libcxx/src/atomic.cpp


Index: libcxx/src/atomic.cpp
===================================================================
--- libcxx/src/atomic.cpp
+++ libcxx/src/atomic.cpp
@@ -16,7 +16,9 @@
 #ifdef __linux__
 
 #include <unistd.h>
+#ifdef _LIBCPP_HAS_FUTEX_H
 #include <linux/futex.h>
+#endif
 #include <sys/syscall.h>
 
 // libc++ uses SYS_futex as a universal syscall name. However, on 32 bit architectures
@@ -39,13 +41,29 @@
                                               __cxx_contention_t __val)
 {
     static constexpr timespec __timeout = { 2, 0 };
+#ifdef _LIBCPP_HAS_FUTEX_H
     syscall(SYS_futex, __ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0);
+#elif defined(__ve__)
+    // VE doesn't distribute linux/futex.h but SYS_futex with
+    // FUTEX_WAIT_PRIVATE is implemented at 128.
+    syscall(SYS_futex, __ptr, 128, __val, &__timeout, 0, 0);
+#else
+#error libc++ requries linux/futex.h or special handling for __libcpp_platform_wait_on_address
+#endif
 }
 
 static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr,
                                               bool __notify_one)
 {
+#ifdef _LIBCPP_HAS_FUTEX_H
     syscall(SYS_futex, __ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0);
+#elif defined(__ve__)
+    // VE doesn't distribute linux/futex.h but SYS_futex with
+    // FUTEX_WAKE_PRIVATE is implemented at 129.
+    syscall(SYS_futex, __ptr, 129, __notify_one ? 1 : INT_MAX, 0, 0, 0);
+#else
+#error libc++ requries linux/futex.h or special handling for __libcpp_platform_wake_on_address
+#endif
 }
 
 #elif defined(__APPLE__) && defined(_LIBCPP_USE_ULOCK)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94909.392710.patch
Type: text/x-patch
Size: 1618 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211208/8a777b02/attachment-0001.bin>


More information about the libcxx-commits mailing list