From b154238b7b9e0d21b60c08a1bec23920bff40e36 Mon Sep 17 00:00:00 2001 From: Marcus Fritzsch Date: Tue, 12 Sep 2017 11:29:28 +0200 Subject: binding: ping() dispatches only pending events * Also, move binding_m mutex to the binding glue. Signed-off-by: Marcus Fritzsch --- src/afb_binding_api.cpp | 2 +- src/app.cpp | 14 +++++++++++--- src/app.hpp | 1 + src/main.cpp | 1 - src/wayland.cpp | 3 +++ 5 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/afb_binding_api.cpp b/src/afb_binding_api.cpp index 7e6aa89..41eed13 100644 --- a/src/afb_binding_api.cpp +++ b/src/afb_binding_api.cpp @@ -100,7 +100,7 @@ binding_api::result_type binding_api::debug_terminate() { } binding_api::result_type binding_api::ping() { - this->app->dispatch_events(); + this->app->dispatch_pending_events(); return Ok(json_object_new_object()); } diff --git a/src/app.cpp b/src/app.cpp index e42d05f..7b2b69c 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -147,9 +147,8 @@ int App::init() { } int App::dispatch_events() { - if (this->pending_events.load(std::memory_order_consume)) { - this->pending_events.store(false, std::memory_order_release); - return this->display->dispatch_pending(); + if (this->dispatch_events() == 0) { + return 0; } int ret = this->display->dispatch(); @@ -166,6 +165,15 @@ int App::dispatch_events() { 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); + this->display->dispatch_pending(); + return 0; + } + return -1; +} + // _ _ _ _ _ ____ // (_)_ __ (_) |_ | | __ _ _ _ ___ _ _| |_ / /\ \ // | | '_ \| | __| | |/ _` | | | |/ _ \| | | | __| | | | diff --git a/src/app.hpp b/src/app.hpp index 00a2ba2..e295797 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -162,6 +162,7 @@ struct App { int init_layers(); int dispatch_events(); + int dispatch_pending_events(); void surface_set_layout_full(uint32_t surface_id); void surface_set_layout_split(uint32_t surface_id, uint32_t sub_surface_id); diff --git a/src/main.cpp b/src/main.cpp index 4c04f74..aee2756 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,6 @@ extern "C" { } namespace { -std::mutex binding_m; struct afb_instance { std::unique_ptr display; diff --git a/src/wayland.cpp b/src/wayland.cpp index 25c2359..fb18386 100644 --- a/src/wayland.cpp +++ b/src/wayland.cpp @@ -16,6 +16,7 @@ #include +#include "util.hpp" #include "wayland.hpp" // _ @@ -46,8 +47,10 @@ int display::dispatch() { return wl_display_dispatch(this->d.get()); } int display::dispatch_pending() { return wl_display_dispatch_pending(this->d.get()); } int display::read_events() { + ST(); // XXX: uhm, how?! while (wl_display_prepare_read(this->d.get()) == -1) { + STN(pending_events_dispatch); if (wl_display_dispatch_pending(this->d.get()) == -1) { return -1; } -- cgit 1.2.3-korg