binding: make the pending_events functionality nicer[tm]
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)
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
src/app.cpp
src/app.hpp
src/main.cpp

index 7b2b69c..9b8f1fd 100644 (file)
@@ -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;
    }
index e295797..c4c0a81 100644 (file)
@@ -148,7 +148,16 @@ struct App {
 
    struct LayoutState state;
 
+   // Set by AFB API when wayland events need to be dispatched
    std::atomic<bool> 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();
index aee2756..f14cf96 100644 (file)
@@ -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);
       }
    }