[libc-commits] [libc] 4d25761 - [libc] move fork into threads folder

Michael Jones via libc-commits libc-commits at lists.llvm.org
Fri Nov 11 16:01:43 PST 2022


Author: Michael Jones
Date: 2022-11-11T16:01:39-08:00
New Revision: 4d25761b076d19c237890ad7b7331d01bd3a84b6

URL: https://github.com/llvm/llvm-project/commit/4d25761b076d19c237890ad7b7331d01bd3a84b6
DIFF: https://github.com/llvm/llvm-project/commit/4d25761b076d19c237890ad7b7331d01bd3a84b6.diff

LOG: [libc] move fork into threads folder

Fork, as a thread function, should go in the threads folder.
Additionally, it depends on the thread mutex, and it was causing build
issues for targets where we don't support threads.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D137867

Added: 
    libc/src/__support/threads/fork_callbacks.cpp
    libc/src/__support/threads/fork_callbacks.h

Modified: 
    libc/src/__support/CMakeLists.txt
    libc/src/__support/threads/CMakeLists.txt
    libc/src/pthread/CMakeLists.txt
    libc/src/pthread/pthread_atfork.cpp
    libc/src/unistd/linux/CMakeLists.txt
    libc/src/unistd/linux/fork.cpp

Removed: 
    libc/src/__support/fork_callbacks.cpp
    libc/src/__support/fork_callbacks.h


################################################################################
diff  --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index aebc9b4a2f89f..92a13d51a591c 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -85,15 +85,6 @@ add_header_library(
     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

diff  --git a/libc/src/__support/threads/CMakeLists.txt b/libc/src/__support/threads/CMakeLists.txt
index 5ef1cd3a5f16e..e71f436fe1751 100644
--- a/libc/src/__support/threads/CMakeLists.txt
+++ b/libc/src/__support/threads/CMakeLists.txt
@@ -16,6 +16,16 @@ if(TARGET libc.src.__support.threads.${LIBC_TARGET_OS}.mutex)
     DEPENDS
       .${LIBC_TARGET_OS}.mutex
   )
+
+  add_object_library(
+    fork_callbacks
+    SRCS
+      fork_callbacks.cpp
+    HDRS
+      fork_callbacks.h
+    DEPENDS
+      .mutex
+  )
 endif()
 
 add_header_library(

diff  --git a/libc/src/__support/fork_callbacks.cpp b/libc/src/__support/threads/fork_callbacks.cpp
similarity index 100%
rename from libc/src/__support/fork_callbacks.cpp
rename to libc/src/__support/threads/fork_callbacks.cpp

diff  --git a/libc/src/__support/fork_callbacks.h b/libc/src/__support/threads/fork_callbacks.h
similarity index 80%
rename from libc/src/__support/fork_callbacks.h
rename to libc/src/__support/threads/fork_callbacks.h
index ab43436c2c898..566290a788155 100644
--- a/libc/src/__support/fork_callbacks.h
+++ b/libc/src/__support/threads/fork_callbacks.h
@@ -6,6 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#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);
@@ -17,3 +20,5 @@ void invoke_parent_callbacks();
 void invoke_child_callbacks();
 
 } // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_THREAD_FORK_CALLBACKS_H

diff  --git a/libc/src/pthread/CMakeLists.txt b/libc/src/pthread/CMakeLists.txt
index f2d33b9b71019..ca5f45efc809b 100644
--- a/libc/src/pthread/CMakeLists.txt
+++ b/libc/src/pthread/CMakeLists.txt
@@ -407,5 +407,5 @@ add_entrypoint_object(
   DEPENDS
     libc.include.errno
     libc.include.pthread
-    libc.src.__support.fork_callbacks
+    libc.src.__support.threads.fork_callbacks
 )

diff  --git a/libc/src/pthread/pthread_atfork.cpp b/libc/src/pthread/pthread_atfork.cpp
index bff80d5fd4563..7136bf35816cb 100644
--- a/libc/src/pthread/pthread_atfork.cpp
+++ b/libc/src/pthread/pthread_atfork.cpp
@@ -9,7 +9,7 @@
 #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.

diff  --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 47382d2490c1c..e5ea13e776556 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -100,7 +100,7 @@ add_entrypoint_object(
     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

diff  --git a/libc/src/unistd/linux/fork.cpp b/libc/src/unistd/linux/fork.cpp
index 5c12fafd425ae..469c72e4ec3ea 100644
--- a/libc/src/unistd/linux/fork.cpp
+++ b/libc/src/unistd/linux/fork.cpp
@@ -10,7 +10,7 @@
 
 #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>


        


More information about the libc-commits mailing list