-
-/* callback: context fetching */
-static ex_ctx_t *__context_ex_ctx(void)
-{
- return current_context->exception;
-}
-
-/* callback: termination */
-static void __context_ex_terminate(xbt_ex_t * e)
-{
- xbt_ex_display(e);
-
- abort();
- /* FIXME: there should be a configuration variable to choose this
- if(current_context!=init_context)
- __context_exit(current_context, e->value);
- else
- abort();
- */
-}
-
-/** \name Functions
- * \ingroup XBT_context
- */
-/* @{ */
-/** Context module initialization
- *
- * \warning It has to be called before using any other function of this module.
- */
-void xbt_context_init(void)
-{
- if (!current_context) {
- current_context = init_context = xbt_new0(s_xbt_context_t, 1);
- DEBUG1("Init Context (%p)", init_context);
-
- init_context->iwannadie = 0; /* useless but makes valgrind happy */
- init_context->exception = xbt_new(ex_ctx_t, 1);
- XBT_CTX_INITIALIZE(init_context->exception);
- __xbt_ex_ctx = __context_ex_ctx;
- __xbt_ex_terminate = __context_ex_terminate;
- context_to_destroy =
- xbt_swag_new(xbt_swag_offset(*current_context, hookup));
- context_living =
- xbt_swag_new(xbt_swag_offset(*current_context, hookup));
- xbt_swag_insert(init_context, context_living);
-#ifdef CONTEXT_THREADS
- creation_mutex = xbt_os_mutex_init();
- creation_cond = xbt_os_cond_init();
-#endif
- }
-}
-
-/** Garbage collection
- *
- * Should be called some time to time to free the memory allocated for contexts
- * that have finished executing their main functions.
- */
-void xbt_context_empty_trash(void)
-{
- xbt_context_t context = NULL;
- DEBUG1("Emptying trashbin (%d contexts to free)",
- xbt_swag_size(context_to_destroy));
- while ((context = xbt_swag_extract(context_to_destroy)))
- xbt_context_free(context);
-}
-