X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fconf-context.c;h=050e43baaf47fc218e83f74aaf20479d83d14eeb;hb=f17e4350dcf0c033891e52b30b0c32a4a4fed5e0;hp=1584143cb98a24b959dda540935105d2ea084620;hpb=b541de765129b6bf28c5601bb355779652001150;p=libucw.git diff --git a/ucw/conf-context.c b/ucw/conf-context.c index 1584143c..050e43ba 100644 --- a/ucw/conf-context.c +++ b/ucw/conf-context.c @@ -12,27 +12,31 @@ #include #include -#ifndef CONFIG_UCW_DEFAULT_CONFIG -#define CONFIG_UCW_DEFAULT_CONFIG NULL -#endif +static struct cf_context cf_default_context; -#ifndef CONFIG_UCW_ENV_VAR_CONFIG -#define CONFIG_UCW_ENV_VAR_CONFIG NULL -#endif +static void +cf_init_context(struct cf_context *cc) +{ + cc->enable_journal = 1; + clist_init(&cc->conf_entries); +} struct cf_context * cf_new_context(void) { struct cf_context *cc = xmalloc_zero(sizeof(*cc)); - cc->need_journal = 1; - clist_init(&cc->conf_entries); + cf_init_context(cc); return cc; } void -cf_free_context(struct cf_context *cc) +cf_delete_context(struct cf_context *cc) { ASSERT(!cc->is_active); + ASSERT(cc != &cf_default_context); + struct cf_context *prev = cf_switch_context(cc); + cf_revert(); + cf_switch_context(prev); xfree(cc->parser); xfree(cc); } @@ -53,15 +57,16 @@ cf_switch_context(struct cf_context *cc) return prev; } +static void CONSTRUCTOR_WITH_PRIORITY(10100) +cf_init_default_context(void) +{ + cf_init_context(&cf_default_context); + ucwlib_thread_context()->cf_context = &cf_default_context; + cf_default_context.is_active = 1; +} + struct cf_context * cf_obtain_context(void) { - struct ucwlib_context *uc = ucwlib_thread_context(); - if (unlikely(!uc->cf_context)) - { - struct cf_context *cc = cf_new_context(); - uc->cf_context = cc; - cc->is_active = 1; - } - return uc->cf_context; + return cf_get_context(); }