[c++ grpc] Simplify io_manager::wait
This commit is contained in:
Родитель
0637203975
Коммит
05d6783e08
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include <bond/core/config.h>
|
#include <bond/core/config.h>
|
||||||
|
|
||||||
#include <bond/ext/detail/event.h>
|
#include <bond/core/detail/once.h>
|
||||||
#include <bond/ext/grpc/detail/io_manager_tag.h>
|
#include <bond/ext/grpc/detail/io_manager_tag.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
@ -179,25 +179,18 @@ namespace bond { namespace ext { namespace gRPC {
|
||||||
/// return.
|
/// return.
|
||||||
void wait()
|
void wait()
|
||||||
{
|
{
|
||||||
bool shouldShutdown = !_isShutdownInProgress.test_and_set();
|
bond::detail::call_once(
|
||||||
if (shouldShutdown)
|
_waitFlag,
|
||||||
{
|
[this]
|
||||||
// borrow the current thread to clean up
|
|
||||||
for (auto& thread : _threads)
|
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(thread.joinable());
|
for (auto& thread : _threads)
|
||||||
thread.join();
|
{
|
||||||
}
|
BOOST_ASSERT(thread.joinable());
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
_threads.clear();
|
_threads.clear();
|
||||||
|
});
|
||||||
_shutdownCompleted.set();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// some other thread is performing clean up, so wait for it
|
|
||||||
_shutdownCompleted.wait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -219,8 +212,7 @@ namespace bond { namespace ext { namespace gRPC {
|
||||||
std::vector<std::thread> _threads;
|
std::vector<std::thread> _threads;
|
||||||
|
|
||||||
std::atomic_flag _isShutdownRequested = ATOMIC_FLAG_INIT;
|
std::atomic_flag _isShutdownRequested = ATOMIC_FLAG_INIT;
|
||||||
std::atomic_flag _isShutdownInProgress = ATOMIC_FLAG_INIT;
|
bond::detail::once_flag _waitFlag{};
|
||||||
bond::ext::detail::event _shutdownCompleted;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} } } // namespace bond::ext::gRPC
|
} } } // namespace bond::ext::gRPC
|
||||||
|
|
Загрузка…
Ссылка в новой задаче