struct dill_ctx *dill_getctx_(void) { int rc = pthread_once(&dill_keyonce, dill_makekey); dill_assert(rc == 0); struct dill_ctx *ctx = pthread_getspecific(dill_key); if(dill_fast(ctx)) return ctx; ctx = malloc(sizeof(struct dill_ctx)); dill_assert(ctx); rc = dill_ctx_now_init(&ctx->now); dill_assert(rc == 0); rc = dill_ctx_cr_init(&ctx->cr); dill_assert(rc == 0); rc = dill_ctx_handle_init(&ctx->handle); dill_assert(rc == 0); rc = dill_ctx_stack_init(&ctx->stack); dill_assert(rc == 0); rc = dill_ctx_pollset_init(&ctx->pollset); dill_assert(rc == 0); if(dill_ismain()) { dill_main = ctx; rc = atexit(dill_ctx_atexit); dill_assert(rc == 0); } rc = pthread_setspecific(dill_key, ctx); dill_assert(rc == 0); return ctx; }
static void dill_ctx_init_(struct dill_ctx *ctx) { dill_assert(ctx->initialized == 0); ctx->initialized = 1; int rc = dill_ctx_now_init(&ctx->now); dill_assert(rc == 0); rc = dill_ctx_cr_init(&ctx->cr); dill_assert(rc == 0); rc = dill_ctx_handle_init(&ctx->handle); dill_assert(rc == 0); rc = dill_ctx_stack_init(&ctx->stack); dill_assert(rc == 0); rc = dill_ctx_pollset_init(&ctx->pollset); dill_assert(rc == 0); rc = dill_ctx_fd_init(&ctx->fd); dill_assert(rc == 0); }
struct dill_ctx *dill_ctx_init(void) { int rc = dill_ctx_now_init(&dill_ctx_.now); dill_assert(rc == 0); rc = dill_ctx_cr_init(&dill_ctx_.cr); dill_assert(rc == 0); rc = dill_ctx_handle_init(&dill_ctx_.handle); dill_assert(rc == 0); rc = dill_ctx_stack_init(&dill_ctx_.stack); dill_assert(rc == 0); rc = dill_ctx_pollset_init(&dill_ctx_.pollset); dill_assert(rc == 0); rc = atexit(dill_ctx_atexit); dill_assert(rc == 0); dill_ctx_.initialized = 1; return &dill_ctx_; }
struct dill_ctx *dill_ctx_init(void) { int rc = dill_ctx_now_init(&dill_ctx_.now); dill_assert(rc == 0); rc = dill_ctx_cr_init(&dill_ctx_.cr); dill_assert(rc == 0); rc = dill_ctx_handle_init(&dill_ctx_.handle); dill_assert(rc == 0); rc = dill_ctx_stack_init(&dill_ctx_.stack); dill_assert(rc == 0); rc = dill_ctx_pollset_init(&dill_ctx_.pollset); dill_assert(rc == 0); rc = pthread_once(&dill_keyonce, dill_makekey); dill_assert(rc == 0); if(dill_ismain()) { dill_main = &dill_ctx_; rc = atexit(dill_ctx_atexit); dill_assert(rc == 0); } rc = pthread_setspecific(dill_key, &dill_ctx_); dill_assert(rc == 0); dill_ctx_.initialized = 1; return &dill_ctx_; }