X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=AFBClient.cpp;h=9210eacbe89a2b9697f50338366b43216d47b84f;hb=715231c6093c54797d36c1e01667439d0a8741f3;hp=3a8549d20e3561a0ba1a7163d05d20cdc13410ae;hpb=6766079f68f6a7e2ccdd68b36e9eb206229dd4f7;p=staging%2Fwindowmanager.git diff --git a/AFBClient.cpp b/AFBClient.cpp index 3a8549d..9210eac 100644 --- a/AFBClient.cpp +++ b/AFBClient.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -85,7 +86,7 @@ void onHangup(void *closure, afb_wsj1 *wsj1) { exit(0); } -static struct afb_wsj1_itf itf = { +constexpr static struct afb_wsj1_itf itf = { onHangup, onCall, onEvent, }; @@ -110,7 +111,8 @@ int api_call(struct sd_event *loop, struct afb_wsj1 *wsj1, const char *verb, // Alternatively we could setup a local struct and use it as // closure, but I think it is cleaner this way. int call_rc = 0; - bool returned = false; + std::atomic returned; + returned.store(false, std::memory_order_relaxed); std::function wrappedOnReply = [&returned, &call_rc, &onReply](bool ok, json_object *j) { TRACEN(wrappedOnReply); @@ -121,7 +123,7 @@ int api_call(struct sd_event *loop, struct afb_wsj1 *wsj1, const char *verb, TRACEN(onReply); onReply(ok, j); } - returned = true; + returned.store(true, std::memory_order_release); }; // make the actual call, use wrappedOnReply as closure @@ -147,7 +149,7 @@ int api_call(struct sd_event *loop, struct afb_wsj1 *wsj1, const char *verb, // We need to dispatch until "returned" got set, this is necessary // if events get triggered by the call (and would be dispatched before // the actual call-reply). - while (!returned) { + while (!returned.load(std::memory_order_consume)) { dispatch_internal(loop); } @@ -234,7 +236,8 @@ int AFBClient::Impl::init(int port, char const *token) { asprintf(&uribuf, "ws://localhost:%d/api?token=%s", port, token); /* connect the websocket wsj1 to the uri given by the first argument */ - wsj1 = afb_ws_client_connect_wsj1(loop, uribuf, &itf, nullptr); + wsj1 = afb_ws_client_connect_wsj1( + loop, uribuf, const_cast(&itf), nullptr); if (wsj1 == nullptr) { sd_event_unref(loop); fprintf(stderr, "Connection to %s failed: %m\n", uribuf);