[orc-rt] Use future rather than condition_variable for shutdown wait. (#179169)
Session::waitForShutdown is a convenience wrapper around the asynchronous Session::shutdown call. The previous Session::waitForShutdown call waited on a std::condition_variable to signal the end of shutdown, but it's easier to just embed a std::promise in a callback to the asynchronous shutdown method.
This commit is contained in:
parent
85545d4c84
commit
448595d4cb
@ -23,7 +23,7 @@
|
||||
#include "orc-rt-c/WrapperFunction.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <condition_variable>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
@ -163,7 +163,6 @@ public:
|
||||
private:
|
||||
struct ShutdownInfo {
|
||||
bool Complete = false;
|
||||
std::condition_variable CompleteCV;
|
||||
std::vector<std::unique_ptr<ResourceManager>> ResourceMgrs;
|
||||
std::vector<OnShutdownCompleteFn> OnCompletes;
|
||||
};
|
||||
|
||||
@ -57,9 +57,10 @@ void Session::shutdown(OnShutdownCompleteFn OnShutdownComplete) {
|
||||
}
|
||||
|
||||
void Session::waitForShutdown() {
|
||||
shutdown([]() {});
|
||||
std::unique_lock<std::mutex> Lock(M);
|
||||
SI->CompleteCV.wait(Lock, [&]() { return SI->Complete; });
|
||||
std::promise<void> P;
|
||||
auto F = P.get_future();
|
||||
shutdown([P = std::move(P)]() mutable { P.set_value(); });
|
||||
F.get();
|
||||
}
|
||||
|
||||
void Session::addResourceManager(std::unique_ptr<ResourceManager> RM) {
|
||||
@ -115,8 +116,6 @@ void Session::shutdownComplete() {
|
||||
|
||||
for (auto &OnShutdownComplete : OnCompletes)
|
||||
OnShutdownComplete();
|
||||
|
||||
SI->CompleteCV.notify_all();
|
||||
}
|
||||
|
||||
void Session::wrapperReturn(orc_rt_SessionRef S, uint64_t CallId,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user