/* * Boot. * Squat app/module is using it */ struct ctx_t * app_boot(struct ctx_t *cur, void *a, void *args) { app_getopt *opts = args; struct app_t *app = a; struct cfg_t *cfg; if(NULL == cur) { if(app->ctx) log(app->ctx, 1, "Alredy got app->ctx!\n"); app->ctx = ctx_new(CTX_STDERR|CTX_BOOT); if (NULL == app->ctx) return NULL; } else app->ctx = cur; cfg = app->ctx->cfg; set_early_log(app->ctx); /* Ok we really really need this very early */ if(NULL == sys_create(app->ctx, "api", T_HASH)) return NULL; /*if(NULL == sys_create(app->ctx, "parser", T_STORE)) return NULL;*/ log(app->ctx, 0, "app boot: %s\n", app->name); /* * Default handler is sig_run * sig_run is responsible of traversing ctx/scope * and run all handlers that are registered */ /*signal(SIGINT, sig_run); signal(SIGHUP, sig_run); signal(SIGTERM, sig_run); signal(SIGSEGV, sig_run); signal(SIGBUS, sig_run);*/ /* reset to default boot options */ if(GET_BIT(app->type, APP_DAEMON)) cfg->basic->daemon = 1; if(GET_BIT(app->type, APP_LOG)) cfg->basic->prio = 1; /* cfg */ cfg->basic->argc = opts->argc; cfg->basic->argv = opts->argv; optind = 1; return app->ctx; }
void start(struct config *config) { assert(config != NULL); assert(config->num_threads > 0); assert(config->port > 0); assert(config->nodes != NULL); assert(config->num_nodes > 0); pthread_t threads[config->num_threads]; struct ctx *ctxs[config->num_threads]; int i; for (i = 0; i < config->num_threads; i++) { if ((ctxs[i] = ctx_new(config->nodes, config->num_nodes, config->port, config->flush_interval)) == NULL) exit(1); pthread_create(&threads[i], NULL, &thread_start, ctxs[i]); } for (i = 0; i < config->num_threads; i++) { pthread_join(threads[i], NULL); ctx_free(ctxs[i]); } }
static void gnome_installer_run_op_async (const gchar **packages, const gchar *options, OpType type, GAsyncReadyCallback callback, gpointer user_data) { ClientCtx *ctx; GSimpleAsyncResult *result; result = g_simple_async_result_new (NULL, callback, user_data, gnome_installer_run_op_async); ctx = ctx_new (type, packages, options != NULL ? options : "", result); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.PackageKit", "/org/freedesktop/PackageKit", type == OP_TYPE_INSTALL ? INSTALL_DBUS_PATH : CHECK_DBUS_PATH, NULL, pkg_kit_proxy_new_cb, ctx); g_object_unref (result); }
int main(int argc, char **argv) { struct timeval stv, etv; struct bundle bundle, *rbundle; ctx_state *rstate; ctx_stack stk; stk.size = 1; assert(ctx_new(&stk) == 0); gettimeofday(&stv, NULL); for (j = 0; j < ITERATIONS; ) test_return(NULL); gettimeofday(&etv, NULL); printf(RFMT, "return", TIME(stv, etv)); gettimeofday(&stv, NULL); for (j = 0; ctx_mark(&bundle.state, NULL, &rstate) < ITERATIONS; ) { if (j == 0) ctx_call(&bundle.state, stk, test_noext); else ctx_jump(rstate, NULL, &bundle.state); } gettimeofday(&etv, NULL); printf(RFMT, "noexts", TIME(stv, etv)); gettimeofday(&stv, NULL); for (j = 0; j < ITERATIONS; ) { if (ctx_mark(&bundle.state, NULL, &rstate) == 0) { if (j == 0) ctx_call(&bundle.state, stk, test_noext); else ctx_jump(rstate, NULL, &bundle.state); } } gettimeofday(&etv, NULL); printf(RFMT, "noextd", TIME(stv, etv)); gettimeofday(&stv, NULL); for (j = 0; ctx_mark(&bundle.state, &bundle.extra, &rbundle) < ITERATIONS; ) { if (j == 0) ctx_call(&bundle, stk, test_ext); else ctx_jump(&rbundle->state, &rbundle->extra, &bundle); } gettimeofday(&etv, NULL); printf(RFMT, "exts", TIME(stv, etv)); gettimeofday(&stv, NULL); for (j = 0; j < ITERATIONS; ) { if (ctx_mark(&bundle.state, &bundle.extra, &rbundle) == 0) { if (j == 0) ctx_call(&bundle, stk, test_ext); else ctx_jump(&rbundle->state, &rbundle->extra, &bundle); } } gettimeofday(&etv, NULL); printf(RFMT, "extd", TIME(stv, etv)); ctx_free(stk); return 0; }