mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Yonggang Luo <luoyonggang@gmail.com>
To: Jens Gustedt <jens.gustedt@inria.fr>, enh <enh@google.com>,
	musl@lists.openwall.com
Cc: Yonggang Luo <luoyonggang@gmail.com>
Subject: [musl] [PATCH v3 4/5] c23: Implement newly base for timespec_get
Date: Tue, 20 Jun 2023 22:37:02 +0800	[thread overview]
Message-ID: <20230620143703.1415-5-luoyonggang@gmail.com> (raw)
In-Reply-To: <20230620143703.1415-1-luoyonggang@gmail.com>

These are implemented https://gustedt.gitlabpages.inria.fr/c23-library/#time_monotonic-time_active-time_thread_active

with:

#define TIME_UTC                1
#define TIME_MONOTONIC          2
#define TIME_ACTIVE             3
#define TIME_THREAD_ACTIVE      4
#define TIME_MONOTONIC_RAW      5
#define TIME_UTC_COARSE         6
#define TIME_MONOTONIC_COARSE   7
#define TIME_BOOTTIME           8
#define TIME_UTC_ALARM          9
#define TIME_BOOTTIME_ALARM     10
#define TIME_SGI_CYCLE          11
#define TIME_TAI                12

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 include/time.h          | 13 +++++++++++-
 src/time/timespec_get.c | 44 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/include/time.h b/include/time.h
index 3d948372..ab31d373 100644
--- a/include/time.h
+++ b/include/time.h
@@ -64,7 +64,18 @@ int timespec_get(struct timespec *, int);
 
 #define CLOCKS_PER_SEC 1000000L
 
-#define TIME_UTC 1
+#define TIME_UTC                1
+#define TIME_MONOTONIC          2
+#define TIME_ACTIVE             3
+#define TIME_THREAD_ACTIVE      4
+#define TIME_MONOTONIC_RAW      5
+#define TIME_UTC_COARSE         6
+#define TIME_MONOTONIC_COARSE   7
+#define TIME_BOOTTIME           8
+#define TIME_UTC_ALARM          9
+#define TIME_BOOTTIME_ALARM     10
+#define TIME_SGI_CYCLE          11
+#define TIME_TAI                12
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
diff --git a/src/time/timespec_get.c b/src/time/timespec_get.c
index 40ea9c1c..b8738189 100644
--- a/src/time/timespec_get.c
+++ b/src/time/timespec_get.c
@@ -4,7 +4,47 @@
  * are considered erroneous. */
 int timespec_get(struct timespec * ts, int base)
 {
-	if (base != TIME_UTC) return 0;
-	int ret = __clock_gettime(CLOCK_REALTIME, ts);
+	clockid_t clockid = -1;
+	switch (base) {
+	default:
+		return 0;
+	case TIME_UTC:
+		clockid = CLOCK_REALTIME;
+		break;
+	case TIME_MONOTONIC:
+		clockid = CLOCK_MONOTONIC;
+		break;
+	case TIME_ACTIVE:
+		clockid = CLOCK_PROCESS_CPUTIME_ID;
+		break;
+	case TIME_THREAD_ACTIVE:
+		clockid = CLOCK_THREAD_CPUTIME_ID;
+		break;
+	case TIME_MONOTONIC_RAW:
+		clockid = CLOCK_MONOTONIC_RAW;
+		break;
+	case TIME_UTC_COARSE:
+		clockid = CLOCK_REALTIME_COARSE;
+		break;
+	case TIME_MONOTONIC_COARSE:
+		clockid = CLOCK_MONOTONIC_COARSE;
+		break;
+	case TIME_BOOTTIME:
+		clockid = CLOCK_BOOTTIME;
+		break;
+	case TIME_UTC_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;
+	}
+	int ret = __clock_gettime(clockid, ts);
 	return ret < 0 ? 0 : base;
 }
-- 
2.39.0.windows.1


  parent reply	other threads:[~2023-06-20 14:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-20 14:36 [musl] [PATCH v3 0/5] Add posix/pthread_mutex_clocklock posix/pthread_cond_clockdwait c2y/mtx_timedlock_base c2y/cnd_timedwait_base Yonggang Luo
2023-06-20 14:36 ` [musl] [PATCH v3 1/5] trim spaces of pthread_cond_timedwait.c and pthread_mutex_timedlock.c Yonggang Luo
2023-06-20 14:37 ` [musl] [PATCH v3 2/5] Rename files for implement pthread_mutex_clocklock and pthread_cond_clockwait Yonggang Luo
2023-06-20 14:37 ` [musl] [PATCH v3 3/5] add pthread_mutex_clocklock and pthread_cond_clockdwait Yonggang Luo
2023-06-21 15:04   ` Rich Felker
2023-06-20 14:37 ` Yonggang Luo [this message]
2023-06-20 14:37 ` [musl] [PATCH v3 5/5] c2y: Add monotonic timedlock/timedwait support for threads mtx/cnd Yonggang Luo
2023-06-20 22:47 ` [musl] [PATCH v3 0/5] Add posix/pthread_mutex_clocklock posix/pthread_cond_clockdwait c2y/mtx_timedlock_base c2y/cnd_timedwait_base Rich Felker
2023-06-21  6:10   ` 罗勇刚(Yonggang Luo)
2023-06-21 14:54     ` Rich Felker
2023-06-21 18:43       ` 罗勇刚(Yonggang Luo)
2023-06-21 18:58         ` enh
2023-06-21  6:25   ` 罗勇刚(Yonggang Luo)
2023-06-21 14:44     ` Rich Felker

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=20230620143703.1415-5-luoyonggang@gmail.com \
    --to=luoyonggang@gmail.com \
    --cc=enh@google.com \
    --cc=jens.gustedt@inria.fr \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).