Merge "<time.h>: change the new C23 TIME_ constants."
This commit is contained in:
commit
e023a02cce
3 changed files with 7 additions and 24 deletions
|
@ -28,27 +28,10 @@
|
|||
|
||||
#include <time.h>
|
||||
|
||||
static clockid_t __base_to_clock(int base) {
|
||||
switch (base) {
|
||||
case TIME_UTC:
|
||||
return CLOCK_REALTIME;
|
||||
case TIME_MONOTONIC:
|
||||
return CLOCK_MONOTONIC;
|
||||
case TIME_ACTIVE:
|
||||
return CLOCK_PROCESS_CPUTIME_ID;
|
||||
case TIME_THREAD_ACTIVE:
|
||||
return CLOCK_THREAD_CPUTIME_ID;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int timespec_get(timespec* ts, int base) {
|
||||
clockid_t clock = __base_to_clock(base);
|
||||
return (clock != -1 && clock_gettime(clock, ts) != -1) ? base : 0;
|
||||
return (clock_gettime(base - 1, ts) != -1) ? base : 0;
|
||||
}
|
||||
|
||||
int timespec_getres(timespec* ts, int base) {
|
||||
clockid_t clock = __base_to_clock(base);
|
||||
return (clock != -1 && clock_getres(clock, ts) != -1) ? base : 0;
|
||||
return (clock_getres(base - 1, ts) != -1) ? base : 0;
|
||||
}
|
||||
|
|
|
@ -109,28 +109,28 @@ time_t timegm(struct tm* _Nonnull __tm);
|
|||
*
|
||||
* Available since API level 29.
|
||||
*/
|
||||
#define TIME_UTC 1
|
||||
#define TIME_UTC (CLOCK_REALTIME+1)
|
||||
|
||||
/**
|
||||
* The timebase for timespec_get() and timespec_getres() corresponding to CLOCK_MONOTONIC.
|
||||
*
|
||||
* Available since API level 35.
|
||||
*/
|
||||
#define TIME_MONOTONIC 2
|
||||
#define TIME_MONOTONIC (CLOCK_MONOTONIC+1)
|
||||
|
||||
/**
|
||||
* The timebase for timespec_get() and timespec_getres() corresponding to CLOCK_PROCESS_CPUTIME_ID.
|
||||
*
|
||||
* Available since API level 35.
|
||||
*/
|
||||
#define TIME_ACTIVE 3
|
||||
#define TIME_ACTIVE (CLOCK_PROCESS_CPUTIME_ID+1)
|
||||
|
||||
/**
|
||||
* The timebase for timespec_get() and timespec_getres() corresponding to CLOCK_THREAD_CPUTIME_ID.
|
||||
*
|
||||
* Available since API level 35.
|
||||
*/
|
||||
#define TIME_THREAD_ACTIVE 4
|
||||
#define TIME_THREAD_ACTIVE (CLOCK_THREAD_CPUTIME_ID+1)
|
||||
|
||||
/**
|
||||
* timespec_get(3) is equivalent to clock_gettime() for the clock corresponding to the given base.
|
||||
|
|
|
@ -1281,7 +1281,7 @@ TEST(time, timespec_get) {
|
|||
TEST(time, timespec_get_invalid) {
|
||||
#if __BIONIC__
|
||||
timespec ts = {};
|
||||
ASSERT_EQ(0, timespec_get(&ts, -1));
|
||||
ASSERT_EQ(0, timespec_get(&ts, 123));
|
||||
#else
|
||||
GTEST_SKIP() << "glibc doesn't have timespec_get until 2.21";
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue