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(); }
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); } }