time: expose _time_from_timespec in time-private.h
PATCH 1/2 time: expose _time_from_timespec in time-private.h
--- ell/time-private.h | 1 + ell/time.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
ell/time-private.h +1 -0
@@ -12,3 +12,4 @@ uint64_t _time_fuzz_msecs(uint64_t ms);uint64_t _time_fuzz_secs (uint32_t secs,uint32_t max_offset);uint64_t _time_realtime_to_boottime (const struct timeval *ts);uint64_t time_realtime_now (void ); +uint64_t _time_from_timespec (const struct timespec *ts);
ell/time.c +1 -1
@@ -18,7 +18,7 @@#include "random.h" #include "private.h" -static uint64_t _time_from_timespec (const struct timespec *ts) +uint64_t _time_from_timespec (const struct timespec *ts) {return ts->tv_sec *L_USEC_PER_SEC + ts->tv_nsec /L_NSEC_PER_USEC ; }
Signature · 1 line
2.34.1
PATCH 2/2 timeout: add l_timeout_remaining
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()
ell/ell.sym +1 -0
@@ -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 */
ell/timeout.c +29 -0
@@ -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; +}
ell/timeout.h +2 -1
@@ -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
Signature · 1 line
2.34.1
Hi James,
Quoted 4 lines · James Prestwood
--- ell/time-private.h | 1 + ell/time.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
all applied, thanks.
Regards,
-Denis