diff --git a/src/Proxy.cpp b/src/Proxy.cpp index b9ae9f5..89d94b7 100644 --- a/src/Proxy.cpp +++ b/src/Proxy.cpp @@ -98,7 +98,7 @@ PendingAsyncCall Proxy::callMethod(const MethodCall& message, async_reply_handle SDBUS_THROW_ERROR_IF(!message.isValid(), "Invalid async method call message provided", EINVAL); auto callback = (void*)&Proxy::sdbus_async_reply_handler; - auto callData = std::make_shared(AsyncCalls::CallData{*this, std::move(asyncReplyCallback), {}, AsyncCalls::CallData::State::RUNNING}); + auto callData = std::make_shared(AsyncCalls::CallData{*this, std::move(asyncReplyCallback)}); auto weakData = std::weak_ptr{callData}; callData->slot = connection_->callMethod(message, callback, callData.get(), timeout); @@ -211,16 +211,13 @@ int Proxy::sdbus_async_reply_handler(sd_bus_message *sdbusMessage, void *userDat assert(asyncCallData != nullptr); assert(asyncCallData->callback); auto& proxy = asyncCallData->proxy; - auto state = asyncCallData->state; // We are removing the CallData item at the complete scope exit, after the callback has been invoked. // We can't do it earlier (before callback invocation for example), because CallBack data (slot release) // is the synchronization point between callback invocation and Proxy::unregister. SCOPE_EXIT { - // Remove call meta-data if it's a real async call (a sync call done in terms of async has STATE_NOT_ASYNC) - if (state != AsyncCalls::CallData::State::NOT_ASYNC) - proxy.pendingAsyncCalls_.removeCall(asyncCallData); + proxy.pendingAsyncCalls_.removeCall(asyncCallData); }; auto message = Message::Factory::create(sdbusMessage, &proxy.connection_->getSdBusInterface()); diff --git a/src/Proxy.h b/src/Proxy.h index 0c35de4..efb5b3a 100644 --- a/src/Proxy.h +++ b/src/Proxy.h @@ -119,16 +119,10 @@ namespace sdbus::internal { public: struct CallData { - enum class State // TODO: In release/v2.0, we no more have sync-in-terms-of-async, we can simplify code with just bool finished like before - { NOT_ASYNC - , RUNNING - , FINISHED - }; - Proxy& proxy; async_reply_handler callback; - Slot slot; - State state; + Slot slot{}; + bool finished{false}; }; ~AsyncCalls() @@ -139,14 +133,14 @@ namespace sdbus::internal { void addCall(std::shared_ptr asyncCallData) { std::lock_guard lock(mutex_); - if (asyncCallData->state != CallData::State::FINISHED) // The call may have finished in the meantime + if (!asyncCallData->finished) // The call may have finished in the meantime calls_.emplace_back(std::move(asyncCallData)); } void removeCall(CallData* data) { std::unique_lock lock(mutex_); - data->state = CallData::State::FINISHED; + data->finished = true; if (auto it = std::find_if(calls_.begin(), calls_.end(), [data](auto const& entry){ return entry.get() == data; }); it != calls_.end()) { auto callData = std::move(*it);