Example #1
0
void check_time_out(sche_t s,uint32_t now)
{
	coro_t co;
	for( ; ;)
	{
		struct heapele *ele = minheap_min(s->_minheap);
		if(!ele)
			break;
		co = (coro_t)((int8_t*)ele - sizeof(co->next));
		if(co->timeout < now)
			break;
		minheap_popmin(s->_minheap);
		if(co->status != CORO_ACTIVE)
		{
			co->status = CORO_ACTIVE;
			LINK_LIST_PUSH_BACK(s->active_list_1,co);
		}else if(co->status == CORO_DIE)
		{
			coro_destroy(&co);
			if(--s->coro_size == 0)
				s->stop = 1;
			//printf("a coro destroy\n");
		}	
	}
	s->next_check_timeout = now + 200;//check every 200 ms
}
Example #2
0
void sche_destroy(sche_t *s)
{
	struct double_link_node *dlnode = NULL;
	while(dlnode = double_link_pop(&(*s)->coros))
	{
		coro_t co = (coro_t)dlnode+sizeof(struct list_node);
		coro_destroy(&co);
	}
	
	LINK_LIST_DESTROY(&((*s)->active_list_1));
	LINK_LIST_DESTROY(&((*s)->active_list_2));
	minheap_destroy(&((*s)->_minheap));
	coro_destroy(&(*s)->co);
	free(*s);
	*s = NULL;
}
Example #3
0
ContextSwitcher::~ContextSwitcher()
{
    qDebug() << "Deleting a context switcher ";
    /* Normally, all contexts should have disappeared before though */
    finish();

    //to suppress "no effect" warning
    (void) coro_destroy(&main_context);
    qDebug() << "End Deleting a context switcher ";
}
Example #4
0
void sche_schedule(sche_t s)
{
	uint32_t now = GetCurrentMs();
	if(now >= s->next_check_timeout)
		check_time_out(s,now);

	if(link_list_is_empty(s->active_list_1) && link_list_is_empty(s->active_list_2))
	{
		if(s->idel)
			s->idel(s->idel_arg);
		else
			sleepms(50);
	}
	else
	{
		coro_t co = _sche_next(s,s->co);
		if(co->status == CORO_DIE && co->_heapele.index == 0)
		{
			coro_destroy(&co);
			printf("a coro destroy\n");
		}
	}
}