[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
Fri Dec 3 22:04:32 PST 2021


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

Fix typo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94909

Files:
  libcxx/CMakeLists.txt
  libcxx/cmake/config-ix.cmake
  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)
Index: libcxx/cmake/config-ix.cmake
===================================================================
--- libcxx/cmake/config-ix.cmake
+++ libcxx/cmake/config-ix.cmake
@@ -3,6 +3,7 @@
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
 include(CheckCSourceCompiles)
+include(CheckIncludeFiles)
 
 if(WIN32 AND NOT MINGW)
   # NOTE(compnerd) this is technically a lie, there is msvcrt, but for now, lets
@@ -24,6 +25,10 @@
   endif()
 endif()
 
+# libc++ is using linux/futex.h for linux platform.  So, check it and pass
+# it to compiler later.
+check_include_files(linux/futex.h LIBCXX_HAS_FUTEX_H)
+
 # libc++ is using -nostdlib++ at the link step when available,
 # otherwise -nodefaultlibs is used. We want all our checks to also
 # use one of these options, otherwise we may end up with an inconsistency between
Index: libcxx/CMakeLists.txt
===================================================================
--- libcxx/CMakeLists.txt
+++ libcxx/CMakeLists.txt
@@ -582,6 +582,11 @@
       target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB)
     endif()
   endif()
+
+  if (LIBCXX_HAS_FUTEX_H)
+    # This tells compiler about the availability of linux/futex.h
+    target_compile_definitions(${target} PRIVATE -D_LIBCPP_HAS_FUTEX_H)
+  endif()
 endfunction()
 
 # Warning flags ===============================================================


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94909.391812.patch
Type: text/x-patch
Size: 2993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211204/79461a1a/attachment-0001.bin>


More information about the libcxx-commits mailing list