예제 #1
0
rstatus_t eventmgr_init(eventmanager* eventmgr, int nevents) 
{
    eventmgr = cs_alloc(sizeof(eventmanager));
    if(eventmgr == nil) {
        return M_ERR;
    }
    eventmgr->epfd = epoll_create(1024);	/*1024 will be ignored*/
    if(eventmgr->epfd == -1) {
        cs_free(eventmgr);
        return M_ERR;
    }
    eventmgr->nevent = nevents;
    eventmgr->events = cs_calloc(eventmgr->nevent, sizeof(*eventmgr->events));
    if(eventmgr->events == nil) {
        cs_free(eventmgr);
        return M_ERR;
    }	
    eventmgr->evmgr_coro = coro_alloc(&event_loop, eventmgr, DEFAULT_STACK_SIZE);
    if(eventmgr->evmgr_coro == nil) {
        cs_free(eventmgr);
        cs_free(eventmgr->events);
        return M_ERR; 
    }
    eventmgr->stop = 0;
    return M_OK;
}
예제 #2
0
파일: coro.c 프로젝트: wbyoung/coro
coro *coro_new(coro_start start, void *context) {
	coro *self = coro_alloc();
	
	self->refcount = 1;
	if (start) {
		self->context = context;
		self->start = start;
		self->stack_size = CORO_DEFAULT_STACK_SIZE;
		self->stack = calloc(1, self->stack_size);
		coro_setup(self);
	}
	return self;
}
예제 #3
0
rstatus_t coro_spawn(scheduler *sched, void (*fn)(void *arg), void *arg, size_t stacksize)
{
    coroutine *coro = coro_alloc(fn, arg, stacksize);
    if(coro == nil) {
        return M_ERR;
    }
	coro->cid = (coroid_t)coro;
    coro->node.key = (int64_t)coro->cid;
    coro->node.data = (void*)coro;
    coro->status = M_FREE;
    coro->sched = sched;
    sched_register_coro(coro);
    coro_ready(coro);
    return M_OK;
}