[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.
This commit is contained in:
Shreeyash Pandey
2025-12-08 22:14:12 +05:30
committed by GitHub
parent 614fe6da14
commit 2a5420ea51
15 changed files with 53 additions and 46 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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>

View File

@@ -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

View File

@@ -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 {

View File

@@ -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
)

View File

@@ -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 @@ public:
} // 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

View File

@@ -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
)

View File

@@ -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

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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
)

View File

@@ -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>