示例#1
0
static inline
struct p7r_stack_hint *p7r_stack_hint_new_blank() {
    __auto_type allocator = p7r_root_alloc_get_proxy();
    struct p7r_stack_hint *hint = scraft_allocate(allocator, sizeof(struct p7r_stack_hint));
    if (unlikely(hint == NULL))
        return NULL;
    return hint;
}
示例#2
0
static
struct p7_coro_cntx *p7_coro_cntx_new_(void (*entry)(void *), void *arg, size_t stack_size, struct p7_limbo *limbo) {
    __auto_type allocator = p7_root_alloc_get_proxy();
    struct p7_coro_cntx *cntx = scraft_allocate(allocator, (sizeof(struct p7_coro_cntx) + sizeof(void *) * stack_size + STACK_RESERVED_SIZE));
    if (cntx != NULL) {
        cntx->stack_size = stack_size;
        if (stack_size > 0)
            (cntx->uc.uc_stack.ss_sp = cntx->stack), (cntx->uc.uc_stack.ss_size = stack_size);
        cntx->uc.uc_link = (limbo != NULL) ? &(limbo->cntx->uc) : NULL;
        // TODO invalidate reserved area of coro's stack
        if (entry != NULL) {
            getcontext(&(cntx->uc));
            makecontext(&(cntx->uc), (void (*)()) entry, 1, arg);
        }
    }
    return cntx;
}
示例#3
0
static
struct p7_coro *p7_coro_new_(void (*entry)(void *), void *arg, size_t stack_size, unsigned carrier_id, struct p7_limbo *limbo) {
    struct p7_coro *coro = NULL;
    struct p7_coro_cntx *cntx = p7_coro_cntx_new_(entry, arg, stack_size, limbo);
    if (cntx != NULL) {
        __auto_type allocator = p7_root_alloc_get_proxy();
        coro = scraft_allocate(allocator, (sizeof(struct p7_coro)));
        if (coro != NULL) {
            (coro->carrier_id = carrier_id), (coro->cntx = cntx), (coro->following = NULL);
            (coro->func_info.entry = entry), (coro->func_info.arg = arg);
            coro->timedout = coro->resched = 0;
            coro->status = P7_CORO_STATUS_ALIVE;
            coro->decay = 0;
            coro->trapper = NULL;
            coro->fd_waiting = -1;
            coro->cleanup_info.arg = NULL;
            coro->cleanup_info.cleanup = NULL;
            (coro->mailbox_cleanup = NULL), (coro->mailbox_cleanup_arg = NULL);
            init_list_head(&(coro->mailbox));
        }
    }
    return coro;
}