Skip to content

Commit 2a5420e

Browse files
authored
[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.
1 parent 614fe6d commit 2a5420e

File tree

15 files changed

+53
-46
lines changed

15 files changed

+53
-46
lines changed

libc/hdr/errno_macros.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#include <linux/errno.h>
1616

1717
#include "include/llvm-libc-macros/error-number-macros.h"
18-
#else // __linux__
18+
#elif defined(__APPLE__)
19+
#include <sys/errno.h>
20+
#else // __APPLE__
1921
#include "include/llvm-libc-macros/generic-error-number-macros.h"
2022
#endif
2123

libc/include/errno.h.def

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@
2121

2222
#include "llvm-libc-macros/linux/error-number-macros.h"
2323

24-
#else // __linux__
24+
#elif defined(__APPLE__)
25+
26+
#include <sys/errno.h>
27+
28+
#else // __APPLE__
29+
2530
#include "llvm-libc-macros/generic-error-number-macros.h"
31+
2632
#endif
2733

2834
__BEGIN_C_DECLS

libc/src/__support/threads/linux/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ add_header_library(
2121
libc.src.__support.CPP.atomic
2222
libc.src.__support.CPP.limits
2323
libc.src.__support.CPP.optional
24-
libc.src.__support.time.linux.abs_timeout
24+
libc.src.__support.time.abs_timeout
2525
)
2626

2727
set(monotonicity_flags)
@@ -38,8 +38,8 @@ add_header_library(
3838
DEPENDS
3939
.futex_utils
4040
libc.src.__support.threads.sleep
41-
libc.src.__support.time.linux.abs_timeout
42-
libc.src.__support.time.linux.monotonicity
41+
libc.src.__support.time.abs_timeout
42+
libc.src.__support.time.monotonicity
4343
libc.src.__support.CPP.optional
4444
libc.hdr.types.pid_t
4545
COMPILE_OPTIONS

libc/src/__support/threads/linux/futex_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "src/__support/macros/attributes.h"
1717
#include "src/__support/macros/config.h"
1818
#include "src/__support/threads/linux/futex_word.h"
19-
#include "src/__support/time/linux/abs_timeout.h"
19+
#include "src/__support/time/abs_timeout.h"
2020
#include <linux/errno.h>
2121
#include <linux/futex.h>
2222

libc/src/__support/threads/linux/raw_mutex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
#include "src/__support/threads/linux/futex_utils.h"
1818
#include "src/__support/threads/linux/futex_word.h"
1919
#include "src/__support/threads/sleep.h"
20-
#include "src/__support/time/linux/abs_timeout.h"
20+
#include "src/__support/time/abs_timeout.h"
2121

2222
#ifndef LIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY
2323
#define LIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY 1
2424
#endif
2525

2626
#if LIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY
27-
#include "src/__support/time/linux/monotonicity.h"
27+
#include "src/__support/time/monotonicity.h"
2828
#endif
2929

3030
#ifndef LIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT

libc/src/__support/threads/linux/rwlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#endif
3636

3737
#if LIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY
38-
#include "src/__support/time/linux/monotonicity.h"
38+
#include "src/__support/time/monotonicity.h"
3939
#endif
4040

4141
namespace LIBC_NAMESPACE_DECL {

libc/src/__support/time/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,23 @@ if(TARGET libc.src.__support.time.${LIBC_TARGET_OS}.clock_settime)
3737
libc.src.__support.time.${LIBC_TARGET_OS}.clock_settime
3838
)
3939
endif()
40+
41+
add_header_library(
42+
abs_timeout
43+
HDRS
44+
abs_timeout.h
45+
DEPENDS
46+
libc.hdr.types.struct_timespec
47+
libc.src.__support.time.units
48+
libc.src.__support.CPP.expected
49+
)
50+
51+
add_header_library(
52+
monotonicity
53+
HDRS
54+
monotonicity.h
55+
DEPENDS
56+
.clock_conversion
57+
.abs_timeout
58+
libc.hdr.time_macros
59+
)

libc/src/__support/time/linux/abs_timeout.h renamed to libc/src/__support/time/abs_timeout.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//===--- Linux absolute timeout ---------------------------------*- C++ -*-===//
1+
//===--- absolute timeout ---------------------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_ABS_TIMEOUT_H
10-
#define LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_ABS_TIMEOUT_H
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_ABS_TIMEOUT_H
10+
#define LLVM_LIBC_SRC___SUPPORT_TIME_ABS_TIMEOUT_H
1111

1212
#include "hdr/time_macros.h"
1313
#include "hdr/types/struct_timespec.h"
@@ -47,4 +47,4 @@ class AbsTimeout {
4747
} // namespace internal
4848
} // namespace LIBC_NAMESPACE_DECL
4949

50-
#endif // LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_ABS_TIMEOUT_H
50+
#endif // LLVM_LIBC_SRC___SUPPORT_TIME_ABS_TIMEOUT_H

libc/src/__support/time/linux/CMakeLists.txt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,3 @@ add_object_library(
2828
libc.src.__support.error_or
2929
libc.src.__support.OSUtil.osutil
3030
)
31-
32-
33-
add_header_library(
34-
abs_timeout
35-
HDRS
36-
abs_timeout.h
37-
DEPENDS
38-
libc.hdr.types.struct_timespec
39-
libc.src.__support.time.units
40-
libc.src.__support.CPP.expected
41-
)
42-
43-
add_header_library(
44-
monotonicity
45-
HDRS
46-
monotonicity.h
47-
DEPENDS
48-
.abs_timeout
49-
libc.hdr.time_macros
50-
libc.src.__support.time.clock_conversion
51-
)

libc/src/__support/time/linux/monotonicity.h renamed to libc/src/__support/time/monotonicity.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//===--- timeout linux implementation ---------------------------*- C++ -*-===//
1+
//===--- timeout implementation ---------------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_MONOTONICITY_H
10-
#define LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_MONOTONICITY_H
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_MONOTONICITY_H
10+
#define LLVM_LIBC_SRC___SUPPORT_TIME_MONOTONICITY_H
1111

1212
#include "hdr/time_macros.h"
1313
#include "src/__support/libc_assert.h"
1414
#include "src/__support/macros/config.h"
15+
#include "src/__support/time/abs_timeout.h"
1516
#include "src/__support/time/clock_conversion.h"
16-
#include "src/__support/time/linux/abs_timeout.h"
1717
namespace LIBC_NAMESPACE_DECL {
1818
namespace internal {
1919
// This function is separated from abs_timeout.
@@ -41,4 +41,4 @@ LIBC_INLINE void ensure_monotonicity(AbsTimeout &timeout) {
4141
} // namespace internal
4242
} // namespace LIBC_NAMESPACE_DECL
4343

44-
#endif // LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_MONOTONICITY_H
44+
#endif // LLVM_LIBC_SRC___SUPPORT_TIME_MONOTONICITY_H

0 commit comments

Comments
 (0)