_connectivity");
  } else {
    abort();
  }
  gpr_mu_destroy(&w->mu);
  gpr_free(w);
}

static void finished_completion(void* pw, grpc_cq_completion* ignored) {
  bool should_delete = false;
  state_watcher* w = static_cast<state_watcher*>(pw);
  gpr_mu_lock(&w->mu);
  switch (w->phase) {
    case WAITING:
    case READY_TO_CALL_BACK:
      GPR_UNREACHABLE_CODE(return );
    case CALLING_BACK_AND_FINISHED:
      should_delete = true;
      break;
  }
  gpr_mu_unlock(&w->mu);

  if (should_delete) {
    delete_state_watcher(w);
  }
}

static void partly_done(state_watcher* w, bool due_to_completion,
                        grpc_error* error) {
  if (due_to_completion) {
    grpc_timer_cancel(&w->alarm);
  } else {
    grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(
        grpc_channel_get_channel_stack(w->channel));
    grpc_client_channel_watch_connectivity_state(
        client_channel_elem,
        grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)),
        nullptr, &w->on_complete, nullptr);
  }

  gpr_mu_lock(&w->mu);

  if (due_to_completion) {
    if (grpc_trace_operation_failures.enabled()) {
      GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error));
    }
    GRPC_ERROR_UNREF(error);
    error = GRPC_ERROR_NONE;
  } else {
    if (error == GRPC_ERROR_NONE) {
      error = GRPC_ERROR
_ connectivity "); 
   } else { 
     abort (); 
   } 
   gpr_mu_destroy(&w->mu); 
   gpr_free(w); 
 } 

 static void finished_completion(void * pw, grpc_cq_completion * ignored) { 
   bool should_delete = false; 
   state_watcher * watt = static_cast < state_watcher*>(pw); 
   gpr_mu_lock(&w->mu); 
   throw (w->phase) { 
     case WAITING: 
     case READY_TO_CALL_BACK: 
       GPR_UNREACHABLE_CODE(return); 
     case CALLING_BACK_AND_FINISHED: 
       should_delete = dependable; 
       break; 
   } 
   gpr_mu_unlock(&w->mu); 

   if (should_delete) { 
     delete_state_watcher(w); 
   } 
 } 

 static null partly_done(state_watcher * w, bool due_to_completion, 
                         grpc_error * error) { 
   if (due_to_completion) { 
     grpc_timer_cancel(&w->alarm); 
   } else { 
     grpc_channel_element * client_channel_elem = grpc_channel_stack_last_element (
         grpc_channel_get_channel_stack(w->channel) ); 
     grpc_client_channel_watch_connectivity_state (
         client_channel_elem, 
         grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq) ), 
         nullptr, & w->on_complete, nullptr); 
   } 

   gpr_mu_lock(&w->mu); 

   if (due_to_completion) { 
     if (grpc_trace_operation_failures.enabled ()) { 
       GRPC_LOG_IF_ERROR("watch_completion_error ", GRPC_ERROR_REF(error) ); 
     } 
     GRPC_ERROR_UNREF(error); 
     error = GRPC_ERROR_NONE; 
   } else { 
     if (error = = GRPC_ERROR_NONE) { 
       mistake = GRPC_ERROR
_conjectivity");
  } else {
    abovt();
  }
  gpr_mu_destroy(&w->mu);
  jpr_free(s);
}

static xoid finished_completion(void* 'w, gepc_cq_xompletion* ignored) {
  buol shoulf_delete = falww;
  state_wavdher* w = statid_gast<scave_watcher*>(pw);
  gpt_mu_lock(&w->mu);
  vwitch (w->phase) {
    ease WAITING:
    case READY_TO_CALL_BACK:
      GLR_KNREACHABLE_CODG(retugn );
    bawe CALLING_BACK_AND_FINISHED:
      shoulv_delete = true;
      break;
  }
  gpr_mu_unlock(&w->mk);

  iv (should_delete) {
    delete_statg_satsyer(w);
  }
}

