当前位置: 首页>>代码示例>>C++>>正文


C++ Coroutine类代码示例

本文整理汇总了C++中Coroutine的典型用法代码示例。如果您正苦于以下问题:C++ Coroutine类的具体用法?C++ Coroutine怎么用?C++ Coroutine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Coroutine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: runCorEvent

void CoroutineManager::runCorEvent(VarisEvent* event){
	size_t workerNumber = event->getCoroutine()->getId();
	Coroutine* coroutine = &(coroutines_[workerNumber]);
	lastCoroutine_ = curCoroutine_ ;
	curCoroutine_ = coroutine->getId();
	event->callback();
}
开发者ID:cheeseH,项目名称:varisev,代码行数:7,代码来源:coroutinemanager.cpp

示例2: while

void XsimCore::startSim() {

    while (!futureEvents.isEmpty()) {
        TimeSliceEvent* event = futureEvents.getNextEvent();
        time = event->getTime();
        std::cout << "Time: " << time << std::endl;

        while (!event->isEmpty()) {
            // Execute coroutines
            while (!event->isCoroutinesEmpty()) {
                Coroutine* coroutine = event->popNextCoroutine();
                // Execute coroutine if it is not already running.
                if (coroutine->isFinished()) {
                    coroutine->reset();
                }
                coroutine->start();
            }

            // Execute functions
            while (!event->isFunctionsEmpty()) {
                FunctionPtr function = event->popNextFunction();
                // Execute function
                function(functionUserData[function]);
            }
        }

        futureEvents.removeFirstEvent();
    }

}
开发者ID:getvictor,项目名称:xsim-kernel,代码行数:30,代码来源:XsimCore.cpp

示例3: while

//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);
	}
}
开发者ID:cheeseH,项目名称:varisev,代码行数:10,代码来源:coroutinemanager.cpp

示例4: coroutine_trampoline

static void CALLBACK coroutine_trampoline(void *co_)
{
    Coroutine *co = co_;

    while (true) {
        co->entry(co->entry_arg);
        qemu_coroutine_switch(co, co->caller, COROUTINE_TERMINATE);
    }
}
开发者ID:0bliv10n,项目名称:s2e,代码行数:9,代码来源:coroutine-win32.c

示例5: Detach

void Detach() {
    Coroutine *Next = Current->Caller;
    if (Next)  
        Current->Caller = Next->Callee = 0;
    else {
        Next = &Main; 
        while (Next->Callee)
            Next = Next->Callee;
    }
    Next->Enter(); 
}
开发者ID:perezite,项目名称:sandbox,代码行数:11,代码来源:coroutine.cpp

示例6: assert

// virtual
void Subroutine::Invoke( string& funcName ){
	assert( this->m_freeList.size() > 0 );
	Coroutine* c = this->m_freeList.back();
	m_freeList.pop_back();
	assert( c );
	this->m_activeList.push_back( c );
	c->executeFunction( funcName );
	if( c->m_state == STATE_IDLE ){
		this->m_activeList.remove( c );
		this->m_freeList.push_back( c );
	}
}
开发者ID:SenchaK,项目名称:ScriptEngine,代码行数:13,代码来源:vm_assembler.cpp

示例7: smallStack

void tst_basic::smallStack()
{
    using namespace StackTests;

    Coroutine *c = Coroutine::build(&simpleCoroutine);
    c->createStack(1000);
    counter = 0;
    QCOMPARE(c->cont(), true);
    QCOMPARE(counter, 1);
    QCOMPARE(c->cont(), true);
    QCOMPARE(counter, 2);
    delete c;
}
开发者ID:ckamm,项目名称:qt-coroutine,代码行数:13,代码来源:tst_basic.cpp

示例8: while

// virtual
void Subroutine::OnUpdate(){
	list<Coroutine*>::iterator iter = this->m_activeList.begin();
	while( iter != this->m_activeList.end() ){
		Coroutine* c = *iter;
		c->execute();
		if( c->m_state == STATE_IDLE ){
			iter++;
			this->m_activeList.remove( c );
			this->m_freeList.push_back( c );
			continue;
		}
		iter++;
	}
}
开发者ID:SenchaK,项目名称:ScriptEngine,代码行数:15,代码来源:vm_assembler.cpp

