summaryrefslogtreecommitdiff
path: root/libc/src/time/linux/clock.cpp
diff options
context:
space:
mode:
authorSchrodinger ZHU Yifan <yifanzhu@rochester.edu>2024-05-09 16:34:45 -0400
committerGitHub <noreply@github.com>2024-05-09 16:34:45 -0400
commit8ac928fea8d561261133e0337a2777fcda99f7ba (patch)
tree3d7b75eea7f0bcf25f7a28f3d36d32157a02b626 /libc/src/time/linux/clock.cpp
parent75ebcbf24abb2e5b045ec920bc86f667516e4cc6 (diff)
[libc][NFC] adjust time related implementations (#91485)
Diffstat (limited to 'libc/src/time/linux/clock.cpp')
-rw-r--r--libc/src/time/linux/clock.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/libc/src/time/linux/clock.cpp b/libc/src/time/linux/clock.cpp
index 1e95f0526bc9..fc48e2792747 100644
--- a/libc/src/time/linux/clock.cpp
+++ b/libc/src/time/linux/clock.cpp
@@ -7,21 +7,19 @@
//===----------------------------------------------------------------------===//
#include "src/time/clock.h"
-
+#include "hdr/time_macros.h"
#include "src/__support/CPP/limits.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
+#include "src/__support/time/clock_gettime.h"
+#include "src/__support/time/units.h"
#include "src/errno/libc_errno.h"
-#include "src/time/linux/clockGetTimeImpl.h"
-
-#include <sys/syscall.h> // For syscall numbers.
-#include <time.h>
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(clock_t, clock, ()) {
+ using namespace time_units;
struct timespec ts;
- auto result = internal::clock_gettimeimpl(CLOCK_PROCESS_CPUTIME_ID, &ts);
+ auto result = internal::clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
if (!result.has_value()) {
libc_errno = result.error();
return -1;
@@ -34,15 +32,15 @@ LLVM_LIBC_FUNCTION(clock_t, clock, ()) {
cpp::numeric_limits<clock_t>::max() / CLOCKS_PER_SEC;
if (ts.tv_sec > CLOCK_SECS_MAX)
return clock_t(-1);
- if (ts.tv_nsec / 1000000000 > CLOCK_SECS_MAX - ts.tv_sec)
+ if (ts.tv_nsec / 1_s_ns > CLOCK_SECS_MAX - ts.tv_sec)
return clock_t(-1);
// For the integer computation converting tv_nsec to clocks to work
// correctly, we want CLOCKS_PER_SEC to be less than 1000000000.
- static_assert(1000000000 > CLOCKS_PER_SEC,
- "Expected CLOCKS_PER_SEC to be less than 1000000000.");
+ static_assert(1_s_ns > CLOCKS_PER_SEC,
+ "Expected CLOCKS_PER_SEC to be less than 1'000'000'000.");
return clock_t(ts.tv_sec * CLOCKS_PER_SEC +
- ts.tv_nsec / (1000000000 / CLOCKS_PER_SEC));
+ ts.tv_nsec / (1_s_ns / CLOCKS_PER_SEC));
}
} // namespace LIBC_NAMESPACE