Skip to content

Commit 082159f

Browse files
authored
Merge pull request #3300 from geky/events-fix-unchain
events - Fix unchaining of event queues
2 parents d60f424 + 87a1cfe commit 082159f

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ python:
22
- "2.7"
33

44
script:
5+
- make -C events/equeue test clean
56
- PYTHONPATH=. python tools/test/config_test/config_test.py
67
- PYTHONPATH=. python tools/test/build_api/build_api_test.py
78
- python tools/test/pylint.py

events/equeue/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ endif
1717
ifdef WORD
1818
CFLAGS += -m$(WORD)
1919
endif
20-
CFLAGS += -I.
20+
CFLAGS += -I. -I..
2121
CFLAGS += -std=c99
2222
CFLAGS += -Wall
2323
CFLAGS += -D_XOPEN_SOURCE=600

events/equeue/equeue.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ static void equeue_chain_update(void *p, int ms) {
558558
}
559559

560560
void equeue_chain(equeue_t *q, equeue_t *target) {
561+
if (!target) {
562+
equeue_background(q, 0, 0);
563+
return;
564+
}
565+
561566
struct equeue_chain_context *c = equeue_alloc(q,
562567
sizeof(struct equeue_chain_context));
563568

events/equeue/tests/tests.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,42 @@ void chain_test(void) {
557557
equeue_dispatch(&q1, 30);
558558

559559
test_assert(touched == 6);
560+
561+
equeue_destroy(&q1);
562+
equeue_destroy(&q2);
563+
}
564+
565+
void unchain_test(void) {
566+
equeue_t q1;
567+
int err = equeue_create(&q1, 2048);
568+
test_assert(!err);
569+
570+
equeue_t q2;
571+
err = equeue_create(&q2, 2048);
572+
test_assert(!err);
573+
574+
equeue_chain(&q2, &q1);
575+
576+
int touched = 0;
577+
int id1 = equeue_call(&q1, simple_func, &touched);
578+
int id2 = equeue_call(&q2, simple_func, &touched);
579+
test_assert(id1 && id2);
580+
581+
equeue_dispatch(&q1, 0);
582+
test_assert(touched == 2);
583+
584+
equeue_chain(&q2, 0);
585+
equeue_chain(&q1, &q2);
586+
587+
id1 = equeue_call(&q1, simple_func, &touched);
588+
id2 = equeue_call(&q2, simple_func, &touched);
589+
test_assert(id1 && id2);
590+
591+
equeue_dispatch(&q2, 0);
592+
test_assert(touched == 4);
593+
594+
equeue_destroy(&q1);
595+
equeue_destroy(&q2);
560596
}
561597

562598
// Barrage tests
@@ -671,6 +707,7 @@ int main() {
671707
test_run(sloth_test);
672708
test_run(background_test);
673709
test_run(chain_test);
710+
test_run(unchain_test);
674711
test_run(multithread_test);
675712
test_run(simple_barrage_test, 20);
676713
test_run(fragmenting_barrage_test, 20);

0 commit comments

Comments
 (0)