Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbloop.h | 10 ++++++++++
lib/loop_poll.c | 6 ++++++
tests/check_loop.c | 7 ++++++-
3 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/include/qb/qbloop.h b/include/qb/qbloop.h
index 8fcd1b0..377e638 100644
--- a/include/qb/qbloop.h
+++ b/include/qb/qbloop.h
@@ -156,6 +156,16 @@ int32_t qb_loop_timer_add(qb_loop_t *l,
int32_t qb_loop_timer_del(qb_loop_t *l, qb_loop_timer_handle th);
/**
+ * Check to see if a timer that is still outstanding.
+ *
+ * @param l pointer to the loop instance
+ * @param th handle to delete the timer if needed.
+ * @retval QB_TRUE yes this timer is outstanding
+ * @retval QB_FALSE this timer does not exist or has expired
+ */
+int32_t qb_loop_timer_is_running(qb_loop_t *l, qb_loop_timer_handle th);
+
+/**
* Get the time remaining before it expires.
*
* @note if the timer has already expired it will return 0
diff --git a/lib/loop_poll.c b/lib/loop_poll.c
index 2f6fc20..7663101 100644
--- a/lib/loop_poll.c
+++ b/lib/loop_poll.c
@@ -875,6 +875,12 @@ qb_loop_timer_expire_time_get(struct qb_loop * lp,
qb_loop_timer_handle th)
#endif /* HAVE_TIMERFD */
+int32_t
+qb_loop_timer_is_running(qb_loop_t *l, qb_loop_timer_handle th)
+{
+ return (qb_loop_timer_expire_time_get(l, th) > 0);
+}
+
static int32_t pipe_fds[2] = { -1, -1 };
struct qb_signal_source {
diff --git a/tests/check_loop.c b/tests/check_loop.c
index 4c022e9..7c54918 100644
--- a/tests/check_loop.c
+++ b/tests/check_loop.c
@@ -319,7 +319,7 @@ START_TEST(test_loop_timer_input)
}
END_TEST
-static void one_shot_tmo(void*data)
+static void one_shot_tmo(void * data)
{
static int32_t been_here = QB_FALSE;
ck_assert_int_eq(been_here, QB_FALSE);
@@ -335,6 +335,8 @@ static void reset_one_shot_tmo(void*data)
if (reset_timer_step == 0) {
res = qb_loop_timer_del(l, reset_th);
ck_assert_int_eq(res, -EINVAL);
+ res = qb_loop_timer_is_running(l, reset_th);
+ ck_assert_int_eq(res, QB_FALSE);
res = qb_loop_timer_add(l, QB_LOOP_LOW, 8*QB_TIME_NS_IN_MSEC, l, reset_one_shot_tmo,
&reset_th);
ck_assert_int_eq(res, 0);
}
@@ -351,6 +353,9 @@ START_TEST(test_loop_timer_basic)
res = qb_loop_timer_add(l, QB_LOOP_LOW, 5*QB_TIME_NS_IN_MSEC, l, one_shot_tmo,
&test_th);
ck_assert_int_eq(res, 0);
+ res = qb_loop_timer_is_running(l, test_th);
+ ck_assert_int_eq(res, QB_TRUE);
+
res = qb_loop_timer_add(l, QB_LOOP_LOW, 7*QB_TIME_NS_IN_MSEC, l, reset_one_shot_tmo,
&reset_th);
ck_assert_int_eq(res, 0);
--
1.7.7.6
Show replies by thread