From 31f581c42572612b76d1cd6c8b9b793a5dcc5f65 Mon Sep 17 00:00:00 2001 From: Paul Thompson Date: Fri, 2 Mar 2018 11:06:15 -0800 Subject: [PATCH] Clear the break requested flag if the dispatch loop is being broken due to a timeout condition --- events/equeue/equeue.c | 1 + events/equeue/tests/tests.c | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/events/equeue/equeue.c b/events/equeue/equeue.c index 6b50db439b..36e14fdd3a 100644 --- a/events/equeue/equeue.c +++ b/events/equeue/equeue.c @@ -418,6 +418,7 @@ void equeue_dispatch(equeue_t *q, int ms) { q->background.active = true; equeue_mutex_unlock(&q->queuelock); } + q->break_requested = false; return; } } diff --git a/events/equeue/tests/tests.c b/events/equeue/tests/tests.c index 57212de22d..47d5464864 100644 --- a/events/equeue/tests/tests.c +++ b/events/equeue/tests/tests.c @@ -687,6 +687,45 @@ void multithreaded_barrage_test(int N) { equeue_destroy(&q); } +struct sCaQ +{ + int p; + equeue_t* q; +}; + +typedef struct sCaQ CountAndQueue; + +void simple_breaker(void *p) { + CountAndQueue* caq = (CountAndQueue*)p; + equeue_break(caq->q); + usleep(10000); + caq->p++; +} + +void break_request_cleared_on_timeout(void) { + equeue_t q; + int err = equeue_create(&q, 2048); + test_assert(!err); + + CountAndQueue pq; + pq.p = 0; + pq.q = &q; + + int id = equeue_call_every(&q, 10, simple_breaker, &pq); + + equeue_dispatch(&q, 10); + test_assert(pq.p == 1); + + equeue_cancel(&q, id); + + int count = 0; + equeue_call_every(&q, 10, simple_func, &count); + + equeue_dispatch(&q, 55); + test_assert(count > 1); + + equeue_destroy(&q); +} int main() { printf("beginning tests...\n"); @@ -712,6 +751,7 @@ int main() { test_run(simple_barrage_test, 20); test_run(fragmenting_barrage_test, 20); test_run(multithreaded_barrage_test, 20); + test_run(break_request_cleared_on_timeout); printf("done!\n"); return test_failure;