binding: ping() dispatches only pending events
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 12 Sep 2017 09:29:28 +0000 (11:29 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 12 Sep 2017 09:29:28 +0000 (11:29 +0200)
* Also, move binding_m mutex to the binding glue.

Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
generate-binding-glue.py
src/afb_binding_api.cpp
src/app.cpp
src/app.hpp
src/main.cpp
src/wayland.cpp

index 086ad32..4791b4d 100644 (file)
@@ -73,7 +73,8 @@ def emit_afb_verbs(api):
     p('   {}', '};')
 
 def emit_binding(api):
-    p('namespace {', '')
+    p('namespace {')
+    p('std::mutex binding_m;', '')
     for func in api['functions']:
         emit_func(api, func)
     p('} // namespace', '')
@@ -95,7 +96,7 @@ def emit_afb_api(api):
     for f in api['functions']:
         p('   result_type %(name)s(' % f + ', '.join(map(lambda x: '%(type)s %(name)s' % x, f.get('args', []))) + ');')
     p('};', '')
-    p('} // namespace wm')
+    p('} // namespace wm', '')
 
 # names must always be valid in c and unique for each function (that is its arguments)
 # arguments will be looked up from json request, range checking needs to be implemented
index 7e6aa89..41eed13 100644 (file)
@@ -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());
 }
 
index e42d05f..7b2b69c 100644 (file)
@@ -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;
+}
+
 //  _       _ _       _                         _    ____
 // (_)_ __ (_) |_    | | __ _ _   _  ___  _   _| |_ / /\ \
 // | | '_ \| | __|   | |/ _` | | | |/ _ \| | | | __| |  | |
index 00a2ba2..e295797 100644 (file)
@@ -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);
index 4c04f74..aee2756 100644 (file)
@@ -30,7 +30,6 @@ extern "C" {
 }
 
 namespace {
-std::mutex binding_m;
 
 struct afb_instance {
    std::unique_ptr<wl::display> display;
index 25c2359..fb18386 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <utility>
 
+#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;
       }