From: James Prestwood <prestwoj@gmail.com>
To: ell@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH 2/2] timeout: add l_timeout_remaining
Date: Thu, 29 Aug 2024 04:25:49 -0700 [thread overview]
Message-ID: <20240829112549.24935-2-prestwoj@gmail.com> (raw)
In-Reply-To: <20240829112549.24935-1-prestwoj@gmail.com>
Gets the remaining microseconds left on a timer. Microseconds were
chosen in order to be easily compatible with l_time APIs.
---
ell/ell.sym | 1 +
ell/timeout.c | 29 +++++++++++++++++++++++++++++
ell/timeout.h | 3 ++-
3 files changed, 32 insertions(+), 1 deletion(-)
v2:
* Use _time_from_timespec
* Changed name to l_timeout_remaining()
diff --git a/ell/ell.sym b/ell/ell.sym
index c7dc9e6..b04ad63 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -526,6 +526,7 @@ global:
l_timeout_create_ms;
l_timeout_modify;
l_timeout_modify_ms;
+ l_timeout_remaining;
l_timeout_remove;
l_timeout_set_callback;
/* tls */
diff --git a/ell/timeout.c b/ell/timeout.c
index 4fc21a0..541692e 100644
--- a/ell/timeout.c
+++ b/ell/timeout.c
@@ -23,6 +23,7 @@
#include "timeout.h"
#include "main-private.h"
#include "private.h"
+#include "time-private.h"
/**
* SECTION:timeout
@@ -298,3 +299,31 @@ LIB_EXPORT void l_timeout_set_callback(struct l_timeout *timeout,
timeout->user_data = user_data;
timeout->destroy = destroy;
}
+
+/**
+ * l_timeout_get_remaining:
+ *
+ * Get the remaining time for a timeout in microseconds
+ *
+ * @timeout: timeout object
+ * @remaining: microseconds remaining on timer
+ *
+ * Returns: True if successfully got remaining time
+ * False if failure to get remaining time
+ **/
+LIB_EXPORT bool l_timeout_remaining(struct l_timeout *timeout,
+ uint64_t *remaining)
+{
+ struct itimerspec current;
+
+ if (unlikely(!timeout))
+ return false;
+
+ if (timerfd_gettime(timeout->fd, ¤t) < 0)
+ return false;
+
+ if (remaining)
+ *remaining = _time_from_timespec(¤t.it_value);
+
+ return true;
+}
diff --git a/ell/timeout.h b/ell/timeout.h
index 2db78d8..c0d463c 100644
--- a/ell/timeout.h
+++ b/ell/timeout.h
@@ -34,7 +34,8 @@ void l_timeout_remove(struct l_timeout *timeout);
void l_timeout_set_callback(struct l_timeout *timeout,
l_timeout_notify_cb_t callback, void *user_data,
l_timeout_destroy_cb_t destroy);
-
+bool l_timeout_remaining(struct l_timeout *timeout,
+ uint64_t *remaining);
#ifdef __cplusplus
}
#endif
--
2.34.1
next prev parent reply other threads:[~2024-08-29 11:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 11:25 [PATCH 1/2] time: expose _time_from_timespec in time-private.h James Prestwood
2024-08-29 11:25 ` James Prestwood [this message]
2024-09-03 15:05 ` Denis Kenzior
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=20240829112549.24935-2-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=ell@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.