void NamingServiceThread::Actions::EndWait(int error_code) { if (bthread_id_trylock(_wait_id, NULL) == 0) { _wait_error = error_code; _has_wait_error.store(true, butil::memory_order_release); bthread_id_unlock_and_destroy(_wait_id); } }
void Sender::Clear() { if (_main_cntl == NULL) { return; } delete _alloc_resources[1].response; delete _alloc_resources[1].sub_done; _alloc_resources[1] = Resource(); const CallId cid = _main_cntl->call_id(); _main_cntl = NULL; if (_user_done) { _user_done->Run(); } bthread_id_unlock_and_destroy(cid); }
int Stream::TriggerOnWritable(bthread_id_t id, void *data, int error_code) { WritableMeta *wm = (WritableMeta*)data; if (wm->has_timer) { bthread_timer_del(wm->timer); } wm->error_code = error_code; if (wm->new_thread) { const bthread_attr_t* attr = FLAGS_usercode_in_pthread ? &BTHREAD_ATTR_PTHREAD : &BTHREAD_ATTR_NORMAL; bthread_t tid; if (bthread_start_background(&tid, attr, RunOnWritable, wm) != 0) { LOG(FATAL) << "Fail to start bthread" << berror(); RunOnWritable(wm); } } else { RunOnWritable(wm); } return bthread_id_unlock_and_destroy(id); }