From: Yonggang Luo <luoyonggang@gmail.com>
To: Jens Gustedt <jens.gustedt@inria.fr>, libc-alpha@sourceware.org
Cc: Yonggang Luo <luoyonggang@gmail.com>
Subject: [PATCH 2/5] time: Implement c23 timespec_get base
Date: Tue, 20 Jun 2023 06:20:49 +0800 [thread overview]
Message-ID: <20230619222052.682-3-luoyonggang@gmail.com> (raw)
In-Reply-To: <20230619222052.682-1-luoyonggang@gmail.com>
These newly implement base are:
#define TIME_MONOTONIC 2
#define TIME_PROCESS_CPUTIME_ID 3
#define TIME_THREAD_CPUTIME_ID 4
#define TIME_MONOTONIC_RAW 5
#define TIME_REALTIME_COARSE 6
#define TIME_MONOTONIC_COARSE 7
#define TIME_BOOTTIME 8
#define TIME_REALTIME_ALARM 9
#define TIME_BOOTTIME_ALARM 10
#define TIME_SGI_CYCLE 11
#define TIME_TAI 12
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
time/time.h | 13 ++++++++++++
time/timespec_get.c | 48 ++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/time/time.h b/time/time.h
index 368f4dc588..189a560199 100644
--- a/time/time.h
+++ b/time/time.h
@@ -64,6 +64,19 @@ typedef __pid_t pid_t;
/* Time base values for timespec_get. */
# define TIME_UTC 1
#endif
+#ifdef __GLIBC_USE_ISOC23
+#define TIME_MONOTONIC 2
+#define TIME_PROCESS_CPUTIME_ID 3
+#define TIME_THREAD_CPUTIME_ID 4
+#define TIME_MONOTONIC_RAW 5
+#define TIME_REALTIME_COARSE 6
+#define TIME_MONOTONIC_COARSE 7
+#define TIME_BOOTTIME 8
+#define TIME_REALTIME_ALARM 9
+#define TIME_BOOTTIME_ALARM 10
+#define TIME_SGI_CYCLE 11
+#define TIME_TAI 12
+#endif
__BEGIN_DECLS
diff --git a/time/timespec_get.c b/time/timespec_get.c
index 9b1d4f22ed..a57b1ee0b8 100644
--- a/time/timespec_get.c
+++ b/time/timespec_get.c
@@ -22,10 +22,52 @@
int
timespec_get (struct timespec *ts, int base)
{
- if (base == TIME_UTC)
+ clockid_t clockid = -1;
+ switch (base) {
+ default:
+ break;
+ case TIME_UTC:
+ clockid = CLOCK_REALTIME;
+ break;
+ case TIME_MONOTONIC:
+ clockid = CLOCK_MONOTONIC;
+ break;
+ case TIME_PROCESS_CPUTIME_ID:
+ clockid = CLOCK_PROCESS_CPUTIME_ID;
+ break;
+ case TIME_THREAD_CPUTIME_ID:
+ clockid = CLOCK_THREAD_CPUTIME_ID;
+ break;
+ case TIME_MONOTONIC_RAW:
+ clockid = CLOCK_MONOTONIC_RAW;
+ break;
+ case TIME_REALTIME_COARSE:
+ clockid = CLOCK_REALTIME_COARSE;
+ break;
+ case TIME_MONOTONIC_COARSE:
+ clockid = CLOCK_MONOTONIC_COARSE;
+ break;
+ case TIME_BOOTTIME:
+ clockid = CLOCK_BOOTTIME;
+ break;
+ case TIME_REALTIME_ALARM:
+ clockid = CLOCK_REALTIME_ALARM;
+ break;
+ case TIME_BOOTTIME_ALARM:
+ clockid = CLOCK_BOOTTIME_ALARM;
+ break;
+ case TIME_SGI_CYCLE:
+ clockid = CLOCK_SGI_CYCLE;
+ break;
+ case TIME_TAI:
+ clockid = CLOCK_TAI;
+ break;
+ }
+ if (clockid >= 0)
{
- __clock_gettime (CLOCK_REALTIME, ts);
- return base;
+ if (__clock_gettime (clockid, ts) >= 0) {
+ return base;
+ }
}
return 0;
}
--
2.39.0.windows.1
next prev parent reply other threads:[~2023-06-19 22:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-19 22:20 [PATCH 0/5] c2y proposal add monotonicwait support for mtx and ctx Yonggang Luo
2023-06-19 22:20 ` [PATCH 1/5] features: Rename __GLIBC_USE_ISOC2X to __GLIBC_USE_ISOC23 Yonggang Luo
2023-06-20 20:21 ` Joseph Myers
2023-06-21 6:32 ` 罗勇刚(Yonggang Luo)
2023-06-19 22:20 ` Yonggang Luo [this message]
2023-06-20 12:44 ` [PATCH 2/5] time: Implement c23 timespec_get base Florian Weimer
2023-06-20 16:10 ` 罗勇刚(Yonggang Luo)
2023-06-20 20:25 ` Joseph Myers
2023-06-19 22:20 ` [PATCH 3/5] clang-format: should format with 2 space and do not usage tab Yonggang Luo
2023-06-19 22:20 ` [PATCH 4/5] c11: Switch to use pthread_mutex_clocklock and pthread_cond_clockwait to implement cnd and mtx lock and wait Yonggang Luo
2023-06-20 9:15 ` Florian Weimer
2023-06-19 22:20 ` [PATCH 5/5] c2y: Add function cnd_timedwait_monotonic and mtx_timedlock_monotonic Yonggang Luo
2023-06-20 20:29 ` Joseph Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230619222052.682-3-luoyonggang@gmail.com \
--to=luoyonggang@gmail.com \
--cc=jens.gustedt@inria.fr \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).