[libc-commits] [libc] 2a5420e - [libc] move abs_timesout and monotonicity out of linux dir (#167719)
via libc-commits
libc-commits at lists.llvm.org
Mon Dec 8 08:44:16 PST 2025
Author: Shreeyash Pandey
Date: 2025-12-08T22:14:12+05:30
New Revision: 2a5420ea5184a334c2af9f2f9f43de4dfc6b76d3
URL: https://github.com/llvm/llvm-project/commit/2a5420ea5184a334c2af9f2f9f43de4dfc6b76d3
DIFF: https://github.com/llvm/llvm-project/commit/2a5420ea5184a334c2af9f2f9f43de4dfc6b76d3.diff
LOG: [libc] move abs_timesout and monotonicity out of linux dir (#167719)
This patch moves abs_timeout and monotonicity out of the linux dir into
common. Both of these functions depend on clock_gettime which is the
actual os-dependent component. As other features in `__support/threads`
may want to use these, it's better to share it in common.
Added:
libc/src/__support/time/abs_timeout.h
libc/src/__support/time/monotonicity.h
Modified:
libc/hdr/errno_macros.h
libc/include/errno.h.def
libc/src/__support/threads/linux/CMakeLists.txt
libc/src/__support/threads/linux/futex_utils.h
libc/src/__support/threads/linux/raw_mutex.h
libc/src/__support/threads/linux/rwlock.h
libc/src/__support/time/CMakeLists.txt
libc/src/__support/time/linux/CMakeLists.txt
libc/src/pthread/pthread_rwlock_clockwrlock.cpp
libc/src/pthread/pthread_rwlock_timedrdlock.cpp
libc/src/pthread/pthread_rwlock_timedwrlock.cpp
libc/test/src/__support/time/linux/CMakeLists.txt
libc/test/src/__support/time/linux/timeout_test.cpp
Removed:
libc/src/__support/time/linux/abs_timeout.h
libc/src/__support/time/linux/monotonicity.h
################################################################################
diff --git a/libc/hdr/errno_macros.h b/libc/hdr/errno_macros.h
index 27ea49977d8c8..e2913f45a8ad9 100644
--- a/libc/hdr/errno_macros.h
+++ b/libc/hdr/errno_macros.h
@@ -15,7 +15,9 @@
#include <linux/errno.h>
#include "include/llvm-libc-macros/error-number-macros.h"
-#else // __linux__
+#elif defined(__APPLE__)
+#include <sys/errno.h>
+#else // __APPLE__
#include "include/llvm-libc-macros/generic-error-number-macros.h"
#endif
diff --git a/libc/include/errno.h.def b/libc/include/errno.h.def
index aa1f6c9e48444..0ac8e57f7a158 100644
--- a/libc/include/errno.h.def
+++ b/libc/include/errno.h.def
@@ -21,8 +21,14 @@
#include "llvm-libc-macros/linux/error-number-macros.h"
-#else // __linux__
+#elif defined(__APPLE__)
+
+#include <sys/errno.h>
+
+#else // __APPLE__
+
#include "llvm-libc-macros/generic-error-number-macros.h"
+
#endif
__BEGIN_C_DECLS
diff --git a/libc/src/__support/threads/linux/CMakeLists.txt b/libc/src/__support/threads/linux/CMakeLists.txt
index 39d2c6fef0fed..cc596d217d7d2 100644
--- a/libc/src/__support/threads/linux/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/CMakeLists.txt
@@ -21,7 +21,7 @@ add_header_library(
libc.src.__support.CPP.atomic
libc.src.__support.CPP.limits
libc.src.__support.CPP.optional
- libc.src.__support.time.linux.abs_timeout
+ libc.src.__support.time.abs_timeout
)
set(monotonicity_flags)
@@ -38,8 +38,8 @@ add_header_library(
DEPENDS
.futex_utils
libc.src.__support.threads.sleep
- libc.src.__support.time.linux.abs_timeout
- libc.src.__support.time.linux.monotonicity
+ libc.src.__support.time.abs_timeout
+ libc.src.__support.time.monotonicity
libc.src.__support.CPP.optional
libc.hdr.types.pid_t
COMPILE_OPTIONS
diff --git a/libc/src/__support/threads/linux/futex_utils.h b/libc/src/__support/threads/linux/futex_utils.h
index 943a99ab38c8c..e1cfa36566555 100644
--- a/libc/src/__support/threads/linux/futex_utils.h
+++ b/libc/src/__support/threads/linux/futex_utils.h
@@ -16,7 +16,7 @@
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#include "src/__support/threads/linux/futex_word.h"
-#include "src/__support/time/linux/abs_timeout.h"
+#include "src/__support/time/abs_timeout.h"
#include <linux/errno.h>
#include <linux/futex.h>
diff --git a/libc/src/__support/threads/linux/raw_mutex.h b/libc/src/__support/threads/linux/raw_mutex.h
index 47f0aa70f1c46..94d6129bbf69b 100644
--- a/libc/src/__support/threads/linux/raw_mutex.h
+++ b/libc/src/__support/threads/linux/raw_mutex.h
@@ -17,14 +17,14 @@
#include "src/__support/threads/linux/futex_utils.h"
#include "src/__support/threads/linux/futex_word.h"
#include "src/__support/threads/sleep.h"
-#include "src/__support/time/linux/abs_timeout.h"
+#include "src/__support/time/abs_timeout.h"
#ifndef LIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY
#define LIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY 1
#endif
#if LIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY
-#include "src/__support/time/linux/monotonicity.h"
+#include "src/__support/time/monotonicity.h"
#endif
#ifndef LIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT
diff --git a/libc/src/__support/threads/linux/rwlock.h b/libc/src/__support/threads/linux/rwlock.h
index f7aeb5b709aa3..165e17239bbd5 100644
--- a/libc/src/__support/threads/linux/rwlock.h
+++ b/libc/src/__support/threads/linux/rwlock.h
@@ -35,7 +35,7 @@
#endif
#if LIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY
-#include "src/__support/time/linux/monotonicity.h"
+#include "src/__support/time/monotonicity.h"
#endif
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/__support/time/CMakeLists.txt b/libc/src/__support/time/CMakeLists.txt
index dcb5d40ae7fb2..3cc3fd873220a 100644
--- a/libc/src/__support/time/CMakeLists.txt
+++ b/libc/src/__support/time/CMakeLists.txt
@@ -37,3 +37,23 @@ if(TARGET libc.src.__support.time.${LIBC_TARGET_OS}.clock_settime)
libc.src.__support.time.${LIBC_TARGET_OS}.clock_settime
)
endif()
+
+add_header_library(
+ abs_timeout
+ HDRS
+ abs_timeout.h
+ DEPENDS
+ libc.hdr.types.struct_timespec
+ libc.src.__support.time.units
+ libc.src.__support.CPP.expected
+)
+
+add_header_library(
+ monotonicity
+ HDRS
+ monotonicity.h
+ DEPENDS
+ .clock_conversion
+ .abs_timeout
+ libc.hdr.time_macros
+)
diff --git a/libc/src/__support/time/linux/abs_timeout.h b/libc/src/__support/time/abs_timeout.h
similarity index 87%
rename from libc/src/__support/time/linux/abs_timeout.h
rename to libc/src/__support/time/abs_timeout.h
index 37e602672208f..23ac23dd864c8 100644
--- a/libc/src/__support/time/linux/abs_timeout.h
+++ b/libc/src/__support/time/abs_timeout.h
@@ -1,4 +1,4 @@
-//===--- Linux absolute timeout ---------------------------------*- C++ -*-===//
+//===--- absolute timeout ---------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_ABS_TIMEOUT_H
-#define LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_ABS_TIMEOUT_H
+#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_ABS_TIMEOUT_H
+#define LLVM_LIBC_SRC___SUPPORT_TIME_ABS_TIMEOUT_H
#include "hdr/time_macros.h"
#include "hdr/types/struct_timespec.h"
@@ -47,4 +47,4 @@ class AbsTimeout {
} // namespace internal
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_ABS_TIMEOUT_H
+#endif // LLVM_LIBC_SRC___SUPPORT_TIME_ABS_TIMEOUT_H
diff --git a/libc/src/__support/time/linux/CMakeLists.txt b/libc/src/__support/time/linux/CMakeLists.txt
index 1d1c961bf1b2b..a7bdb7b36be49 100644
--- a/libc/src/__support/time/linux/CMakeLists.txt
+++ b/libc/src/__support/time/linux/CMakeLists.txt
@@ -28,24 +28,3 @@ add_object_library(
libc.src.__support.error_or
libc.src.__support.OSUtil.osutil
)
-
-
-add_header_library(
- abs_timeout
- HDRS
- abs_timeout.h
- DEPENDS
- libc.hdr.types.struct_timespec
- libc.src.__support.time.units
- libc.src.__support.CPP.expected
-)
-
-add_header_library(
- monotonicity
- HDRS
- monotonicity.h
- DEPENDS
- .abs_timeout
- libc.hdr.time_macros
- libc.src.__support.time.clock_conversion
-)
diff --git a/libc/src/__support/time/linux/monotonicity.h b/libc/src/__support/time/monotonicity.h
similarity index 83%
rename from libc/src/__support/time/linux/monotonicity.h
rename to libc/src/__support/time/monotonicity.h
index 2ee260ee44ba9..a8c7a56f4c6cc 100644
--- a/libc/src/__support/time/linux/monotonicity.h
+++ b/libc/src/__support/time/monotonicity.h
@@ -1,4 +1,4 @@
-//===--- timeout linux implementation ---------------------------*- C++ -*-===//
+//===--- timeout implementation ---------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,14 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_MONOTONICITY_H
-#define LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_MONOTONICITY_H
+#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_MONOTONICITY_H
+#define LLVM_LIBC_SRC___SUPPORT_TIME_MONOTONICITY_H
#include "hdr/time_macros.h"
#include "src/__support/libc_assert.h"
#include "src/__support/macros/config.h"
+#include "src/__support/time/abs_timeout.h"
#include "src/__support/time/clock_conversion.h"
-#include "src/__support/time/linux/abs_timeout.h"
namespace LIBC_NAMESPACE_DECL {
namespace internal {
// This function is separated from abs_timeout.
@@ -41,4 +41,4 @@ LIBC_INLINE void ensure_monotonicity(AbsTimeout &timeout) {
} // namespace internal
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_MONOTONICITY_H
+#endif // LLVM_LIBC_SRC___SUPPORT_TIME_MONOTONICITY_H
diff --git a/libc/src/pthread/pthread_rwlock_clockwrlock.cpp b/libc/src/pthread/pthread_rwlock_clockwrlock.cpp
index 8f58c7f24bb10..787a1b1484df7 100644
--- a/libc/src/pthread/pthread_rwlock_clockwrlock.cpp
+++ b/libc/src/pthread/pthread_rwlock_clockwrlock.cpp
@@ -12,7 +12,7 @@
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/threads/linux/rwlock.h"
-#include "src/__support/time/linux/abs_timeout.h"
+#include "src/__support/time/abs_timeout.h"
#include <pthread.h>
diff --git a/libc/src/pthread/pthread_rwlock_timedrdlock.cpp b/libc/src/pthread/pthread_rwlock_timedrdlock.cpp
index fcddfed224906..745da508cf140 100644
--- a/libc/src/pthread/pthread_rwlock_timedrdlock.cpp
+++ b/libc/src/pthread/pthread_rwlock_timedrdlock.cpp
@@ -13,7 +13,7 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"
#include "src/__support/threads/linux/rwlock.h"
-#include "src/__support/time/linux/abs_timeout.h"
+#include "src/__support/time/abs_timeout.h"
#include <pthread.h>
diff --git a/libc/src/pthread/pthread_rwlock_timedwrlock.cpp b/libc/src/pthread/pthread_rwlock_timedwrlock.cpp
index d2dc70e992e82..9666fc5b47284 100644
--- a/libc/src/pthread/pthread_rwlock_timedwrlock.cpp
+++ b/libc/src/pthread/pthread_rwlock_timedwrlock.cpp
@@ -13,7 +13,7 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"
#include "src/__support/threads/linux/rwlock.h"
-#include "src/__support/time/linux/abs_timeout.h"
+#include "src/__support/time/abs_timeout.h"
#include <pthread.h>
diff --git a/libc/test/src/__support/time/linux/CMakeLists.txt b/libc/test/src/__support/time/linux/CMakeLists.txt
index 3174986283dd8..6dd13e0a2d8ce 100644
--- a/libc/test/src/__support/time/linux/CMakeLists.txt
+++ b/libc/test/src/__support/time/linux/CMakeLists.txt
@@ -3,7 +3,7 @@ add_libc_test(
SUITE libc-support-time-tests
SRCS timeout_test.cpp
DEPENDS
- libc.src.__support.time.linux.abs_timeout
- libc.src.__support.time.linux.monotonicity
+ libc.src.__support.time.abs_timeout
+ libc.src.__support.time.monotonicity
libc.src.__support.CPP.expected
)
diff --git a/libc/test/src/__support/time/linux/timeout_test.cpp b/libc/test/src/__support/time/linux/timeout_test.cpp
index 37b3763332e2d..33e8231959926 100644
--- a/libc/test/src/__support/time/linux/timeout_test.cpp
+++ b/libc/test/src/__support/time/linux/timeout_test.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/__support/CPP/expected.h"
-#include "src/__support/time/linux/abs_timeout.h"
-#include "src/__support/time/linux/monotonicity.h"
+#include "src/__support/time/abs_timeout.h"
+#include "src/__support/time/monotonicity.h"
#include "test/UnitTest/Test.h"
template <class T, class E>
More information about the libc-commits
mailing list