2 * UCW Library -- Configuration files: Contexts
4 * (c) 2012 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
12 #include <ucw/conf-internal.h>
13 #include <ucw/threads.h>
15 static struct cf_context cf_default_context;
18 cf_init_context(struct cf_context *cc)
20 cc->enable_journal = 1;
21 clist_init(&cc->conf_entries);
27 struct cf_context *cc = xmalloc_zero(sizeof(*cc));
33 cf_delete_context(struct cf_context *cc)
35 ASSERT(!cc->is_active);
36 ASSERT(cc != &cf_default_context);
37 struct cf_context *prev = cf_switch_context(cc);
39 cf_switch_context(prev);
45 cf_switch_context(struct cf_context *cc)
47 struct ucwlib_context *uc = ucwlib_thread_context();
48 struct cf_context *prev = uc->cf_context;
53 ASSERT(!cc->is_active);
60 static void CONSTRUCTOR_WITH_PRIORITY(10100)
61 cf_init_default_context(void)
63 cf_init_context(&cf_default_context);
64 ucwlib_thread_context()->cf_context = &cf_default_context;
65 cf_default_context.is_active = 1;
69 cf_obtain_context(void)
71 return cf_get_context();