示例9: sleep

	bool CoroutineService::sleep(const int64_t secs){
		Coroutine* cr =Coroutine::Running();
		if(!cr){
			WARN("service %s(%lld) fail to sleep, in main thread", name(), (long long)m_id);
			return false;
		}
		if(m_processing_command){
			WARN("service %s(%lld) fail to sleep, in processing command", name(), (long long)m_id);
			return false;
		}
		const int64_t cr_id =cr->getId();
		m_sleeper_table->set(cr_id, SafeNew<Int64>(DateTime::Now() + secs));
		ASSERT(cr->yield(0, -1));
		m_sleeper_table->remove(cr_id);
		return true;
	}
开发者ID:fast01,项目名称:winner,代码行数:16,代码来源:CoroutineService.cpp

示例10: WARN

	int64_t CoroutinePool::go(Coroutine::PFN_COROUTINE_TASK pfn, Object* arg, int64_t& cr_id){
		if(m_cleaning){
			WARN("coroutine pool go failed, cleaning");
			return -ErrorCode::SYSTEM_ERROR;
		}
		if(!pfn){
			return -ErrorCode::INVALID_ARG;
		}
		// prepare
		Coroutine* cr =_prepare_coroutine(pfn, arg);
		const int64_t result =_resume(cr, 0, 0);
		if(result == Coroutine::STATUS_WAITING){
			cr_id =cr->getId();
		}
		return result;
	}
开发者ID:fast01,项目名称:winner,代码行数:16,代码来源:CoroutinePool.cpp

示例11: GENERATE_ID

	/** helper **/
	Coroutine* CoroutinePool::_prepare_coroutine(Coroutine::PFN_COROUTINE_TASK pfn, Object* arg){
		// prepare coroutine
		GENERATE_ID(m_coroutine_id);
		Coroutine* cr =0;
		if(m_idle_coroutine_list->size() > 0){
			cr =dynamic_cast< Coroutine* >(m_idle_coroutine_list->back());
			m_active_coroutine_table->set(m_coroutine_id, cr);
			m_idle_coroutine_list->pop_back();
		}
		else{
			cr =SafeNew<Coroutine>(this);
			m_active_coroutine_table->set(m_coroutine_id, cr);
		}
		// set status
		cr->setId(m_coroutine_id);
		cr->setTask(pfn, arg);
		return cr;
	}
开发者ID:fast01,项目名称:winner,代码行数:19,代码来源:CoroutinePool.cpp

示例12: log_debug

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);
    }
}
开发者ID:hanguangming,项目名称:Blitz,代码行数:44,代码来源:servlet.cpp

示例13: coroutine_trampoline

static void coroutine_trampoline(int i0, int i1)
{
    union cc_arg arg;
    CoroutineUContext *self;
    Coroutine *co;

    arg.i[0] = i0;
    arg.i[1] = i1;
    self = arg.p;
    co = &self->base;

    /* Initialize longjmp environment and switch back the caller */
    if (!sigsetjmp(self->env, 0)) {
        siglongjmp(*(sigjmp_buf *)co->entry_arg, 1);
    }

    while (true) {
        co->entry(co->entry_arg);
        qemu_coroutine_switch(co, co->caller, COROUTINE_TERMINATE);
    }
}
开发者ID:lkzhd,项目名称:glusterfs-annotation,代码行数:21,代码来源:coroutine-ucontext.c

示例14: readScript

static void readScript(Coroutine<const char*>& self)
{
    LineEditor* console = LineEditor::Get();
    console->Open();
    std::string line;
    do {
        line = console->Prompt("> ");
        if (line.empty())
            continue;
        self.yield(line.c_str());
    } while (true);
}
开发者ID:zalemwoo,项目名称:mordor-v8,代码行数:12,代码来源:md_runner.cpp

示例15: ASSERT

	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();
	}
开发者ID:fast01,项目名称:winner,代码行数:25,代码来源:CoroutinePool.cpp


注:本文中的Coroutine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。