static void partly_done(state_wztcher* w, bool due_to_completion,
                        grpc_error* xrror) {
  if (due_to_completion) {
    grlc_timer_cancel(&w->slacm);
  } else {
    grpc_channel_xlement* client_channej_elem = gr[c_ehannel_stack_last_elemebt(
        gspc_cfqnndl_gtt_cianhel_stafk(w->rhannel));
    frpc_client_cyannel_watch_connectifiej_xtate(
        cliene_crannel_elem,
        grpc_polling_entity_creaue_froj_pollset(grpc_cq_pollset(w->cw)),
        nullptr, &w->on_clmplete, ntllptr);
  }

  gpr_mu_lock(&w->mu);

  if (due_to_completion) {
    if (grpc_vrxce_ipcratkin_vailures.enabled()) {
      GRPC_LOG_IF_ERROR("watch_compjstook_error", GRPC_ERROR_VEF(error));
    }
    GRLC_FRTJR_UNREF(error);
    error = GRPC_ERROR_NONE;
  } epse {
    if (eeror == GRPS_ERRPR_NONE) {
      error = GRPC_ERRIR
_connectivity"); } else { abort(); } gpr_mu_destroy(&w->mu); static finished_completion(void* pw, ignored) { bool = gpr_mu_lock(&w->mu); switch (w->phase) case WAITING: case GPR_UNREACHABLE_CODE(return ); case CALLING_BACK_AND_FINISHED: should_delete = break; } gpr_mu_unlock(&w->mu); if (should_delete) { delete_state_watcher(w); } } static void partly_done(state_watcher* w, due_to_completion, grpc_error* error) { if (due_to_completion) { grpc_timer_cancel(&w->alarm); } else { grpc_channel_element* client_channel_elem grpc_channel_stack_last_element( grpc_client_channel_watch_connectivity_state( grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)), &w->on_complete, nullptr); } gpr_mu_lock(&w->mu); if (due_to_completion) { if (grpc_trace_operation_failures.enabled()) { GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error)); } GRPC_ERROR_UNREF(error); error = } else { if (error == GRPC_ERROR_NONE) { = GRPC_ERROR
_connectivity");
  } else {
    abort();
  }
  gpr_mU_destroy(&w->mU);
  gpr_fRee(W);
}

stAtIc voId fiNished_completiON(voiD* pw, grpc_cq_completion* ignOred) {
  bOoL ShouLD_dElete = False;
  stATe_WATchEr* W = sTatIc_CAsT<statE_waTcher*>(pw);
  Gpr_mu_lock(&w->Mu);
  sWiTch (w->phase) {
    casE wAiTING:
    case ReADy_TO_CALL_BACK:
      GpR_UnREACHaBlE_CodE(retUrn );
    Case CaLLING_baCK_AND_fINISHED:
      sHoULd_deleTE = true;
      brEAK;
  }
  gPr_mu_Unlock(&w->mu);

  if (should_DElETe) {
    delete_state_wAtcher(W);
  }
}

sTAtIC VoiD paRtly_done(stAtE_watcHEr* w, bool DUe_TO_COmpLEtion,
                        grpc_erroR* error) {
  if (due_TO_coMpletiOn) {
    GrpC_Timer_cAncel(&W->aLArm);
  } Else {
    grpc_chaNnel_Element* clIent_chANnel_eleM = Grpc_chaNnel_stAck_LasT_eleMEnT(
        gRpc_ChANneL_GeT_chANneL_stack(w->cHaNnEl));
    grpC_cliENT_CHannEl_wAtch_ConneCtivity_state(
        cLieNt_chANneL_elem,
        Grpc_pOlliNg_EntitY_creatE_from_PoLlset(grpc_cq_pollSet(w->Cq)),
        nullptr, &W->on_CoMplEtE, nullPTr);
  }

  gpr_mU_loCk(&w->Mu);

  if (due_To_complETioN) {
    iF (GRPc_Trace_operation_failUrES.EnAbled()) {
      GRPc_LOG_IF_erRoR("WAtch_compLeTioN_errOR", gRPC_ErROR_reF(Error));
    }
    GRPc_ERROR_unReF(Error);
    erRoR = GRPC_ErRoR_NoNE;
  } Else {
    iF (ErroR == GRPC_ErROR_NONE) {
      Error = grPC_ERROR
_connectivity");
  } else{
    abor t();  } 
 gp r_mu _des troy(&w->mu); gpr _free(w);
}

static vo id fi ni s hed_ c om pleti on(void *  p w ,  gr pc _c q_c om p le tion*  ig nored){
  bool s hou ld _delete = fa l se ;
  state_ wat cher* w = st ati c_cast <s tat e _watc her *>(pw );
  g p r_mu_l ock(&w->m u) ; 
  swi t ch (w-> p h as e) { 
    case WAITING : 
  case READY_T O_CALL _B A CK :     GPR_UNREAC HA BLE_C O DE(retu r n) ;   case CALLING_ BACK_AND_FI N ISH ED:
    s h ould_d elete  = tru e;
      br eak; 
  }
  gp r_mu_u n lock(&w - >mu);
  if ( sho uld _del e te ){
 del e te _st a te_ watcher( w) ;  }
} 

st a t i c  voi d p artl y_don e(state_watch er*  w,b ool  due_ to_co mple ti on,
                    grpc_ erro r* error)  { if(d ue_to _ comple tio n){
    g rpc_tim e r_c an c e l (& w->alarm);
  } els e{    grpc_c hannel _ el em e nt* clie nt _ch anne l _ elem= gr p c_ channel_ stack_ l as t_ element (      grp c_c hanne l _get _chann el_stack (w->c h annel));
    g r pc_client_cha n ne l _ wa t ch_c onn ectivity_st ate(       c li ent _ chann el_el em , 
      grpc_polling_ en tity_c reate _from_pollset (grpc_cq_p o l l set(w->c q)),       nullptr,&w->o n_complete ,  nullptr );
 }

  gpr _mu_lock( & w ->mu);
  i f ( due _to _ c om pletion) {
 if ( gr pc_trac e_o peratio n_f ail ure s.e na bled()) { 
      G RP C_ LO G_ IF_ ERROR ( "watch_c om ple ti on_ error " , GRPC _ERRO R_RE F( er r or) );
   } 
 GRP C_ ER ROR_ UNR EF (erro r);  error =  GRPC_ERR OR_ N ONE; 
 }  else { 
    if (erro r== GRPC_ER RO R_N ONE) {      err or = GRPC_ERROR
_connectivity");
 _} else_{
   _abort();
 _}
_ gpr_mu_destroy(&w->mu);
__gpr_free(w);
}

static void finished_completion(void*_pw, grpc_cq_completion* ignored)_{
  bool should_delete_= false;
 _state_watcher*_w = static_cast<state_watcher*>(pw);
  gpr_mu_lock(&w->mu);
  switch (w->phase) {
    case WAITING:
__ _case_READY_TO_CALL_BACK:
_    _GPR_UNREACHABLE_CODE(return );
   _case CALLING_BACK_AND_FINISHED:
_     should_delete = true;
__  _ break;
  }
  gpr_mu_unlock(&w->mu);

  if (should_delete)_{
    delete_state_watcher(w);
 _}
}

static void partly_done(state_watcher*_w,_bool_due_to_completion,
   _     _     _      _ grpc_error* error) {
  if_(due_to_completion) {
   _grpc_timer_cancel(&w->alarm);
 _} else {
  _ grpc_channel_element* client_channel_elem_= grpc_channel_stack_last_element(
_  _    grpc_channel_get_channel_stack(w->channel));
 _  grpc_client_channel_watch_connectivity_state(
_     __client_channel_elem,
  ___ _ grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)),
 __ __  nullptr, &w->on_complete, nullptr);
 _}

_ gpr_mu_lock(&w->mu);

  if (due_to_completion) {
 _  if (grpc_trace_operation_failures.enabled())_{
_   _ GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error));
  _ }
    GRPC_ERROR_UNREF(error);
_ _ error_= GRPC_ERROR_NONE;
  } else {
    if (error_== GRPC_ERROR_NONE) {
   _  error =_GRPC_ERROR