#include <cstdlib>
#include <cstring>
+#include <atomic>
#include <mutex>
#include <unistd.h>
exit(0);
}
-static struct afb_wsj1_itf itf = {
+constexpr static struct afb_wsj1_itf itf = {
onHangup, onCall, onEvent,
};
// 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<bool> returned;
+ returned.store(false, std::memory_order_relaxed);
std::function<void(bool, json_object *)> wrappedOnReply =
[&returned, &call_rc, &onReply](bool ok, json_object *j) {
TRACEN(wrappedOnReply);
TRACEN(onReply);
onReply(ok, j);
}
- returned = true;
+ returned.store(true, std::memory_order_release);
};
// make the actual call, use wrappedOnReply as closure
// 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);
}
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<struct afb_wsj1_itf *>(&itf), nullptr);
if (wsj1 == nullptr) {
sd_event_unref(loop);
fprintf(stderr, "Connection to %s failed: %m\n", uribuf);