diff options
author | Marcus Fritzsch <marcus_fritzsch@mentor.com> | 2017-09-04 13:41:35 +0200 |
---|---|---|
committer | Marcus Fritzsch <marcus_fritzsch@mentor.com> | 2017-09-14 14:04:51 +0200 |
commit | 808d675237bdc2750f63a21869264ddb7319a57f (patch) | |
tree | 2d68aef663206ef7a5af97a06a0f1d69f0d3d1f8 /AFBClient.cpp | |
parent | 6766079f68f6a7e2ccdd68b36e9eb206229dd4f7 (diff) |
Impl: made 'returned' boolean atomic
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
Diffstat (limited to 'AFBClient.cpp')
-rw-r--r-- | AFBClient.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/AFBClient.cpp b/AFBClient.cpp index 3a8549d..26efab6 100644 --- a/AFBClient.cpp +++ b/AFBClient.cpp @@ -7,6 +7,7 @@ #include <cstdlib> #include <cstring> +#include <atomic> #include <mutex> #include <unistd.h> @@ -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<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); @@ -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); } |