From: mquinson Date: Mon, 13 Jul 2009 18:03:57 +0000 (+0000) Subject: Fix compilation bug when enabling pthreads. X-Git-Tag: SVN~1154 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/062ce26ac2d8afce1a666f908d0bf49c94c1b6c7 Fix compilation bug when enabling pthreads. Move contexts' control API (start, stop, yield, etc) to the context_factory data structure instead of having pointers in each xbt_context data structure for them. This saves a bunch of memory and context creation is a bit faster. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6494 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/simix/xbt_context.c b/src/simix/xbt_context.c index 5159b766a4..8e1a7ae3eb 100644 --- a/src/simix/xbt_context.c +++ b/src/simix/xbt_context.c @@ -86,11 +86,6 @@ void xbt_context_mod_exit(void) xbt_context_t context = NULL; xbt_pfn_context_factory_finalize_t finalize_factory; - /* finalize the context factory */ - finalize_factory = context_factory->finalize; - - (*finalize_factory) (&context_factory); - /* destroy all contexts in the list of contexts to destroy */ xbt_context_empty_trash(); @@ -102,17 +97,21 @@ void xbt_context_mod_exit(void) * the killed contexts are added in the list of the contexts to destroy */ while ((context = xbt_swag_extract(context_living))) - (*(context->kill)) (context); - + (*(context_factory->kill)) (context); /* destroy all contexts in the list of contexts to destroy */ xbt_context_empty_trash(); + /* finalize the context factory */ + finalize_factory = context_factory->finalize; + + (*finalize_factory) (&context_factory); + free(maestro_context); maestro_context = current_context = NULL; /* destroy the lists */ - xbt_swag_free(context_to_destroy); + xbt_swag_free(context_to_destroy); xbt_swag_free(context_living); } } @@ -177,13 +176,13 @@ xbt_context_new(const char *name, /* Argument must be stopped first -- runs in maestro context */ void xbt_context_free(xbt_context_t context) { - (*(context->free)) (context); + (*(context_factory->free)) (context); } void xbt_context_kill(xbt_context_t context) { - (*(context->kill)) (context); + (*(context_factory->kill)) (context); } /** @@ -194,7 +193,7 @@ void xbt_context_kill(xbt_context_t context) */ void xbt_context_start(xbt_context_t context) { - (*(context->start)) (context); + (*(context_factory->start)) (context); } /** @@ -207,7 +206,7 @@ void xbt_context_start(xbt_context_t context) */ void xbt_context_yield(void) { - (*(current_context->yield)) (); + (*(context_factory->yield)) (); } /** @@ -221,13 +220,13 @@ void xbt_context_yield(void) */ void xbt_context_schedule(xbt_context_t context) { - (*(context->schedule)) (context); + (*(context_factory->schedule)) (context); } void xbt_context_stop(int exit_code) { - (*(current_context->stop)) (exit_code); + (*(context_factory->stop)) (exit_code); } int xbt_context_select_factory(const char *name) @@ -284,15 +283,13 @@ xbt_context_init_factory_by_name(xbt_context_factory_t * factory, #endif /* CONTEXT_THREADS */ else if (!strcmp(name, "sysv")) -#ifndef WIN32 +#if !defined(WIN32) && !defined(CONTEXT_THREADS) xbt_ctx_sysv_factory_init(factory); #else THROW0(not_found_error, 0, "Factory 'sysv' does not exist: no System V thread support under Windows"); -#endif - +#endif else THROW1(not_found_error, 0, "Factory '%s' does not exist", name); - } /** Garbage collection @@ -305,5 +302,5 @@ void xbt_context_empty_trash(void) xbt_context_t context = NULL; while ((context = xbt_swag_extract(context_to_destroy))) - (*(context->free)) (context); + (*(context_factory->free)) (context); } diff --git a/src/simix/xbt_context_java.c b/src/simix/xbt_context_java.c index b89b25057d..b40d5e5060 100644 --- a/src/simix/xbt_context_java.c +++ b/src/simix/xbt_context_java.c @@ -80,8 +80,13 @@ void xbt_ctx_java_factory_init(xbt_context_factory_t * factory) (*factory)->create_context = xbt_ctx_java_factory_create_context; (*factory)->finalize = xbt_ctx_java_factory_finalize; - (*factory)->create_maestro_context = - xbt_ctx_java_factory_create_maestro_context; + (*factory)->create_maestro_context = xbt_ctx_java_factory_create_maestro_context; + (*factory)->free = xbt_ctx_java_free; + (*factory)->kill = xbt_ctx_java_kill; + (*factory)->schedule = xbt_ctx_java_schedule; + (*factory)->yield = xbt_ctx_java_yield; + (*factory)->start = xbt_ctx_java_start; + (*factory)->stop = xbt_ctx_java_stop; (*factory)->name = "ctx_java_factory"; } @@ -117,19 +122,10 @@ xbt_ctx_java_factory_create_context(const char *name, xbt_main_func_t code, xbt_ctx_java_t context = xbt_new0(s_xbt_ctx_java_t, 1); context->name = xbt_strdup(name); - context->cleanup_func = cleanup_func; context->cleanup_arg = cleanup_arg; - context->exception = xbt_new(ex_ctx_t, 1); XBT_CTX_INITIALIZE(context->exception); - - context->free = xbt_ctx_java_free; - context->kill = xbt_ctx_java_kill; - context->schedule = xbt_ctx_java_schedule; - context->yield = xbt_ctx_java_yield; - context->start = xbt_ctx_java_start; - context->stop = xbt_ctx_java_stop; context->jprocess = (jobject) startup_arg; context->jenv = get_current_thread_env(); diff --git a/src/simix/xbt_context_private.h b/src/simix/xbt_context_private.h index 6797af1c24..c5a76936d4 100644 --- a/src/simix/xbt_context_private.h +++ b/src/simix/xbt_context_private.h @@ -21,18 +21,6 @@ SG_BEGIN_DECL() /* the following function pointers types describe the interface that all context concepts must implement */ -typedef void (*xbt_pfn_context_free_t) (xbt_context_t); /* function used to destroy the specified context */ - -typedef void (*xbt_pfn_context_kill_t) (xbt_context_t); /* function used to kill the specified context */ - -typedef void (*xbt_pfn_context_schedule_t) (xbt_context_t); /* function used to resume the specified context */ - -typedef void (*xbt_pfn_context_yield_t) (void); /* function used to yield the specified context */ - -typedef void (*xbt_pfn_context_start_t) (xbt_context_t); /* function used to start the specified context */ - -typedef void (*xbt_pfn_context_stop_t) (int); /* function used to stop the current context */ - /* each context type must contain this macro at its begining -- OOP in C :/ */ #define XBT_CTX_BASE_T \ s_xbt_swag_hookup_t hookup; \ @@ -45,13 +33,7 @@ typedef void (*xbt_pfn_context_stop_t) (int); /* function used to stop the cu int argc; \ char **argv; \ void_f_pvoid_t startup_func; \ - void *startup_arg; \ - xbt_pfn_context_free_t free; \ - xbt_pfn_context_kill_t kill; \ - xbt_pfn_context_schedule_t schedule; \ - xbt_pfn_context_yield_t yield; \ - xbt_pfn_context_start_t start; \ - xbt_pfn_context_stop_t stop + void *startup_arg; /* all other context types derive from this structure */ typedef struct s_xbt_context { @@ -89,11 +71,35 @@ typedef int (*xbt_pfn_context_factory_create_maestro_context_t) (xbt_context_t*) /* this function finalize the specified context factory */ typedef int (*xbt_pfn_context_factory_finalize_t) (xbt_context_factory_t*); +/* function used to destroy the specified context */ +typedef void (*xbt_pfn_context_free_t) (xbt_context_t); + +/* function used to kill the specified context */ +typedef void (*xbt_pfn_context_kill_t) (xbt_context_t); + +/* function used to resume the specified context */ +typedef void (*xbt_pfn_context_schedule_t) (xbt_context_t); + +/* function used to yield the specified context */ +typedef void (*xbt_pfn_context_yield_t) (void); + +/* function used to start the specified context */ +typedef void (*xbt_pfn_context_start_t) (xbt_context_t); + +/* function used to stop the current context */ +typedef void (*xbt_pfn_context_stop_t) (int); + /* interface of the context factories */ typedef struct s_xbt_context_factory { xbt_pfn_context_factory_create_maestro_context_t create_maestro_context; xbt_pfn_context_factory_create_context_t create_context; xbt_pfn_context_factory_finalize_t finalize; + xbt_pfn_context_free_t free; + xbt_pfn_context_kill_t kill; + xbt_pfn_context_schedule_t schedule; + xbt_pfn_context_yield_t yield; + xbt_pfn_context_start_t start; + xbt_pfn_context_stop_t stop; const char *name; } s_xbt_context_factory_t; diff --git a/src/simix/xbt_context_sysv.c b/src/simix/xbt_context_sysv.c index 0eb57b88fb..28f5a9fccd 100644 --- a/src/simix/xbt_context_sysv.c +++ b/src/simix/xbt_context_sysv.c @@ -89,13 +89,17 @@ static void xbt_ctx_sysv_ex_terminate(xbt_ex_t * e) void xbt_ctx_sysv_factory_init(xbt_context_factory_t * factory) { - /* context exception */ *factory = xbt_new0(s_xbt_context_factory_t, 1); (*factory)->create_context = xbt_ctx_sysv_factory_create_context; (*factory)->finalize = xbt_ctx_sysv_factory_finalize; - (*factory)->create_maestro_context = - xbt_ctx_sysv_factory_create_maestro_context; + (*factory)->create_maestro_context = xbt_ctx_sysv_factory_create_maestro_context; + (*factory)->free = xbt_ctx_sysv_free; + (*factory)->kill = xbt_ctx_sysv_kill; + (*factory)->schedule = xbt_ctx_sysv_schedule; + (*factory)->yield = xbt_ctx_sysv_yield; + (*factory)->start = xbt_ctx_sysv_start; + (*factory)->stop = xbt_ctx_sysv_stop; (*factory)->name = "ctx_sysv_context_factory"; /* context exception handlers */ @@ -166,14 +170,6 @@ xbt_ctx_sysv_factory_create_context(const char *name, xbt_main_func_t code, context->cleanup_func = cleanup_func; context->cleanup_arg = cleanup_arg; - - context->free = xbt_ctx_sysv_free; - context->kill = xbt_ctx_sysv_kill; - context->schedule = xbt_ctx_sysv_schedule; - context->yield = xbt_ctx_sysv_yield; - context->start = xbt_ctx_sysv_start; - context->stop = xbt_ctx_sysv_stop; - return (xbt_context_t) context; } @@ -313,9 +309,8 @@ static void xbt_ctx_sysv_resume(xbt_context_t context) current_context = context; - rv = - swapcontext(&(((xbt_ctx_sysv_t) context)->prev->uc), - &(((xbt_ctx_sysv_t) context)->uc)); + rv = swapcontext(&(((xbt_ctx_sysv_t) context)->prev->uc), + &(((xbt_ctx_sysv_t) context)->uc)); xbt_assert0((rv == 0), "Context swapping failure"); } diff --git a/src/simix/xbt_context_thread.c b/src/simix/xbt_context_thread.c index a00612bf78..5059f0ef97 100644 --- a/src/simix/xbt_context_thread.c +++ b/src/simix/xbt_context_thread.c @@ -8,7 +8,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "xbt/function_types.h" -#include "xbt/xbt_context_private.h" +#include "xbt_context_private.h" #include "portable.h" /* loads context system definitions */ #include "xbt/swag.h" @@ -67,8 +67,13 @@ void xbt_ctx_thread_factory_init(xbt_context_factory_t * factory) (*factory)->create_context = xbt_ctx_thread_factory_create_context; (*factory)->finalize = xbt_ctx_thread_factory_finalize; - (*factory)->create_maestro_context = - xbt_ctx_thread_factory_create_master_context; + (*factory)->create_maestro_context = xbt_ctx_thread_factory_create_master_context; + (*factory)->free = xbt_ctx_thread_free; + (*factory)->kill = xbt_ctx_thread_kill; + (*factory)->schedule = xbt_ctx_thread_schedule; + (*factory)->yield = xbt_ctx_thread_yield; + (*factory)->start = xbt_ctx_thread_start; + (*factory)->stop = xbt_ctx_thread_stop; (*factory)->name = "ctx_thread_factory"; } @@ -110,13 +115,6 @@ xbt_ctx_thread_factory_create_context(const char *name, xbt_main_func_t code, context->cleanup_func = cleanup_func; context->cleanup_arg = cleanup_arg; - context->free = xbt_ctx_thread_free; - context->kill = xbt_ctx_thread_kill; - context->schedule = xbt_ctx_thread_schedule; - context->yield = xbt_ctx_thread_yield; - context->start = xbt_ctx_thread_start; - context->stop = xbt_ctx_thread_stop; - return (xbt_context_t) context; }