[libc-commits] [libc] c236b41 - [libc][NFC] Add the platform independent file target only if mutex is available.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Thu Mar 17 20:34:57 PDT 2022
Author: Siva Chandra Reddy
Date: 2022-03-18T03:34:38Z
New Revision: c236b41e451a4b25767ff16fcd025b05a4a8e0c4
URL: https://github.com/llvm/llvm-project/commit/c236b41e451a4b25767ff16fcd025b05a4a8e0c4
DIFF: https://github.com/llvm/llvm-project/commit/c236b41e451a4b25767ff16fcd025b05a4a8e0c4.diff
LOG: [libc][NFC] Add the platform independent file target only if mutex is available.
The platform independent file implementation is not an entrypoint so it
cannot be excluded via the entrypoints.txt file. Hence, we need a
special treatment to exclude it from the build.
Reviewed By: michaelrj
Differential Revision: https://reviews.llvm.org/D121947
Added:
libc/src/__support/threads/mutex_common.h
Modified:
libc/src/__support/CMakeLists.txt
libc/src/__support/File/CMakeLists.txt
libc/src/__support/threads/CMakeLists.txt
libc/src/__support/threads/linux/CMakeLists.txt
libc/src/__support/threads/linux/mutex.h
libc/src/__support/threads/mutex.h
libc/src/stdlib/CMakeLists.txt
libc/src/threads/CMakeLists.txt
libc/src/threads/linux/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 64837795196bd..8ac10d26ffca7 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -54,7 +54,10 @@ add_header_library(
integer_operations.h
)
+# Thread support is used by other support libraries. So, we add the "threads"
+# before other directories.
+add_subdirectory(threads)
+
add_subdirectory(File)
add_subdirectory(FPUtil)
add_subdirectory(OSUtil)
-add_subdirectory(threads)
diff --git a/libc/src/__support/File/CMakeLists.txt b/libc/src/__support/File/CMakeLists.txt
index 12403242a847f..e80eaa27a9109 100644
--- a/libc/src/__support/File/CMakeLists.txt
+++ b/libc/src/__support/File/CMakeLists.txt
@@ -1,3 +1,9 @@
+if(NOT (TARGET libc.src.__support.threads.mutex))
+ # Not all platforms have a mutex implementation. If mutex is unvailable,
+ # we just skip everything about files.
+ return()
+endif()
+
add_object_library(
file
SRCS
@@ -5,7 +11,7 @@ add_object_library(
HDRS
file.h
DEPENDS
- libc.src.__support.threads.thread
+ libc.src.__support.threads.mutex
libc.include.errno
libc.src.errno.errno
)
diff --git a/libc/src/__support/threads/CMakeLists.txt b/libc/src/__support/threads/CMakeLists.txt
index a2792c3475dd1..6ded0da525a40 100644
--- a/libc/src/__support/threads/CMakeLists.txt
+++ b/libc/src/__support/threads/CMakeLists.txt
@@ -1,11 +1,19 @@
+add_header_library(
+ mutex_common
+ HDRS
+ mutex_common.h
+)
+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
add_subdirectory(${LIBC_TARGET_OS})
endif()
-add_header_library(
- thread
- HDRS
- mutex.h
- DEPENDS
- .${LIBC_TARGET_OS}.thread
-)
+if(TARGET libc.src.__support.threads.${LIBC_TARGET_OS}.mutex)
+ add_header_library(
+ mutex
+ HDRS
+ mutex.h
+ DEPENDS
+ .${LIBC_TARGET_OS}.mutex
+ )
+endif()
diff --git a/libc/src/__support/threads/linux/CMakeLists.txt b/libc/src/__support/threads/linux/CMakeLists.txt
index 53a150a05d2d7..5dd154d53e897 100644
--- a/libc/src/__support/threads/linux/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/CMakeLists.txt
@@ -1,9 +1,10 @@
add_header_library(
- thread
+ mutex
HDRS
mutex.h
DEPENDS
libc.include.sys_syscall
libc.src.__support.CPP.atomic
libc.src.__support.OSUtil.osutil
+ libc.src.__support.threads.mutex_common
)
diff --git a/libc/src/__support/threads/linux/mutex.h b/libc/src/__support/threads/linux/mutex.h
index e4e06e99b5eb2..5926fd96e45f1 100644
--- a/libc/src/__support/threads/linux/mutex.h
+++ b/libc/src/__support/threads/linux/mutex.h
@@ -11,7 +11,7 @@
#include "src/__support/CPP/atomic.h"
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
-#include "src/__support/threads/mutex.h"
+#include "src/__support/threads/mutex_common.h"
#include <linux/futex.h>
#include <stdint.h>
diff --git a/libc/src/__support/threads/mutex.h b/libc/src/__support/threads/mutex.h
index f585dcd1c32fa..1015333b677a9 100644
--- a/libc/src/__support/threads/mutex.h
+++ b/libc/src/__support/threads/mutex.h
@@ -9,18 +9,6 @@
#ifndef LLVM_LIBC_SRC_SUPPORT_THREAD_MUTEX_H
#define LLVM_LIBC_SRC_SUPPORT_THREAD_MUTEX_H
-namespace __llvm_libc {
-
-enum class MutexError : int {
- NONE,
- BUSY,
- TIMEOUT,
- UNLOCK_WITHOUT_LOCK,
- BAD_LOCK_STATE,
-};
-
-} // namespace __llvm_libc
-
// Platform independent code will include this header file which pulls
// the platfrom specific specializations using platform macros.
//
diff --git a/libc/src/__support/threads/mutex_common.h b/libc/src/__support/threads/mutex_common.h
new file mode 100644
index 0000000000000..2fde20a3fe828
--- /dev/null
+++ b/libc/src/__support/threads/mutex_common.h
@@ -0,0 +1,24 @@
+//===--- Common definitions useful for mutex implementations ----*- 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_MUTEX_COMMON_H
+#define LLVM_LIBC_SRC_SUPPORT_THREAD_MUTEX_COMMON_H
+
+namespace __llvm_libc {
+
+enum class MutexError : int {
+ NONE,
+ BUSY,
+ TIMEOUT,
+ UNLOCK_WITHOUT_LOCK,
+ BAD_LOCK_STATE,
+};
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_THREAD_MUTEX_COMMON_H
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index e1bf45f5a3bb5..77a407347542b 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -280,7 +280,7 @@ add_entrypoint_object(
20 # For constinit of the atexit callback list.
DEPENDS
libc.src.__support.CPP.blockstore
- libc.src.__support.threads.thread
+ libc.src.__support.threads.mutex
)
add_entrypoint_object(
diff --git a/libc/src/threads/CMakeLists.txt b/libc/src/threads/CMakeLists.txt
index 2a4f04debce55..a02fc161ecc5c 100644
--- a/libc/src/threads/CMakeLists.txt
+++ b/libc/src/threads/CMakeLists.txt
@@ -31,7 +31,7 @@ add_entrypoint_object(
mtx_init.h
DEPENDS
libc.include.threads
- libc.src.__support.threads.thread
+ libc.src.__support.threads.mutex
)
add_entrypoint_object(
@@ -42,7 +42,7 @@ add_entrypoint_object(
mtx_destroy.h
DEPENDS
libc.include.threads
- libc.src.__support.threads.thread
+ libc.src.__support.threads.mutex
)
add_entrypoint_object(
@@ -53,7 +53,7 @@ add_entrypoint_object(
mtx_lock.h
DEPENDS
libc.include.threads
- libc.src.__support.threads.thread
+ libc.src.__support.threads.mutex
)
add_entrypoint_object(
@@ -64,7 +64,7 @@ add_entrypoint_object(
mtx_unlock.h
DEPENDS
libc.include.threads
- libc.src.__support.threads.thread
+ libc.src.__support.threads.mutex
)
add_entrypoint_object(
diff --git a/libc/src/threads/linux/CMakeLists.txt b/libc/src/threads/linux/CMakeLists.txt
index 5ca715b3c6a55..6706c422934bc 100644
--- a/libc/src/threads/linux/CMakeLists.txt
+++ b/libc/src/threads/linux/CMakeLists.txt
@@ -34,7 +34,7 @@ add_header_library(
libc.include.threads
libc.src.__support.CPP.atomic
libc.src.__support.OSUtil.osutil
- libc.src.__support.threads.thread
+ libc.src.__support.threads.mutex
)
add_entrypoint_object(
@@ -105,7 +105,7 @@ add_entrypoint_object(
DEPENDS
.threads_utils
libc.include.threads
- libc.src.__support.threads.thread
+ libc.src.__support.threads.mutex
)
add_entrypoint_object(
More information about the libc-commits
mailing list