@@ -34,6 +34,11 @@
#include <sys/time.h>
#include <time.h>
+#define TST_TIMER_NONE 0
+#define TST_TIMER_STARTED 1
+#define TST_TIMER_STOPPED (1 << 1)
+#define TST_TIMER_EXPIRED (1 << 2)
+
/*
* Converts timespec to microseconds.
*/
@@ -259,6 +264,8 @@ void tst_timer_start(clockid_t clk_id);
*/
int tst_timer_expired_ms(long long ms);
+int tst_timer_state_ms(long long ms);
+
/*
* Marks timer end time.
*/
@@ -87,6 +87,17 @@ int tst_timer_expired_ms(long long ms)
return tst_timespec_diff_ms(cur_time, start_time) >= ms;
}
+int tst_timer_state_ms(long long ms)
+{
+ int status = TST_TIMER_NONE;
+
+ status |= (start_time.tv_sec | start_time.tv_nsec) > 0;
+ status |= ((stop_time.tv_sec | stop_time.tv_nsec) > 0) << 1;
+ status |= tst_timer_expired_ms(ms) << 2;
+
+ return status;
+}
+
void tst_timer_stop(void)
{
if (tst_clock_gettime(clock_id, &stop_time))
Allow the user to discover the current timer state with a single function. Useful for using a timer in a loop where we do not know if the timer has already been started. Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com> --- include/tst_timer.h | 7 +++++++ lib/tst_timer.c | 11 +++++++++++ 2 files changed, 18 insertions(+)