From: Marcus Fritzsch Date: Fri, 1 Sep 2017 12:39:28 +0000 (+0200) Subject: Guard dispatch using a mutex, remove dipatch() timeout parameter X-Git-Tag: 4.99.1~46 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=staging%2Fwindowmanager.git;a=commitdiff_plain;h=b4cf01ec167f17c5df96906741fb4c6690ed9164 Guard dispatch using a mutex, remove dipatch() timeout parameter Signed-off-by: Marcus Fritzsch --- diff --git a/AFBClient.cpp b/AFBClient.cpp index d3e3a5e..0452d16 100644 --- a/AFBClient.cpp +++ b/AFBClient.cpp @@ -7,6 +7,8 @@ #include #include +#include + #include #include @@ -87,13 +89,16 @@ static struct afb_wsj1_itf itf = { onHangup, onCall, onEvent, }; -void dispatch_internal(AFBClient *c, uint64_t timeout) { +std::recursive_mutex dispatch_mutex; + +void dispatch_internal(struct sd_event *loop) { + std::lock_guard guard(dispatch_mutex); TRACE(); - c->dispatch(timeout); + sd_event_run(loop, -1); } /// object will be json_object_put -int api_call(AFBClient *c, struct afb_wsj1 *wsj1, const char *verb, +int api_call(struct sd_event *loop, struct afb_wsj1 *wsj1, const char *verb, json_object *object, std::function onReply) { TRACE(); @@ -142,7 +147,7 @@ int api_call(AFBClient *c, struct afb_wsj1 *wsj1, const char *verb, // if events get triggered by the call (and would be dispatched before // the actual call-reply). while (!returned) { - dispatch_internal(c, -1); + dispatch_internal(loop); } // return the actual API call result @@ -219,8 +224,9 @@ fail: return rc; } -int AFBClient::dispatch(uint64_t timeout) { - return sd_event_run(loop, timeout); +int AFBClient::dispatch() { + std::lock_guard guard(dispatch_mutex); + return sd_event_run(loop, 1); } int AFBClient::requestSurface(const char *label) { @@ -230,7 +236,7 @@ int AFBClient::requestSurface(const char *label) { int rc = -1; /* send the request */ int rc2 = api_call( - this, wsj1, "request_surface", jp, [&rc](bool ok, json_object *j) { + loop, wsj1, "request_surface", jp, [&rc](bool ok, json_object *j) { if (ok) { int id = json_object_get_int(json_object_object_get(j, "response")); @@ -259,7 +265,7 @@ int AFBClient::activateSurface(const char *label) { TRACE(); json_object *j = json_object_new_object(); json_object_object_add(j, "drawing_name", json_object_new_string(label)); - return api_call(this, wsj1, "activate_surface", j, [](bool ok, + return api_call(loop, wsj1, "activate_surface", j, [](bool ok, json_object *j) { if (!ok) { fprintf( @@ -274,7 +280,7 @@ int AFBClient::deactivateSurface(const char *label) { TRACE(); json_object *j = json_object_new_object(); json_object_object_add(j, "drawing_name", json_object_new_string(label)); - return api_call(this, wsj1, "deactivate_surface", j, [](bool ok, + return api_call(loop, wsj1, "deactivate_surface", j, [](bool ok, json_object *j) { if (!ok) { fprintf( @@ -289,7 +295,7 @@ int AFBClient::endDraw(const char *label) { TRACE(); json_object *j = json_object_new_object(); json_object_object_add(j, "drawing_name", json_object_new_string(label)); - return api_call(this, wsj1, "enddraw", j, [](bool ok, json_object *j) { + return api_call(loop, wsj1, "enddraw", j, [](bool ok, json_object *j) { if (!ok) { fprintf( stderr, "API Call endDraw() failed: %s\n", diff --git a/AFBClient.h b/AFBClient.h index 6625c44..b1694b8 100644 --- a/AFBClient.h +++ b/AFBClient.h @@ -3,12 +3,9 @@ #include -extern "C" -{ - struct json_object; - struct afb_wsj1; - struct sd_event; -} +struct json_object; +struct afb_wsj1; +struct sd_event; class AFBClient { @@ -31,7 +28,7 @@ public: static AFBClient &instance(); int init(int port, char const *token); - int dispatch(uint64_t timeout); + int dispatch(); // WM API int requestSurface(const char *label);