Skip to content

Commit 31f581c

Browse files
author
Paul Thompson
committed
Clear the break requested flag if the dispatch loop is being broken due to a timeout condition
1 parent 5d98d22 commit 31f581c

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

events/equeue/equeue.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ void equeue_dispatch(equeue_t *q, int ms) {
418418
q->background.active = true;
419419
equeue_mutex_unlock(&q->queuelock);
420420
}
421+
q->break_requested = false;
421422
return;
422423
}
423424
}

events/equeue/tests/tests.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,45 @@ void multithreaded_barrage_test(int N) {
687687
equeue_destroy(&q);
688688
}
689689

690+
struct sCaQ
691+
{
692+
int p;
693+
equeue_t* q;
694+
};
695+
696+
typedef struct sCaQ CountAndQueue;
697+
698+
void simple_breaker(void *p) {
699+
CountAndQueue* caq = (CountAndQueue*)p;
700+
equeue_break(caq->q);
701+
usleep(10000);
702+
caq->p++;
703+
}
704+
705+
void break_request_cleared_on_timeout(void) {
706+
equeue_t q;
707+
int err = equeue_create(&q, 2048);
708+
test_assert(!err);
709+
710+
CountAndQueue pq;
711+
pq.p = 0;
712+
pq.q = &q;
713+
714+
int id = equeue_call_every(&q, 10, simple_breaker, &pq);
715+
716+
equeue_dispatch(&q, 10);
717+
test_assert(pq.p == 1);
718+
719+
equeue_cancel(&q, id);
720+
721+
int count = 0;
722+
equeue_call_every(&q, 10, simple_func, &count);
723+
724+
equeue_dispatch(&q, 55);
725+
test_assert(count > 1);
726+
727+
equeue_destroy(&q);
728+
}
690729

691730
int main() {
692731
printf("beginning tests...\n");
@@ -712,6 +751,7 @@ int main() {
712751
test_run(simple_barrage_test, 20);
713752
test_run(fragmenting_barrage_test, 20);
714753
test_run(multithreaded_barrage_test, 20);
754+
test_run(break_request_cleared_on_timeout);
715755

716756
printf("done!\n");
717757
return test_failure;

0 commit comments

Comments
 (0)