MailBox: Only allocate a promise when we have a blocking call.

This commit is contained in:
Jean-Philip Desjardins 2024-05-18 11:28:47 -04:00
parent a70c8d6fea
commit 58a9c2f278
2 changed files with 7 additions and 3 deletions

View file

@ -36,7 +36,8 @@ void CMailBox::SendCall(const FunctionType& function, bool waitForCompletion)
if(waitForCompletion)
{
future = message.promise.get_future();
message.promise = std::make_unique<std::promise<void>>();
future = message.promise->get_future();
}
m_calls.push_back(std::move(message));
@ -73,5 +74,8 @@ void CMailBox::ReceiveCall()
m_calls.pop_front();
}
message.function();
message.promise.set_value();
if(message.promise)
{
message.promise->set_value();
}
}

View file

@ -34,7 +34,7 @@ private:
MESSAGE& operator=(const MESSAGE&) = delete;
FunctionType function;
std::promise<void> promise;
std::unique_ptr<std::promise<void>> promise;
};
typedef std::deque<MESSAGE> FunctionCallQueue;