int ASYNC_init_pool(size_t max_size, size_t init_size)
{
    async_pool *pool;
    size_t curr_size = 0;

    if (init_size > max_size || max_size == 0) {
        ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ASYNC_R_INVALID_POOL_SIZE);
        return 0;
    }

    if(async_get_pool() != NULL) {
        ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ASYNC_R_POOL_ALREADY_INITED);
        return 0;
    }

    pool = OPENSSL_zalloc(sizeof *pool);
    if (pool == NULL) {
        ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ERR_R_MALLOC_FAILURE);
        return 0;
    }

    pool->jobs = sk_ASYNC_JOB_new_null();
    if (pool->jobs == NULL) {
        ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ERR_R_MALLOC_FAILURE);
        OPENSSL_free(pool);
        return 0;
    }

    pool->max_size = max_size;

    /* Pre-create jobs as required */
    while (init_size) {
        ASYNC_JOB *job;
        job = async_job_new();
        if (job) {
            async_fibre_makecontext(&job->fibrectx);
            job->funcargs = NULL;
            sk_ASYNC_JOB_push(pool->jobs, job);
            curr_size++;
            init_size--;
        } else {
            /*
             * Not actually fatal because we already created the pool, just skip
             * creation of any more jobs
             */
            init_size = 0;
        }
    }
    pool->curr_size = curr_size;

    if (!async_set_pool(pool)) {
        ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ASYNC_R_FAILED_TO_SET_POOL);
        goto err;
    }

    return 1;
err:
    async_free_pool_internal(pool);
    return 0;
}