@ -227,18 +227,19 @@ void WorkStealingThreadPool::PostforkChild() { pool_->Postfork(); }
WorkStealingThreadPool : : WorkStealingThreadPoolImpl : : WorkStealingThreadPoolImpl (
size_t reserve_threads )
: reserve_threads_ ( reserve_threads ) , queue_ ( this ) , lifeguard_ ( this ) { }
: reserve_threads_ ( reserve_threads ) , queue_ ( this ) { }
void WorkStealingThreadPool : : WorkStealingThreadPoolImpl : : Start ( ) {
for ( size_t i = 0 ; i < reserve_threads_ ; i + + ) {
StartThread ( ) ;
}
lifeguard_ . Start ( ) ;
grpc_core : : MutexLock lock ( & lifeguard_ptr_mu_ ) ;
lifeguard_ = std : : make_unique < Lifeguard > ( this ) ;
}
void WorkStealingThreadPool : : WorkStealingThreadPoolImpl : : Run (
EventEngine : : Closure * closure ) {
DCHECK ( quiesced_ . load ( std : : memory_order_relaxed ) = = false ) ;
CHECK ( ! IsQuiesced ( ) ) ;
if ( g_local_queue ! = nullptr & & g_local_queue - > owner ( ) = = this ) {
g_local_queue - > Add ( closure ) ;
} else {
@ -283,7 +284,8 @@ void WorkStealingThreadPool::WorkStealingThreadPoolImpl::Quiesce() {
}
CHECK ( queue_ . Empty ( ) ) ;
quiesced_ . store ( true , std : : memory_order_relaxed ) ;
lifeguard_ . BlockUntilShutdownAndReset ( ) ;
grpc_core : : MutexLock lock ( & lifeguard_ptr_mu_ ) ;
lifeguard_ . reset ( ) ;
}
bool WorkStealingThreadPool : : WorkStealingThreadPoolImpl : : SetThrottled (
@ -325,7 +327,8 @@ void WorkStealingThreadPool::WorkStealingThreadPoolImpl::PrepareFork() {
if ( ! threads_were_shut_down . ok ( ) & & g_log_verbose_failures ) {
DumpStacksAndCrash ( ) ;
}
lifeguard_ . BlockUntilShutdownAndReset ( ) ;
grpc_core : : MutexLock lock ( & lifeguard_ptr_mu_ ) ;
lifeguard_ . reset ( ) ;
}
void WorkStealingThreadPool : : WorkStealingThreadPoolImpl : : Postfork ( ) {
@ -374,9 +377,7 @@ WorkStealingThreadPool::WorkStealingThreadPoolImpl::Lifeguard::Lifeguard(
. set_max_backoff ( kLifeguardMaxSleepBetweenChecks )
. set_multiplier ( 1.3 ) ) ,
lifeguard_should_shut_down_ ( std : : make_unique < grpc_core : : Notification > ( ) ) ,
lifeguard_is_shut_down_ ( std : : make_unique < grpc_core : : Notification > ( ) ) { }
void WorkStealingThreadPool : : WorkStealingThreadPoolImpl : : Lifeguard : : Start ( ) {
lifeguard_is_shut_down_ ( std : : make_unique < grpc_core : : Notification > ( ) ) {
// lifeguard_running_ is set early to avoid a quiesce race while the
// lifeguard is still starting up.
lifeguard_running_ . store ( true ) ;
@ -411,8 +412,7 @@ void WorkStealingThreadPool::WorkStealingThreadPoolImpl::Lifeguard::
lifeguard_is_shut_down_ - > Notify ( ) ;
}
void WorkStealingThreadPool : : WorkStealingThreadPoolImpl : : Lifeguard : :
BlockUntilShutdownAndReset ( ) {
WorkStealingThreadPool : : WorkStealingThreadPoolImpl : : Lifeguard : : ~ Lifeguard ( ) {
lifeguard_should_shut_down_ - > Notify ( ) ;
while ( lifeguard_running_ . load ( std : : memory_order_relaxed ) ) {
GRPC_LOG_EVERY_N_SEC_DELAYED ( kBlockingQuiesceLogRateSeconds , GPR_DEBUG ,