summaryrefslogtreecommitdiff
path: root/libc/src/pthread/pthread_atfork.cpp
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2022-10-07 08:07:59 +0000
committerSiva Chandra Reddy <sivachandra@google.com>2022-10-10 18:28:43 +0000
commit438e59182b0c2e44c263f5bacc1add0e514354f8 (patch)
treec042e1d2d2cce75014ff7b65bc681269bfcdceb5 /libc/src/pthread/pthread_atfork.cpp
parentfaea104ef17b00d320017d2cd0d10a89277dc48a (diff)
[libc] Add implementation of pthread_atfork.
Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D135432
Diffstat (limited to 'libc/src/pthread/pthread_atfork.cpp')
-rw-r--r--libc/src/pthread/pthread_atfork.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/libc/src/pthread/pthread_atfork.cpp b/libc/src/pthread/pthread_atfork.cpp
new file mode 100644
index 000000000000..bff80d5fd456
--- /dev/null
+++ b/libc/src/pthread/pthread_atfork.cpp
@@ -0,0 +1,25 @@
+//===-- Linux implementation of the pthread_atfork 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 "pthread_atfork.h"
+
+#include "src/__support/common.h"
+#include "src/__support/fork_callbacks.h"
+
+#include <errno.h>
+#include <pthread.h> // For pthread_* type definitions.
+
+namespace __llvm_libc {
+
+LLVM_LIBC_FUNCTION(int, pthread_atfork,
+ (__atfork_callback_t prepare, __atfork_callback_t parent,
+ __atfork_callback_t child)) {
+ return register_atfork_callbacks(prepare, parent, child) ? 0 : ENOMEM;
+}
+
+} // namespace __llvm_libc