Skip to content

Commit

Permalink
Clear the break requested flag if the dispatch loop is being broken d…
Browse files Browse the repository at this point in the history
…ue to a timeout condition
  • Loading branch information
Paul Thompson authored and geky committed Aug 4, 2019
1 parent 1acddeb commit b1ebdc5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions equeue.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ void equeue_dispatch(equeue_t *q, int ms) {
q->background.active = true;
equeue_mutex_unlock(&q->queuelock);
}
q->break_requested = false;
return;
}
}
Expand Down
40 changes: 40 additions & 0 deletions tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,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");
Expand All @@ -701,6 +740,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;
Expand Down

0 comments on commit b1ebdc5

Please sign in to comment.