[libc]Revert "Add linux implementations of thrd_create and thrd_join functions."
authorSiva Chandra Reddy <sivachandra@google.com>
Fri, 6 Mar 2020 04:46:13 +0000 (20:46 -0800)
committerSiva Chandra Reddy <sivachandra@google.com>
Fri, 6 Mar 2020 04:46:13 +0000 (20:46 -0800)
This reverts commit abc040e9533011a62a25c93b07b4fc31c8a641f7 as the bots
are failing because of this.

16 files changed:
libc/config/linux/api.td
libc/config/linux/threads.h.in [deleted file]
libc/include/CMakeLists.txt
libc/include/threads.h.def
libc/lib/CMakeLists.txt
libc/src/CMakeLists.txt
libc/src/threads/CMakeLists.txt [deleted file]
libc/src/threads/linux/CMakeLists.txt [deleted file]
libc/src/threads/linux/thrd_create.cpp [deleted file]
libc/src/threads/linux/thrd_join.cpp [deleted file]
libc/src/threads/linux/thread_utils.h [deleted file]
libc/src/threads/thrd_create.h [deleted file]
libc/src/threads/thrd_join.h [deleted file]
libc/test/src/CMakeLists.txt
libc/test/src/threads/CMakeLists.txt [deleted file]
libc/test/src/threads/thrd_test.cpp [deleted file]

index 2f9a840..1c9fa8a 100644 (file)
@@ -150,15 +150,7 @@ def SignalAPI : PublicAPI<"signal.h"> {
   ];
 }
 
