From d564823cfdbdb62e4d84a3b2d15fa016fd7fb5dd Mon Sep 17 00:00:00 2001 From: Damian Hobson-Garcia Date: Tue, 31 Aug 2021 18:59:33 +0900 Subject: server: stop wl_display event loop from any context Calling wl_display_terminate() will exit the wl_display event loop at the start of the next loop iteration. This works fine when wl_display_terminate() is called after the event loop wakes up from polling on the added event sources. If, however, it is called before polling starts, the event loop will not exit until one or more event sources trigger. Depending on the types of event sources, they may never trigger (or may not trigger for a long time), so the event loop may never exit. Add an extra event source to the wl_display event loop that will trigger whenever wl_display_terminate() is called, so that the event loop will always exit. Fixes #201 Signed-off-by: Damian Hobson-Garcia --- tests/display-test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/display-test.c b/tests/display-test.c index 3db7c95..763adc9 100644 --- a/tests/display-test.c +++ b/tests/display-test.c @@ -1629,3 +1629,24 @@ TEST(global_remove) display_destroy(d); } + +static void +terminate_display(void *arg) +{ + struct wl_display *wl_display = arg; + wl_display_terminate(wl_display); +} + +TEST(no_source_terminate) +{ + struct display *d; + struct wl_event_loop *loop; + + d = display_create(); + loop = wl_display_get_event_loop(d->wl_display); + + wl_event_loop_add_idle(loop, terminate_display, d->wl_display); + + display_run(d); + display_destroy(d); +} -- cgit v1.2.3-70-g09d2