本文整理汇总了C++中Coroutine::resume方法的典型用法代码示例。如果您正苦于以下问题:C++ Coroutine::resume方法的具体用法?C++ Coroutine::resume怎么用?C++ Coroutine::resume使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coroutine
的用法示例。
在下文中一共展示了Coroutine::resume方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: finalize
void CoroutinePool::finalize(){
m_cleaning =true;
// clean idle list
for(int64_t i=0; i<m_idle_coroutine_list->size(); ++i){
Coroutine* cr =static_cast< Coroutine* >(m_idle_coroutine_list->get(i));
cr->resume(SafeNew<Error>(ErrorCode::COROUTINE_CLEAN), 0);
ASSERT(cr->getStatus() == Coroutine::STATUS_DEAD);
}
CLEAN_POINTER(m_idle_coroutine_list);
// clean active table
Hash* active_cr_tb =m_active_coroutine_table;
m_active_coroutine_table =0;
HashIterator* it =static_cast< HashIterator* >(active_cr_tb->iterator());
while(it->next()){
Coroutine* cr =static_cast< Coroutine* >(it->getValue());
cr->resume(SafeNew<Error>(ErrorCode::COROUTINE_CLEAN), 0);
ASSERT(cr->getStatus() == Coroutine::STATUS_DEAD);
}
CLEAN_POINTER(active_cr_tb);
// super
Super::finalize();
}
示例2: execute
void ServletManager::execute(unsigned servlet_id, unsigned seq, unsigned size, Peer *peer) noexcept {
if (servlet_id == GX_KEEPALIVE_SERVLET) {
if (seq || size) {
peer->close();
return;
}
return;
}
auto it = _map.find(servlet_id);
if (it == _map.end()) {
log_debug("servlet 0x%x not registered.", servlet_id);
peer->close();
return;
}
ServletBase *servlet = it->second;
Coroutine *co;
bool use_co = servlet->use_coroutine();
if (use_co) {
co = Coroutine::spawn(routine, peer);
}
else {
co = Coroutine::self();
}
if (!co) {
log_debug("no coroutine available.");
peer->input().read(nullptr, size);
return;
}
co->context()->_servlet = servlet;
co->context()->_seq = seq;
co->context()->_size = size;
if (use_co) {
co->resume();
}
else {
routine(peer);
}
}