diff options
author | Marcus Fritzsch <marcus_fritzsch@mentor.com> | 2017-08-31 17:17:42 +0200 |
---|---|---|
committer | Marcus Fritzsch <marcus_fritzsch@mentor.com> | 2017-09-04 16:54:02 +0200 |
commit | 89685c1f1e603d9a45ce0f3407c73e712dd7ad5a (patch) | |
tree | 6948c5a5b0a1d187035f8d51c3aec43e6daeefc2 | |
parent | 45b2e667e2e0f0791b911dcfd8afa843be58e311 (diff) |
main/binding: do not allow concurrent threads in App
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
-rw-r--r-- | generate-binding-glue.py | 1 | ||||
-rw-r--r-- | src/main.cpp | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/generate-binding-glue.py b/generate-binding-glue.py index a489b63..82f71ae 100644 --- a/generate-binding-glue.py +++ b/generate-binding-glue.py @@ -49,6 +49,7 @@ def emit_func_impl(api, f): def emit_func(api, f): p('void %(impl_name)s(afb_req req) noexcept {' % f) + p(' std::lock_guard<std::mutex> guard(binding_m);') p(' if (g_afb_instance == nullptr) {', ' afb_req_fail(req, "failed", "Binding not initialized, did the compositor die?");', ' return;', diff --git a/src/main.cpp b/src/main.cpp index a768347..47e3335 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,8 @@ #include "wayland.hpp" #include <algorithm> +#include <mutex> + #include <json.h> extern "C" { @@ -28,6 +30,8 @@ extern "C" { } namespace { +std::mutex binding_m; + struct afb_instance { std::unique_ptr<wl::display> display; wm::App app; @@ -49,6 +53,8 @@ int afb_instance::init() { int display_event_callback(sd_event_source *evs, int /*fd*/, uint32_t events, void * /*data*/) { + std::lock_guard<std::mutex> guard(binding_m); + if ((events & EPOLLHUP) != 0) { logerror("The compositor hung up, dying now."); delete g_afb_instance; |