-def ThreadStartT : TypeDecl<"thrd_start_t"> {
-  let Decl = "typedef int (*thrd_start_t)(void *);";
-}
-
 def ThreadsAPI : PublicAPI<"threads.h"> {
-  let TypeDeclarations = [
-    ThreadStartT,
-  ];
-
   let Enumerations = [
     "mtx_plain",
     "mtx_recursive",
@@ -169,9 +161,4 @@ def ThreadsAPI : PublicAPI<"threads.h"> {
     "thrd_error",
     "thrd_nomem",
   ];
-
-  let Functions = [
-    "thrd_create",
-    "thrd_join",
-  ];
 }
diff --git a/libc/config/linux/threads.h.in b/libc/config/linux/threads.h.in
deleted file mode 100644 (file)
index 58f58a3..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-//===--------- Linux specific definitions of types from threads.h ---------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-%%begin()
-
-typedef struct {
-  unsigned char __clear_tid[4];
-  int __tid;
-  void *__stack;
-  int __stack_size;
-  int __retval;
-} thrd_t;
index bbc41b0..db5f371 100644 (file)
@@ -39,12 +39,8 @@ add_gen_header(
   threads_h
   DEF_FILE threads.h.def
   GEN_HDR threads.h
-  PARAMS
-    platform_threads=../config/${LIBC_TARGET_OS}/threads.h.in
   DEPENDS
     llvm_libc_common_h
-  DATA_FILES
-    ../config/${LIBC_TARGET_OS}/threads.h.in
 )
 
 add_gen_header(
index e99fcfc..276f78b 100644 (file)
@@ -11,8 +11,6 @@
 
 #include <__llvm-libc-common.h>
 
-%%include_file(${platform_threads})
-
 %%public_api()
 
 #endif // LLVM_LIBC_THREADS_H
index 83b19fd..b67f8e4 100644 (file)
@@ -22,10 +22,6 @@ add_entrypoint_library(
     # stdlib.h entrypoints
     _Exit
     abort
-
-    # threads.h entrypoints
-    thrd_create
-    thrd_join
 )
 
 add_entrypoint_library(
index 4e661c8..7f8ef92 100644 (file)
@@ -5,6 +5,5 @@ add_subdirectory(stdlib)
 add_subdirectory(string)
 # TODO: Add this target conditional to the target OS.
 add_subdirectory(sys)
-add_subdirectory(threads)
 
 add_subdirectory(__support)
diff --git a/libc/src/threads/CMakeLists.txt b/libc/src/threads/CMakeLists.txt
deleted file mode 100644 (file)
index b4bbe81..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
-  add_subdirectory(${LIBC_TARGET_OS})
-endif()
diff --git a/libc/src/threads/linux/CMakeLists.txt b/libc/src/threads/linux/CMakeLists.txt
deleted file mode 100644 (file)
index 809a365..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-add_header_library(
-  threads_utils
-  HDRS
-    thread_utils.h
-)
-
-add_entrypoint_object(
-  thrd_create
-  SRCS
-    thrd_create.cpp
-  HDRS
-    ../thrd_create.h
-  DEPENDS
-    errno_h
-    linux_syscall_h
-    mmap
-    support_common_h
-    sys_syscall_h
-    threads_h
-    threads_utils
-    __errno_location
-)
-
-add_entrypoint_object(
-  thrd_join
-  SRCS
-    thrd_join.cpp
-  HDRS
-    ../thrd_join.h
-  DEPENDS
-    linux_syscall_h
-    munmap
-    support_common_h
-    sys_syscall_h
-    threads_h
-    threads_utils
-)
diff --git a/libc/src/threads/linux/thrd_create.cpp b/libc/src/threads/linux/thrd_create.cpp
deleted file mode 100644 (file)
index 650c38c..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-//===---------- Linux implementation of the thrd_create function ----------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "config/linux/syscall.h" // For syscall function.
-#include "include/errno.h"        // For E* error values.
-#include "include/sys/mman.h"     // For PROT_* and MAP_* definitions.
-#include "include/sys/syscall.h"  // For syscall numbers.
-#include "include/threads.h"      // For thrd_* type definitions.
-#include "src/__support/common.h"
-#include "src/errno/llvmlibc_errno.h"
-#include "src/sys/mman/mmap.h"
-#include "src/sys/mman/munmap.h"
-#include "src/threads/linux/thread_utils.h"
-
-#include <linux/futex.h> // For futex operations.
-#include <linux/sched.h> // For CLONE_* flags.
-#include <stdint.h>
-
-namespace __llvm_libc {
-
-static void start_thread(thrd_t *thread, thrd_start_t func, void *arg) {
-  __llvm_libc::syscall(SYS_exit, thread->__retval = func(arg));
-}
-
-int LLVM_LIBC_ENTRYPOINT(thrd_create)(thrd_t *thread, thrd_start_t func,
-                                      void *arg) {
-  unsigned clone_flags =
-      CLONE_VM        // Share the memory space with the parent.
-      | CLONE_FS      // Share the file system with the parent.
-      | CLONE_FILES   // Share the files with the parent.
-      | CLONE_SIGHAND // Share the signal handlers with the parent.
-      | CLONE_THREAD  // Same thread group as the parent.
-      | CLONE_SYSVSEM // Share a single list of System V semaphore adjustment
-                      // values
-      | CLONE_PARENT_SETTID   // Set child thread ID in |ptid| of the parent.
-      | CLONE_CHILD_CLEARTID; // Let the kernel clear the tid address and futex
-                              // wake the joining thread.
-  // TODO: Add the CLONE_SETTLS flag and setup the TLS area correctly when
-  // making the clone syscall.
-
-  void *stack = __llvm_libc::mmap(nullptr, ThreadParams::DefaultStackSize,
-                                  PROT_READ | PROT_WRITE,
-                                  MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
-  if (stack == MAP_FAILED)
-    return llvmlibc_errno == ENOMEM ? thrd_nomem : thrd_error;
-
-  thread->__stack = stack;
-  thread->__stack_size = ThreadParams::DefaultStackSize;
-  thread->__retval = -1;
-  FutexData *clear_tid_address =
-      reinterpret_cast<FutexData *>(thread->__clear_tid);
-  *clear_tid_address = ThreadParams::ClearTIDValue;
-
-  long clone_result = __llvm_libc::syscall(
-      SYS_clone, clone_flags,
-      reinterpret_cast<uintptr_t>(stack) + ThreadParams::DefaultStackSize - 1,
-      &thread->__tid, clear_tid_address, 0);
-
-  if (clone_result == 0) {
-    start_thread(thread, func, arg);
-  } else if (clone_result < 0) {
-    int error_val = -clone_result;
-    return error_val == ENOMEM ? thrd_nomem : thrd_error;
-  }
-
-  return thrd_success;
-}
-
-} // namespace __llvm_libc
diff --git a/libc/src/threads/linux/thrd_join.cpp b/libc/src/threads/linux/thrd_join.cpp
deleted file mode 100644 (file)
index 7237354..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-//===----------- Linux implementation of the thrd_join function -----------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "config/linux/syscall.h" // For syscall function.
-#include "include/sys/syscall.h"  // For syscall numbers.
-#include "include/threads.h"      // For thrd_* type definitions.
-#include "src/__support/common.h"
-#include "src/sys/mman/munmap.h"
-#include "src/threads/linux/thread_utils.h"
-
-#include <linux/futex.h> // For futex operations.
-#include <stdatomic.h>   // For atomic_load.
-
-namespace __llvm_libc {
-
-int LLVM_LIBC_ENTRYPOINT(thrd_join)(thrd_t *thread, int *retval) {
-  FutexData *clear_tid_address =
-      reinterpret_cast<FutexData *>(thread->__clear_tid);
-
-  while (atomic_load(clear_tid_address) != 0) {
-    // We cannot do a FUTEX_WAIT_PRIVATE here as the kernel does a
-    // FUTEX_WAKE and not a FUTEX_WAKE_PRIVATE.
-    __llvm_libc::syscall(SYS_futex, clear_tid_address, FUTEX_WAIT,
-                         ThreadParams::ClearTIDValue, nullptr);
-
-    // The kernel should set the value at the clear tid address to zero.
-    // If not, it is a spurious wake and we should continue to wait on
-    // the futex.
-  }
-
-  *retval = thread->__retval;
-
-  if (__llvm_libc::munmap(thread->__stack, thread->__stack_size) == -1)
-    return thrd_error;
-
-  return thrd_success;
-}
-
-} // namespace __llvm_libc
diff --git a/libc/src/threads/linux/thread_utils.h b/libc/src/threads/linux/thread_utils.h
deleted file mode 100644 (file)
index b6f41b4..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-//===--- Linux specific definitions to support mutex operations --*- C++ -*===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC_THREADS_LINUX_THREAD_UTILS_H
-#define LLVM_LIBC_SRC_THREADS_LINUX_THREAD_UTILS_H
-
-#include <stdint.h>
-
-using FutexData = _Atomic uint32_t;
-
-struct ThreadParams {
-  static constexpr uintptr_t DefaultStackSize = 1 << 15; // 32 KB
-  static constexpr uint32_t ClearTIDValue = 0xABCD1234;
-};
-
-#endif // LLVM_LIBC_SRC_THREADS_LINUX_THREAD_UTILS_H
diff --git a/libc/src/threads/thrd_create.h b/libc/src/threads/thrd_create.h
deleted file mode 100644 (file)
index 3119290..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-//===------- Implementation header for thrd_create function ------ *-C++-* ===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC_THREADS_LINUX_THRD_CREATE_H
-#define LLVM_LIBC_SRC_THREADS_LINUX_THRD_CREATE_H
-
-#include "include/threads.h"
-
-namespace __llvm_libc {
-
-int thrd_create(thrd_t *thread, thrd_start_t func, void *arg);
-
-} // namespace __llvm_libc
-
-#endif // LLVM_LIBC_SRC_THREADS_LINUX_THRD_CREATE_H
diff --git a/libc/src/threads/thrd_join.h b/libc/src/threads/thrd_join.h
deleted file mode 100644 (file)
index 495b049..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-------- Implementation header for thrd_join function ------- *-C++-* ===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC_THREADS_LINUX_THRD_JOIN_H
-#define LLVM_LIBC_SRC_THREADS_LINUX_THRD_JOIN_H
-
-#include "include/threads.h"
-
-namespace __llvm_libc {
-
-int thrd_join(thrd_t *thread, int *retval);
-
-} // namespace __llvm_libc
-
-#endif // LLVM_LIBC_SRC_THREADS_LINUX_THRD_JOIN_H
index 2ff4ca4..bf56591 100644 (file)
@@ -3,4 +3,3 @@ add_subdirectory(signal)
 add_subdirectory(stdlib)
 add_subdirectory(string)
 add_subdirectory(sys)
-add_subdirectory(threads)
diff --git a/libc/test/src/threads/CMakeLists.txt b/libc/test/src/threads/CMakeLists.txt
deleted file mode 100644 (file)
index 9607a25..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-add_libc_testsuite(libc_threads_unittests)
-
-add_libc_unittest(
-  thrd_test
-  SUITE
-    libc_threads_unittests
-  SRCS
-    thrd_test.cpp
-  DEPENDS
-    __errno_location
-    mmap
-    munmap
-    threads_h
-    thrd_create
-    thrd_join
-)
diff --git a/libc/test/src/threads/thrd_test.cpp b/libc/test/src/threads/thrd_test.cpp
deleted file mode 100644 (file)
index be9e410..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-//===---------------------- Unittests for thrd_t --------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "include/threads.h"
-#include "src/threads/thrd_create.h"
-#include "src/threads/thrd_join.h"
-#include "utils/UnitTest/Test.h"
-
-static constexpr int thread_count = 1000;
-static int counter = 0;
-static int thread_func(void *) {
-  ++counter;
-  return 0;
-}
-
-TEST(ThreadTest, CreateAndJoin) {
-  for (counter = 0; counter <= thread_count;) {
-    thrd_t thread;
-    int old_counter_val = counter;
-    ASSERT_EQ(__llvm_libc::thrd_create(&thread, thread_func, nullptr),
-              (int)thrd_success);
-    int retval = thread_count + 1; // Start with a retval we dont expect.
-    ASSERT_EQ(__llvm_libc::thrd_join(&thread, &retval), (int)thrd_success);
-    ASSERT_EQ(retval, 0);
-    ASSERT_EQ(counter, old_counter_val + 1);
-  }
-}
-
-static int return_arg(void *arg) { return *reinterpret_cast<int *>(arg); }
-
-TEST(ThreadTest, SpawnAndJoin) {
-  thrd_t thread_list[thread_count];
-  int args[thread_count];
-
-  for (int i = 0; i < thread_count; ++i) {
-    args[i] = i;
-    ASSERT_EQ(__llvm_libc::thrd_create(thread_list + i, return_arg, args + i),
-              (int)thrd_success);
-  }
-
-  for (int i = 0; i < thread_count; ++i) {
-    int retval = thread_count + 1; // Start with a retval we dont expect.
-    ASSERT_EQ(__llvm_libc::thrd_join(&thread_list[i], &retval),
-              (int)thrd_success);
-    ASSERT_EQ(retval, i);
-  }
-}