diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 8708cf21c3b..7f15cb416b9 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -202,7 +202,6 @@ class ConnectedSubchannelStateWatcher // Must be instantiated while holding c->mu. explicit ConnectedSubchannelStateWatcher(grpc_subchannel* c) : subchannel_(c) { - gpr_mu_init(&mu_); // Steal subchannel ref for connecting. GRPC_SUBCHANNEL_WEAK_REF(subchannel_, "state_watcher"); GRPC_SUBCHANNEL_WEAK_UNREF(subchannel_, "connecting"); @@ -235,13 +234,10 @@ class ConnectedSubchannelStateWatcher ~ConnectedSubchannelStateWatcher() { GRPC_SUBCHANNEL_WEAK_UNREF(subchannel_, "state_watcher"); - gpr_mu_destroy(&mu_); } - void Orphan() override { - MutexLock lock(&mu_); - health_check_client_.reset(); - } + // Must be called while holding subchannel_->mu. + void Orphan() override { health_check_client_.reset(); } private: static void OnConnectivityChanged(void* arg, grpc_error* error) { @@ -307,13 +303,12 @@ class ConnectedSubchannelStateWatcher static void OnHealthChanged(void* arg, grpc_error* error) { auto* self = static_cast(arg); - MutexLock health_state_lock(&self->mu_); + grpc_subchannel* c = self->subchannel_; + MutexLock lock(&c->mu); if (self->health_state_ == GRPC_CHANNEL_SHUTDOWN) { self->Unref(); return; } - grpc_subchannel* c = self->subchannel_; - MutexLock lock(&c->mu); if (self->last_connectivity_state_ == GRPC_CHANNEL_READY) { grpc_connectivity_state_set(&c->state_and_health_tracker, self->health_state_, GRPC_ERROR_REF(error), @@ -330,8 +325,6 @@ class ConnectedSubchannelStateWatcher grpc_core::OrphanablePtr health_check_client_; grpc_closure on_health_changed_; grpc_connectivity_state health_state_ = GRPC_CHANNEL_CONNECTING; - // Ensure atomic change to health_check_client_ and health_state_. - gpr_mu mu_; }; } // namespace grpc_core