libc.src.errno.errno
)
-add_object_library(
- fork_callbacks
- SRCS
- fork_callbacks.cpp
- HDRS
- fork_callbacks.h
- DEPENDS
- .threads.mutex
-)
add_header_library(
integer_operations
+++ /dev/null
-//===-- Implementation of at-fork callback helpers -----------------------===//
-//
-// 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 "fork_callbacks.h"
-
-#include "src/__support/threads/mutex.h"
-
-#include <stddef.h> // For size_t
-
-namespace __llvm_libc {
-
-namespace {
-
-struct ForkCallbackTriple {
- ForkCallback *prepare = nullptr;
- ForkCallback *parent = nullptr;
- ForkCallback *child = nullptr;
- constexpr ForkCallbackTriple() = default;
-};
-
-class AtForkCallbackManager {
- static constexpr size_t CALLBACK_SIZE = 32;
- // TODO: Replace this with block store when integration tests
- // can use allocators.
- ForkCallbackTriple list[CALLBACK_SIZE];
- Mutex mtx;
- size_t next_index;
-
-public:
- constexpr AtForkCallbackManager() : mtx(false, false, false), next_index(0) {}
-
- bool register_triple(const ForkCallbackTriple &triple) {
- MutexLock lock(&mtx);
- if (next_index >= CALLBACK_SIZE)
- return false;
- list[next_index] = triple;
- ++next_index;
- return true;
- }
-
- void invoke_prepare() {
- MutexLock lock(&mtx);
- for (size_t i = 0; i < next_index; ++i) {
- auto prepare = list[i].prepare;
- if (prepare)
- prepare();
- }
- }
-
- void invoke_parent() {
- MutexLock lock(&mtx);
- for (size_t i = 0; i < next_index; ++i) {
- auto parent = list[i].parent;
- if (parent)
- parent();
- }
- }
-
- void invoke_child() {
- MutexLock lock(&mtx);
- for (size_t i = 0; i < next_index; ++i) {
- auto child = list[i].child;
- if (child)
- child();
- }
- }
-};
-
-AtForkCallbackManager cb_manager;
-
-} // Anonymous namespace
-
-bool register_atfork_callbacks(ForkCallback *prepare_cb,
- ForkCallback *parent_cb,
- ForkCallback *child_cb) {
- return cb_manager.register_triple({prepare_cb, parent_cb, child_cb});
-}
-
-void invoke_child_callbacks() { cb_manager.invoke_child(); }
-
-void invoke_prepare_callbacks() { cb_manager.invoke_prepare(); }
-
-void invoke_parent_callbacks() { cb_manager.invoke_parent(); }
-
-} // namespace __llvm_libc
+++ /dev/null
-//===-- At-fork callback helpers -------------------------------*- 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
-//
-//===----------------------------------------------------------------------===//
-
-namespace __llvm_libc {
-
-using ForkCallback = void(void);
-
-bool register_atfork_callbacks(ForkCallback *prepare_cd,
- ForkCallback *parent_cb, ForkCallback *child_cb);
-void invoke_prepare_callbacks();
-void invoke_parent_callbacks();
-void invoke_child_callbacks();
-
-} // namespace __llvm_libc
DEPENDS
.${LIBC_TARGET_OS}.mutex
)
+
+ add_object_library(
+ fork_callbacks
+ SRCS
+ fork_callbacks.cpp
+ HDRS
+ fork_callbacks.h
+ DEPENDS
+ .mutex
+ )
endif()
add_header_library(
--- /dev/null
+//===-- Implementation of at-fork callback helpers -----------------------===//
+//
+// 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 "fork_callbacks.h"
+
+#include "src/__support/threads/mutex.h"
+
+#include <stddef.h> // For size_t
+
+namespace __llvm_libc {
+
+namespace {
+
+struct ForkCallbackTriple {
+ ForkCallback *prepare = nullptr;
+ ForkCallback *parent = nullptr;
+ ForkCallback *child = nullptr;
+ constexpr ForkCallbackTriple() = default;
+};
+
+class AtForkCallbackManager {
+ static constexpr size_t CALLBACK_SIZE = 32;
+ // TODO: Replace this with block store when integration tests
+ // can use allocators.
+ ForkCallbackTriple list[CALLBACK_SIZE];
+ Mutex mtx;
+ size_t next_index;
+
+public:
+ constexpr AtForkCallbackManager() : mtx(false, false, false), next_index(0) {}
+
+ bool register_triple(const ForkCallbackTriple &triple) {
+ MutexLock lock(&mtx);
+ if (next_index >= CALLBACK_SIZE)
+ return false;
+ list[next_index] = triple;
+ ++next_index;
+ return true;
+ }
+
+ void invoke_prepare() {
+ MutexLock lock(&mtx);
+ for (size_t i = 0; i < next_index; ++i) {
+ auto prepare = list[i].prepare;
+ if (prepare)
+ prepare();
+ }
+ }
+
+ void invoke_parent() {
+ MutexLock lock(&mtx);
+ for (size_t i = 0; i < next_index; ++i) {
+ auto parent = list[i].parent;
+ if (parent)
+ parent();
+ }
+ }
+
+ void invoke_child() {
+ MutexLock lock(&mtx);
+ for (size_t i = 0; i < next_index; ++i) {
+ auto child = list[i].child;
+ if (child)
+ child();
+ }
+ }
+};
+
+AtForkCallbackManager cb_manager;
+
+} // Anonymous namespace
+
+bool register_atfork_callbacks(ForkCallback *prepare_cb,
+ ForkCallback *parent_cb,
+ ForkCallback *child_cb) {
+ return cb_manager.register_triple({prepare_cb, parent_cb, child_cb});
+}
+
+void invoke_child_callbacks() { cb_manager.invoke_child(); }
+
+void invoke_prepare_callbacks() { cb_manager.invoke_prepare(); }
+
+void invoke_parent_callbacks() { cb_manager.invoke_parent(); }
+
+} // namespace __llvm_libc
--- /dev/null
+//===-- At-fork callback helpers -------------------------------*- 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_SUPPORT_THREAD_FORK_CALLBACKS_H
+#define LLVM_LIBC_SRC_SUPPORT_THREAD_FORK_CALLBACKS_H
+
+namespace __llvm_libc {
+
+using ForkCallback = void(void);
+
+bool register_atfork_callbacks(ForkCallback *prepare_cd,
+ ForkCallback *parent_cb, ForkCallback *child_cb);
+void invoke_prepare_callbacks();
+void invoke_parent_callbacks();
+void invoke_child_callbacks();
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_THREAD_FORK_CALLBACKS_H
DEPENDS
libc.include.errno
libc.include.pthread
- libc.src.__support.fork_callbacks
+ libc.src.__support.threads.fork_callbacks
)
#include "pthread_atfork.h"
#include "src/__support/common.h"
-#include "src/__support/fork_callbacks.h"
+#include "src/__support/threads/fork_callbacks.h"
#include <errno.h>
#include <pthread.h> // For pthread_* type definitions.
libc.include.errno
libc.include.unistd
libc.include.sys_syscall
- libc.src.__support.fork_callbacks
+ libc.src.__support.threads.fork_callbacks
libc.src.__support.OSUtil.osutil
libc.src.__support.threads.thread
libc.src.errno.errno
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
-#include "src/__support/fork_callbacks.h"
+#include "src/__support/threads/fork_callbacks.h"
#include "src/__support/threads/thread.h" // For thread self object
#include <errno.h>