Skip to content

Commit 198a8bf

Browse files
author
Cruz Monrreal
authored
Merge pull request #9144 from deepikabhavnani/equeue_cancel_issue
EventQueue: Old pointers of sibling were not cleared
2 parents ac361d6 + 12623ac commit 198a8bf

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

events/equeue/equeue.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ void equeue_destroy(equeue_t *q)
108108
{
109109
// call destructors on pending events
110110
for (struct equeue_event *es = q->queue; es; es = es->next) {
111-
for (struct equeue_event *e = q->queue; e; e = e->sibling) {
111+
for (struct equeue_event *e = es->sibling; e; e = e->sibling) {
112112
if (e->dtor) {
113113
e->dtor(e + 1);
114114
}
115115
}
116+
if (es->dtor) {
117+
es->dtor(es + 1);
118+
}
116119
}
117-
118120
// notify background timer
119121
if (q->background.update) {
120122
q->background.update(q->background.timer, -1);
@@ -239,8 +241,8 @@ static int equeue_enqueue(equeue_t *q, struct equeue_event *e, unsigned tick)
239241
if (e->next) {
240242
e->next->ref = &e->next;
241243
}
242-
243244
e->sibling = *p;
245+
e->sibling->next = 0;
244246
e->sibling->ref = &e->sibling;
245247
} else {
246248
e->next = *p;

events/equeue/tests/tests.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,29 @@ void break_request_cleared_on_timeout(void)
779779
equeue_destroy(&q);
780780
}
781781

782+
void sibling_test(void)
783+
{
784+
equeue_t q;
785+
int err = equeue_create(&q, 1024);
786+
test_assert(!err);
787+
788+
int id0 = equeue_call_in(&q, 1, pass_func, 0);
789+
int id1 = equeue_call_in(&q, 1, pass_func, 0);
790+
int id2 = equeue_call_in(&q, 1, pass_func, 0);
791+
792+
struct equeue_event *e = q.queue;
793+
794+
for (; e; e = e->next) {
795+
for (struct equeue_event *s = e->sibling; s; s = s->sibling) {
796+
test_assert(!s->next);
797+
}
798+
}
799+
equeue_cancel(&q, id0);
800+
equeue_cancel(&q, id1);
801+
equeue_cancel(&q, id2);
802+
equeue_destroy(&q);
803+
}
804+
782805
int main()
783806
{
784807
printf("beginning tests...\n");
@@ -806,7 +829,7 @@ int main()
806829
test_run(fragmenting_barrage_test, 20);
807830
test_run(multithreaded_barrage_test, 20);
808831
test_run(break_request_cleared_on_timeout);
809-
832+
test_run(sibling_test);
810833
printf("done!\n");
811834
return test_failure;
812835
}

0 commit comments

Comments
 (0)