Пример #1
0
bool CoroutineManager::doWork(VarisEvent* event){
		Coroutine* cor;
		if((cor = event->getCoroutine())!=NULL &&( event->getListenEventType()&T_COROUTINE)){
			cor->setStatus(BUSY);
			runCorEvent(event);
			return true;
		}
		//no coroutine free
		if(freeCoroutine_.empty()){
			return false;
		}
	if(!(event->getListenEventType()&T_COROUTINE)){
			int tmpCoroutine = freeCoroutine_.top();
			freeCoroutine_.pop();
			ucontext_t* context = coroutines_[tmpCoroutine].getContext();
			context->uc_link = coroutines_[0].getContext();
			Coroutine* coroutine = &(coroutines_[tmpCoroutine]);
			coroutine->setStatus(READY);
			event->setCoroutine(coroutine);
			makecontext(context,(corfunc)(VarisEvent::handle),1,event);
			runCoroutine(tmpCoroutine);
			return true;
	}
	return false;

}
Пример #2
0
//notice
void CoroutineManager::onCoroutineFinished(CoroutineManager* th){
	while(true){
		Coroutine cor = th->coroutines_[th->curCoroutine_];
		cor.setStatus(FREE);
		th->freeCoroutine_.push(th->curCoroutine_);
		th->curCoroutine_ = 0;
		th->runCoroutine(1);
	}
}