Skip to content

[libc] remove redundant call_once #79226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2024
Merged

Conversation

nickdesaulniers
Copy link
Member

Missed cleanup from https://reviews.llvm.org/D134716.

Fixes: #79220

@llvmbot
Copy link
Member

llvmbot commented Jan 23, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

Changes

Missed cleanup from https://reviews.llvm.org/D134716.

Fixes: #79220


Full diff: https://github.com/llvm/llvm-project/pull/79226.diff

2 Files Affected:

  • (removed) libc/src/threads/linux/call_once.cpp (-67)
  • (removed) libc/src/threads/linux/thread_start_args.h.def (-11)
diff --git a/libc/src/threads/linux/call_once.cpp b/libc/src/threads/linux/call_once.cpp
deleted file mode 100644
index 5cdd8ebfd190ea..00000000000000
--- a/libc/src/threads/linux/call_once.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-//===-- Linux implementation of the call_once 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 "Futex.h"
-
-#include "src/__support/CPP/atomic.h"
-#include "src/__support/OSUtil/syscall.h" // For syscall functions.
-#include "src/__support/common.h"
-#include "src/threads/call_once.h"
-#include "src/threads/linux/Futex.h"
-
-#include <limits.h>
-#include <linux/futex.h>
-#include <sys/syscall.h> // For syscall numbers.
-#include <threads.h>     // For call_once related type definition.
-
-namespace LIBC_NAMESPACE {
-
-static constexpr FutexWordType START = 0x11;
-static constexpr FutexWordType WAITING = 0x22;
-static constexpr FutexWordType FINISH = 0x33;
-static constexpr once_flag ONCE_FLAG_INIT_VAL = ONCE_FLAG_INIT;
-
-LLVM_LIBC_FUNCTION(void, call_once,
-                   (once_flag * flag, __call_once_func_t func)) {
-  auto *futex_word = reinterpret_cast<cpp::Atomic<FutexWordType> *>(flag);
-  static_assert(sizeof(*futex_word) == sizeof(once_flag));
-
-  FutexWordType not_called = ONCE_FLAG_INIT_VAL.__word;
-
-  // The C standard wording says:
-  //
-  //     The completion of the function func synchronizes with all
-  //     previous or subsequent calls to call_once with the same
-  //     flag variable.
-  //
-  // What this means is that, the call_once call can return only after
-  // the called function |func| returns. So, we use futexes to synchronize
-  // calls with the same flag value.
-  if (futex_word->compare_exchange_strong(not_called, START)) {
-    func();
-    auto status = futex_word->exchange(FINISH);
-    if (status == WAITING) {
-      LIBC_NAMESPACE::syscall_impl(FUTEX_SYSCALL_ID, &futex_word->val,
-                                   FUTEX_WAKE_PRIVATE,
-                                   INT_MAX, // Wake all waiters.
-                                   0, 0, 0);
-    }
-    return;
-  }
-
-  FutexWordType status = START;
-  if (futex_word->compare_exchange_strong(status, WAITING) ||
-      status == WAITING) {
-    LIBC_NAMESPACE::syscall_impl(
-        FUTEX_SYSCALL_ID, &futex_word->val, FUTEX_WAIT_PRIVATE,
-        WAITING, // Block only if status is still |WAITING|.
-        0, 0, 0);
-  }
-}
-
-} // namespace LIBC_NAMESPACE
diff --git a/libc/src/threads/linux/thread_start_args.h.def b/libc/src/threads/linux/thread_start_args.h.def
deleted file mode 100644
index cc990a37548b6c..00000000000000
--- a/libc/src/threads/linux/thread_start_args.h.def
+++ /dev/null
@@ -1,11 +0,0 @@
-//===-- Implementation of the get_start_args_addr 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
-//
-//===----------------------------------------------------------------------===//
-
-#include <stdint.h>
-
-%%include_file(${thread_start_args})

@nickdesaulniers nickdesaulniers merged commit 6a3ace2 into llvm:main Jan 23, 2024
@nickdesaulniers nickdesaulniers deleted the call_once branch January 23, 2024 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc] deduplicate call_once
3 participants