From: Marcus Fritzsch Date: Tue, 12 Sep 2017 09:29:28 +0000 (+0200) Subject: binding: make the pending_events functionality nicer[tm] X-Git-Tag: 4.99.1~115 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=staging%2Fwindowmanager.git;a=commitdiff_plain;h=83555b0c53f0d59f42e9dcfaeb269948e65e0391 binding: make the pending_events functionality nicer[tm] Signed-off-by: Marcus Fritzsch --- diff --git a/src/app.cpp b/src/app.cpp index 7b2b69c..9b8f1fd 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -159,15 +159,12 @@ int App::dispatch_events() { } this->display->flush(); - // execute pending tasks, that is layout changes etc. - // this->execute_pending(); - return 0; } int App::dispatch_pending_events() { - if (this->pending_events.load(std::memory_order_consume)) { - this->pending_events.store(false, std::memory_order_release); + if (this->pop_pending_events()) { + assert(this->pending_events == false); this->display->dispatch_pending(); return 0; } diff --git a/src/app.hpp b/src/app.hpp index e295797..c4c0a81 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -148,7 +148,16 @@ struct App { struct LayoutState state; + // Set by AFB API when wayland events need to be dispatched std::atomic pending_events; + void set_pending_events() { + this->pending_events.store(true, std::memory_order_release); + } + bool pop_pending_events() { + bool x{true}; + return this->pending_events.compare_exchange_strong( + x, false, std::memory_order_consume); + } explicit App(wl::display *d); ~App(); diff --git a/src/main.cpp b/src/main.cpp index aee2756..f14cf96 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,13 +65,17 @@ int display_event_callback(sd_event_source *evs, int fd, uint32_t events, { STN(display_read_events); g_afb_instance->app.display->read_events(); - g_afb_instance->app.pending_events.store(true, std::memory_order_release); + g_afb_instance->app.set_pending_events(); } { + // We want do dispatch pending wayland events from within + // the API context STN(winman_ping_api_call); - afb_service_call("winman", "ping", json_object_new_object(), [](void *c, int st, json_object* j) { - STN(winman_ping_api_call_return); - }, nullptr); + afb_service_call("winman", "ping", json_object_new_object(), + [](void *c, int st, json_object *j) { + STN(winman_ping_api_call_return); + }, + nullptr); } }