[libc-commits] [libc] [libc] move abs_timesout and monotonicity out of linux dir (PR #167719)

Shreeyash Pandey via libc-commits libc-commits at lists.llvm.org
Mon Dec 8 05:14:18 PST 2025


https://github.com/bojle updated https://github.com/llvm/llvm-project/pull/167719

>From d898aa914bc86e513ef0122c3c188863c7a5ab6b Mon Sep 17 00:00:00 2001
From: Shreeyash Pandey <shreeyash335 at gmail.com>
Date: Wed, 12 Nov 2025 16:34:32 +0530
Subject: [PATCH 1/8] [libc] add darwin errno support

Adds support for darwin's errno headers/macros by including it from
<sys/errno.h> and modifying header guards in hdr/ and include/.
---
 libc/hdr/errno_macros.h  | 4 +++-
 libc/include/errno.h.def | 8 +++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libc/hdr/errno_macros.h b/libc/hdr/errno_macros.h
index 27ea49977d8c8..ce3453d16bce1 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 __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..ba9864439369a 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 __APPLE__
+
+#include <sys/errno.h>
+
+#else // __APPLE__
+
 #include "llvm-libc-macros/generic-error-number-macros.h"
+
 #endif
 
 __BEGIN_C_DECLS

>From 4c527b7fe487dbaafb8dd339f3f241f329f641c3 Mon Sep 17 00:00:00 2001
From: Shreeyash Pandey <shreeyash335 at gmail.com>
Date: Wed, 12 Nov 2025 21:08:37 +0530
Subject: [PATCH 2/8] [libc] move abs_timesout and monotonicity out of linux
 dir

---
 .../src/__support/threads/linux/futex_utils.h |  2 +-
 libc/src/__support/threads/linux/rwlock.h     |  2 +-
 libc/src/__support/time/CMakeLists.txt        | 29 +++++++++++++++++++
 .../__support/time/{linux => }/abs_timeout.h  | 10 +++----
 libc/src/__support/time/linux/CMakeLists.txt  | 21 --------------
 .../__support/time/{linux => }/monotonicity.h | 12 ++++----
 .../pthread/pthread_rwlock_clockwrlock.cpp    |  2 +-
 .../pthread/pthread_rwlock_timedrdlock.cpp    |  2 +-
 .../pthread/pthread_rwlock_timedwrlock.cpp    |  2 +-
 9 files changed, 45 insertions(+), 37 deletions(-)
 rename libc/src/__support/time/{linux => }/abs_timeout.h (85%)
 rename libc/src/__support/time/{linux => }/monotonicity.h (82%)

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/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..df79896887086 100644
--- a/libc/src/__support/time/CMakeLists.txt
+++ b/libc/src/__support/time/CMakeLists.txt
@@ -37,3 +37,32 @@ 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(
+  clock_conversion
+  HDRS
+    clock_conversion.h
+  DEPENDS
+    .clock_gettime
+    libc.src.__support.time.units
+)
+
+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 85%
rename from libc/src/__support/time/linux/abs_timeout.h
rename to libc/src/__support/time/abs_timeout.h
index 37e602672208f..23ad52f530545 100644
--- a/libc/src/__support/time/linux/abs_timeout.h
+++ b/libc/src/__support/time/abs_timeout.h
@@ -1,13 +1,13 @@
-//===--- 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.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
-//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------===//
 
-#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 82%
rename from libc/src/__support/time/linux/monotonicity.h
rename to libc/src/__support/time/monotonicity.h
index 2ee260ee44ba9..4fee76da2a62e 100644
--- a/libc/src/__support/time/linux/monotonicity.h
+++ b/libc/src/__support/time/monotonicity.h
@@ -1,19 +1,19 @@
-//===--- 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.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
-//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------===//
 
-#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>
 

>From 44f2e9cae7e981d591d066adde9ee1190f4f7f29 Mon Sep 17 00:00:00 2001
From: Shreeyash Pandey <shreeyash335 at gmail.com>
Date: Fri, 14 Nov 2025 20:29:49 +0530
Subject: [PATCH 3/8] [libc] linux/abs_timeout.h -> abs_timesout.h

---
 libc/src/__support/threads/linux/raw_mutex.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/__support/threads/linux/raw_mutex.h b/libc/src/__support/threads/linux/raw_mutex.h
index 47f0aa70f1c46..8f69da2ceab07 100644
--- a/libc/src/__support/threads/linux/raw_mutex.h
+++ b/libc/src/__support/threads/linux/raw_mutex.h
@@ -17,7 +17,7 @@
 #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

>From f181323dfe58791e36e982393a1230831f711cf7 Mon Sep 17 00:00:00 2001
From: Shreeyash Pandey <shreeyash335 at gmail.com>
Date: Wed, 3 Dec 2025 18:26:36 +0530
Subject: [PATCH 4/8] [libc] address comments

---
 libc/hdr/errno_macros.h  | 2 +-
 libc/include/errno.h.def | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/hdr/errno_macros.h b/libc/hdr/errno_macros.h
index ce3453d16bce1..e2913f45a8ad9 100644
--- a/libc/hdr/errno_macros.h
+++ b/libc/hdr/errno_macros.h
@@ -15,7 +15,7 @@
 #include <linux/errno.h>
 
 #include "include/llvm-libc-macros/error-number-macros.h"
-#elif __APPLE__
+#elif defined(__APPLE__)
 #include <sys/errno.h>
 #else // __APPLE__
 #include "include/llvm-libc-macros/generic-error-number-macros.h"
diff --git a/libc/include/errno.h.def b/libc/include/errno.h.def
index ba9864439369a..0ac8e57f7a158 100644
--- a/libc/include/errno.h.def
+++ b/libc/include/errno.h.def
@@ -21,7 +21,7 @@
 
 #include "llvm-libc-macros/linux/error-number-macros.h"
 
-#elif __APPLE__
+#elif defined(__APPLE__)
 
 #include <sys/errno.h>
 

>From 3ab73568588f111f03bcae905ad1d2cdaae11ef6 Mon Sep 17 00:00:00 2001
From: Shreeyash Pandey <shreeyash335 at gmail.com>
Date: Thu, 4 Dec 2025 18:23:23 +0530
Subject: [PATCH 5/8] [libc] remove double clock_conversion

---
 libc/src/__support/time/CMakeLists.txt | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/libc/src/__support/time/CMakeLists.txt b/libc/src/__support/time/CMakeLists.txt
index df79896887086..3cc3fd873220a 100644
--- a/libc/src/__support/time/CMakeLists.txt
+++ b/libc/src/__support/time/CMakeLists.txt
@@ -48,15 +48,6 @@ add_header_library(
     libc.src.__support.CPP.expected
 )
 
-add_header_library(
-  clock_conversion
-  HDRS
-    clock_conversion.h
-  DEPENDS
-    .clock_gettime
-    libc.src.__support.time.units
-)
-
 add_header_library(
   monotonicity
   HDRS

>From ca31528d8384a80b4b39a0ea606fd8a3f23d26b1 Mon Sep 17 00:00:00 2001
From: Shreeyash Pandey <shreeyash335 at gmail.com>
Date: Thu, 4 Dec 2025 18:52:44 +0530
Subject: [PATCH 6/8] [libc] remove linux/

---
 libc/src/__support/threads/linux/raw_mutex.h        | 2 +-
 libc/test/src/__support/time/linux/timeout_test.cpp | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libc/src/__support/threads/linux/raw_mutex.h b/libc/src/__support/threads/linux/raw_mutex.h
index 8f69da2ceab07..94d6129bbf69b 100644
--- a/libc/src/__support/threads/linux/raw_mutex.h
+++ b/libc/src/__support/threads/linux/raw_mutex.h
@@ -24,7 +24,7 @@
 #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/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>

>From 042c8cc2a8fb0f31cd7a7f6673a0221f35eba636 Mon Sep 17 00:00:00 2001
From: Shreeyash Pandey <shreeyash335 at gmail.com>
Date: Thu, 4 Dec 2025 18:55:46 +0530
Subject: [PATCH 7/8] [libc] header to 80

---
 libc/src/__support/time/abs_timeout.h  | 4 ++--
 libc/src/__support/time/monotonicity.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libc/src/__support/time/abs_timeout.h b/libc/src/__support/time/abs_timeout.h
index 23ad52f530545..23ac23dd864c8 100644
--- a/libc/src/__support/time/abs_timeout.h
+++ b/libc/src/__support/time/abs_timeout.h
@@ -1,10 +1,10 @@
-//===--- 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.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
-//===----------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_TIME_ABS_TIMEOUT_H
 #define LLVM_LIBC_SRC___SUPPORT_TIME_ABS_TIMEOUT_H
diff --git a/libc/src/__support/time/monotonicity.h b/libc/src/__support/time/monotonicity.h
index 4fee76da2a62e..a8c7a56f4c6cc 100644
--- a/libc/src/__support/time/monotonicity.h
+++ b/libc/src/__support/time/monotonicity.h
@@ -1,10 +1,10 @@
-//===--- timeout 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.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
-//===----------------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_TIME_MONOTONICITY_H
 #define LLVM_LIBC_SRC___SUPPORT_TIME_MONOTONICITY_H

>From 3812ff81450f48870612217034f663228573f8c4 Mon Sep 17 00:00:00 2001
From: Shreeyash Pandey <shreeyash335 at gmail.com>
Date: Mon, 8 Dec 2025 18:43:20 +0530
Subject: [PATCH 8/8] [libc] remove .linux.

---
 libc/test/src/__support/time/linux/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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
 )



More information about the libc-commits mailing list