From 8e970353f6db8e98fd13fcc1bf80e57e84f3d25c Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 14 Apr 2008 15:21:07 +0000 Subject: [PATCH] Try to fixup the context mess git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5335 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/java/jmsg.c | 5 +- src/java/jmsg_process.c | 6 +- src/xbt/xbt_context_factory.h | 51 ------- src/xbt/xbt_context_java.c | 2 +- src/xbt/xbt_context_java.h | 10 +- src/xbt/xbt_context_private.h | 70 +++++++-- .../{xbt_ucontext.c => xbt_context_sysv.c} | 134 ++++++++--------- ..._thread_context.c => xbt_context_thread.c} | 140 +++++++++--------- 8 files changed, 206 insertions(+), 212 deletions(-) delete mode 100644 src/xbt/xbt_context_factory.h rename src/xbt/{xbt_ucontext.c => xbt_context_sysv.c} (56%) rename src/xbt/{xbt_thread_context.c => xbt_context_thread.c} (55%) diff --git a/src/java/jmsg.c b/src/java/jmsg.c index e1f2dcf348..e74aec4f8d 100644 --- a/src/java/jmsg.c +++ b/src/java/jmsg.c @@ -12,8 +12,7 @@ #include "msg/msg.h" #include "msg/private.h" #include "simix/private.h" -#include "xbt/xbt_jcontext.h" -#include "xbt/xbt_context_factory.h" +#include "xbt/xbt_context_java.h" #include "jmsg_process.h" #include "jmsg_host.h" @@ -49,7 +48,7 @@ get_current_thread_env(void) { static jobject native_to_java_process(m_process_t process) { - return ((xbt_jcontext_t)(process->simdata->s_process->simdata->context))->jprocess; + return ((xbt_ctx_java_t)(process->simdata->s_process->simdata->context))->jprocess; } diff --git a/src/java/jmsg_process.c b/src/java/jmsg_process.c index 4121efdec5..2fb7ecf67e 100644 --- a/src/java/jmsg_process.c +++ b/src/java/jmsg_process.c @@ -14,7 +14,7 @@ #include "jmsg.h" #include "jxbt_utilities.h" -#include "xbt/xbt_jcontext.h" +#include "xbt/xbt_context_java.h" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); @@ -188,7 +188,7 @@ jprocess_schedule(xbt_context_t context) { if(!id) return; - (*env)->CallVoidMethod(env,((xbt_jcontext_t)context)->jprocess,id); + (*env)->CallVoidMethod(env,((xbt_ctx_java_t)context)->jprocess,id); } @@ -206,6 +206,6 @@ jprocess_unschedule(xbt_context_t context) { if(!id) return; - (*env)->CallVoidMethod(env,((xbt_jcontext_t)context)->jprocess,id); + (*env)->CallVoidMethod(env,((xbt_ctx_java_t)context)->jprocess,id); } diff --git a/src/xbt/xbt_context_factory.h b/src/xbt/xbt_context_factory.h deleted file mode 100644 index 7ad0ad09ba..0000000000 --- a/src/xbt/xbt_context_factory.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef _XBT_CONTEXT_FACTORY_H -#define _XBT_CONTEXT_FACTORY_H - -#include "portable.h" -#include "xbt/function_types.h" -#include "xbt_context_private.h" - -SG_BEGIN_DECL() - -/* forward declaration */ -struct s_xbt_context_factory; - -/* this function describes the interface that all context factory must implement */ -typedef xbt_context_t (*xbt_pfn_context_factory_create_context_t)(const char*, xbt_main_func_t, void_f_pvoid_t, void*, void_f_pvoid_t, void*, int, char**); -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)(struct s_xbt_context_factory**); - -/* this interface is used by the xbt context module to create the appropriate concept */ -typedef struct s_xbt_context_factory -{ - xbt_pfn_context_factory_create_maestro_context_t create_maestro_context; /* create the context of the maestro */ - xbt_pfn_context_factory_create_context_t create_context; /* create a new context */ - xbt_pfn_context_factory_finalize_t finalize; /* finalize the context factory */ - const char* name; /* the name of the context factory */ - -}s_xbt_context_factory_t; - -/** - * This function select a context factory associated with the name specified by - * the parameter name. - * If successful the function returns 0. Otherwise the function returns the error - * code. - */ -int -xbt_context_select_factory(const char* name); - -/** - * This function initialize a context factory from the name specified by the parameter - * name. - * If successful the factory specified by the parameter factory is initialized and the - * function returns 0. Otherwise the function returns the error code. - */ -int -xbt_context_init_factory_by_name(xbt_context_factory_t* factory, const char* name); - - -SG_END_DECL() - -#endif /* !_XBT_CONTEXT_FACTORY_H */ diff --git a/src/xbt/xbt_context_java.c b/src/xbt/xbt_context_java.c index 8b2516b5a8..bf75e6d3ac 100644 --- a/src/xbt/xbt_context_java.c +++ b/src/xbt/xbt_context_java.c @@ -2,7 +2,7 @@ #include "xbt/function_types.h" #include "xbt/ex_interface.h" -#include "xbt/xbt_context_factory.h" +#include "xbt/xbt_context_private.h" #include "xbt/xbt_context_java.h" XBT_LOG_NEW_DEFAULT_CATEGORY(jmsg,"MSG for Java(TM)"); diff --git a/src/xbt/xbt_context_java.h b/src/xbt/xbt_context_java.h index a817ec216e..9760e0430b 100644 --- a/src/xbt/xbt_context_java.h +++ b/src/xbt/xbt_context_java.h @@ -1,5 +1,5 @@ -#ifndef _XBT_JCONTEXT_H -#define _XBT_JCONTEXT_H +#ifndef _XBT_CONTEXT_JAVA_H +#define _XBT_CONTEXT_JAVA_H #include "portable.h" #include "xbt/misc.h" @@ -10,13 +10,13 @@ SG_BEGIN_DECL() -typedef struct s_xbt_jcontext +typedef struct s_xbt_ctx_java { XBT_CTX_BASE_T; jobject jprocess; /* the java process instance binded with the msg process structure */ JNIEnv* jenv; /* jni interface pointer associated to this thread */ -}s_xbt_jcontext_t,* xbt_jcontext_t; +}s_xbt_ctx_java_t,* xbt_ctx_java_t; SG_END_DECL() -#endif /* !_XBT_JCONTEXT_H */ +#endif /* !_XBT_CONTEXT_JAVA_H */ diff --git a/src/xbt/xbt_context_private.h b/src/xbt/xbt_context_private.h index b073653c7f..bf01c289bf 100644 --- a/src/xbt/xbt_context_private.h +++ b/src/xbt/xbt_context_private.h @@ -7,16 +7,19 @@ SG_BEGIN_DECL() +/* *********************** */ +/* Context type definition */ +/* *********************** */ + /* the following function pointers describe the interface that all context concepts must implement */ - typedef void (*xbt_pfn_context_free_t)(xbt_context_t); /* pointer type to the function used to destroy the specified context */ typedef void (*xbt_pfn_context_kill_t)(xbt_context_t); /* pointer type to the function used to kill the specified context */ typedef void (*xbt_pfn_context_schedule_t)(xbt_context_t); /* pointer type to the function used to resume the specified context */ -typedef void (*xbt_pfn_context_yield_t)(void); /* pointer type to the function used to yield the specified context */ +typedef void (*xbt_pfn_context_yield_t)(void); /* pointer type to the function used to yield the specified context */ typedef void (*xbt_pfn_context_start_t)(xbt_context_t); /* pointer type to the function used to start the specified context */ -typedef void (*xbt_pfn_context_stop_t)(int); /* pointer type to the function used to stop the current context */ +typedef void (*xbt_pfn_context_stop_t)(int); /* pointer type to the function used to stop the current context */ -/* each context concept must use this macro in its declaration */ +/* each context type must contain this macro at its begining -- OOP in C :/ */ #define XBT_CTX_BASE_T \ s_xbt_swag_hookup_t hookup; \ char *name; \ @@ -36,11 +39,14 @@ typedef void (*xbt_pfn_context_stop_t)(int); /* pointer type to the function xbt_pfn_context_start_t start; \ xbt_pfn_context_stop_t stop -/* all other contexts derive from this structure */ -typedef struct s_xbt_context -{ +/* all other context types derive from this structure */ +typedef struct s_xbt_context { XBT_CTX_BASE_T; -}s_xbt_context_t; +} s_xbt_context_t; + +/* ****************** */ +/* Globals definition */ +/* ****************** */ /* Important guys */ extern xbt_context_t current_context; @@ -49,13 +55,53 @@ extern xbt_context_t maestro_context; extern xbt_swag_t context_living; extern xbt_swag_t context_to_destroy; +/* *********************** */ +/* factory type definition */ +/* *********************** */ +typedef struct s_xbt_context_factory * xbt_context_factory_t; + +/* this function describes the interface that all context factory must implement */ +typedef xbt_context_t (*xbt_pfn_context_factory_create_context_t)(const char*, xbt_main_func_t, void_f_pvoid_t, void*, void_f_pvoid_t, void*, int, char**); +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*); + +/* this interface is used by the xbt context module to create the appropriate concept */ +typedef struct s_xbt_context_factory { + xbt_pfn_context_factory_create_maestro_context_t create_maestro_context; /* create the context of the maestro */ + xbt_pfn_context_factory_create_context_t create_context; /* create a new context */ + xbt_pfn_context_factory_finalize_t finalize; /* finalize the context factory */ + const char* name; /* the name of the context factory */ + +} s_xbt_context_factory_t; + +/** + * This function select a context factory associated with the name specified by + * the parameter name. + * If successful the function returns 0. Otherwise the function returns the error + * code. + */ +int +xbt_context_select_factory(const char* name); + +/** + * This function initialize a context factory from the name specified by the parameter + * name. + * If successful the factory specified by the parameter factory is initialized and the + * function returns 0. Otherwise the function returns the error code. + */ +int +xbt_context_init_factory_by_name(xbt_context_factory_t* factory, const char* name); + /* All factories init */ -typedef struct s_xbt_context_factory* xbt_context_factory_t; +int xbt_ctx_thread_factory_init(xbt_context_factory_t* factory); +int xbt_ctx_sysv_factory_init(xbt_context_factory_t* factory); +int xbt_ctx_java_factory_init(xbt_context_factory_t* factory); + + -int xbt_thread_context_factory_init(xbt_context_factory_t* factory); -int xbt_ucontext_factory_init(xbt_context_factory_t* factory); -int xbt_jcontext_factory_init(xbt_context_factory_t* factory); SG_END_DECL() diff --git a/src/xbt/xbt_ucontext.c b/src/xbt/xbt_context_sysv.c similarity index 56% rename from src/xbt/xbt_ucontext.c rename to src/xbt/xbt_context_sysv.c index 638edc6416..9295621d5c 100644 --- a/src/xbt/xbt_ucontext.c +++ b/src/xbt/xbt_context_sysv.c @@ -1,18 +1,18 @@ -#include "ucontext_stack.h" #include "xbt/ex_interface.h" -#include "xbt/xbt_context_factory.h" +#include "xbt/xbt_context_private.h" -#include "ucontext_stack.h" /* loads context system definitions */ +#include "context_sysv_config.h" /* loads context system definitions */ +#include "portable.h" #include /* context relative declarations */ #define STACK_SIZE 128*1024 /* lower this if you want to reduce the memory consumption */ -typedef struct s_xbt_ucontext { +typedef struct s_xbt_ctx_sysv { XBT_CTX_BASE_T; ucontext_t uc; /* the thread that execute the code */ char stack[STACK_SIZE]; /* the thread stack size */ - struct s_xbt_ucontext* prev; /* the previous thread */ -} s_xbt_ucontext_t,* xbt_ucontext_t; + struct s_xbt_ctx_sysv* prev;/* the previous thread */ +} s_xbt_ctx_sysv_t,* xbt_ctx_sysv_t; /* callback: context fetching */ @@ -24,59 +24,59 @@ static void xbt_jcontext_ex_terminate(xbt_ex_t *e); static xbt_context_t -xbt_ucontext_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv); +xbt_ctx_sysv_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv); static int -xbt_ucontext_factory_finalize(xbt_context_factory_t* factory); +xbt_ctx_sysv_factory_finalize(xbt_context_factory_t* factory); static int -xbt_ucontext_factory_create_maestro_context(xbt_context_t* maestro); +xbt_ctx_sysv_factory_create_maestro_context(xbt_context_t* maestro); static void -xbt_ucontext_free(xbt_context_t context); +xbt_ctx_sysv_free(xbt_context_t context); static void -xbt_ucontext_kill(xbt_context_t context); +xbt_ctx_sysv_kill(xbt_context_t context); static void -xbt_ucontext_schedule(xbt_context_t context); +xbt_ctx_sysv_schedule(xbt_context_t context); static void -xbt_ucontext_yield(void); +xbt_ctx_sysv_yield(void); static void -xbt_ucontext_start(xbt_context_t context); +xbt_ctx_sysv_start(xbt_context_t context); static void -xbt_ucontext_stop(int exit_code); +xbt_ctx_sysv_stop(int exit_code); static void -xbt_ucontext_swap(xbt_context_t context); +xbt_ctx_sysv_swap(xbt_context_t context); static void -xbt_ucontext_schedule(xbt_context_t context); +xbt_ctx_sysv_schedule(xbt_context_t context); static void -xbt_ucontext_yield(void); +xbt_ctx_sysv_yield(void); static void -xbt_ucontext_suspend(xbt_context_t context); +xbt_ctx_sysv_suspend(xbt_context_t context); static void -xbt_ucontext_resume(xbt_context_t context); +xbt_ctx_sysv_resume(xbt_context_t context); -static void xbt_ucontext_wrapper(void); +static void xbt_ctx_sysv_wrapper(void); /* callback: context fetching */ static ex_ctx_t* -xbt_ucontext_ex_ctx(void) +xbt_ctx_sysv_ex_ctx(void) { return current_context->exception; } /* callback: termination */ static void -xbt_ucontext_ex_terminate(xbt_ex_t *e) +xbt_ctx_sysv_ex_terminate(xbt_ex_t *e) { xbt_ex_display(e); abort(); @@ -84,28 +84,28 @@ xbt_ucontext_ex_terminate(xbt_ex_t *e) int -xbt_ucontext_factory_init(xbt_context_factory_t* factory) +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_ucontext_factory_create_context; - (*factory)->finalize = xbt_ucontext_factory_finalize; - (*factory)->create_maestro_context = xbt_ucontext_factory_create_maestro_context; - (*factory)->name = "ucontext_context_factory"; + (*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)->name = "ctx_sysv_context_factory"; /* context exception handlers */ - __xbt_ex_ctx = xbt_ucontext_ex_ctx; - __xbt_ex_terminate = xbt_ucontext_ex_terminate; + __xbt_ex_ctx = xbt_ctx_sysv_ex_ctx; + __xbt_ex_terminate = xbt_ctx_sysv_ex_terminate; return 0; } static int -xbt_ucontext_factory_create_maestro_context(xbt_context_t* maestro) +xbt_ctx_sysv_factory_create_maestro_context(xbt_context_t* maestro) { - xbt_ucontext_t context = xbt_new0(s_xbt_ucontext_t, 1); + xbt_ctx_sysv_t context = xbt_new0(s_xbt_ctx_sysv_t, 1); context->exception = xbt_new(ex_ctx_t,1); XBT_CTX_INITIALIZE(context->exception); @@ -118,7 +118,7 @@ xbt_ucontext_factory_create_maestro_context(xbt_context_t* maestro) static int -xbt_ucontext_factory_finalize(xbt_context_factory_t* factory) +xbt_ctx_sysv_factory_finalize(xbt_context_factory_t* factory) { free(maestro_context->exception); free(*factory); @@ -127,9 +127,9 @@ xbt_ucontext_factory_finalize(xbt_context_factory_t* factory) } static xbt_context_t -xbt_ucontext_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv) +xbt_ctx_sysv_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv) { - xbt_ucontext_t context = xbt_new0(s_xbt_ucontext_t, 1); + xbt_ctx_sysv_t context = xbt_new0(s_xbt_ctx_sysv_t, 1); context->code = code; context->name = xbt_strdup(name); @@ -150,18 +150,18 @@ xbt_ucontext_factory_create_context(const char* name, xbt_main_func_t code, void context->cleanup_arg = cleanup_arg; - context->free = xbt_ucontext_free; - context->kill = xbt_ucontext_kill; - context->schedule = xbt_ucontext_schedule; - context->yield = xbt_ucontext_yield; - context->start = xbt_ucontext_start; - context->stop = xbt_ucontext_stop; + 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; } static void -xbt_ucontext_free(xbt_context_t context) +xbt_ctx_sysv_free(xbt_context_t context) { if(context) { @@ -187,10 +187,10 @@ xbt_ucontext_free(xbt_context_t context) } static void -xbt_ucontext_kill(xbt_context_t context) +xbt_ctx_sysv_kill(xbt_context_t context) { context->iwannadie = 1; - xbt_ucontext_swap(context); + xbt_ctx_sysv_swap(context); } /** @@ -203,10 +203,10 @@ xbt_ucontext_kill(xbt_context_t context) * Only the maestro can call this function to run a given process. */ static void -xbt_ucontext_schedule(xbt_context_t context) +xbt_ctx_sysv_schedule(xbt_context_t context) { xbt_assert0((current_context == maestro_context),"You are not supposed to run this function here!"); - xbt_ucontext_swap(context); + xbt_ctx_sysv_swap(context); } /** @@ -218,20 +218,20 @@ xbt_ucontext_schedule(xbt_context_t context) * to the maestro */ static void -xbt_ucontext_yield(void) +xbt_ctx_sysv_yield(void) { xbt_assert0((current_context != maestro_context),"You are not supposed to run this function here!"); - xbt_ucontext_swap(current_context); + xbt_ctx_sysv_swap(current_context); } static void -xbt_ucontext_start(xbt_context_t context) +xbt_ctx_sysv_start(xbt_context_t context) { - makecontext(&(((xbt_ucontext_t)context)->uc), xbt_ucontext_wrapper, 0); + makecontext(&(((xbt_ctx_sysv_t)context)->uc), xbt_ctx_sysv_wrapper, 0); } static void -xbt_ucontext_stop(int exit_code) +xbt_ctx_sysv_stop(int exit_code) { if(current_context->cleanup_func) ((*current_context->cleanup_func))(current_context->cleanup_arg); @@ -239,59 +239,59 @@ xbt_ucontext_stop(int exit_code) xbt_swag_remove(current_context, context_living); xbt_swag_insert(current_context, context_to_destroy); - xbt_ucontext_swap(current_context); + xbt_ctx_sysv_swap(current_context); } static void -xbt_ucontext_swap(xbt_context_t context) +xbt_ctx_sysv_swap(xbt_context_t context) { xbt_assert0(current_context, "You have to call context_init() first."); xbt_assert0(context, "Invalid argument"); - if(((xbt_ucontext_t)context)->prev == NULL) - xbt_ucontext_resume(context); + if(((xbt_ctx_sysv_t)context)->prev == NULL) + xbt_ctx_sysv_resume(context); else - xbt_ucontext_suspend(context); + xbt_ctx_sysv_suspend(context); if(current_context->iwannadie) - xbt_ucontext_stop(1); + xbt_ctx_sysv_stop(1); } static void -xbt_ucontext_wrapper(void) +xbt_ctx_sysv_wrapper(void) { if (current_context->startup_func) (*current_context->startup_func)(current_context->startup_arg); - xbt_ucontext_stop((*(current_context->code))(current_context->argc, current_context->argv)); + xbt_ctx_sysv_stop((*(current_context->code))(current_context->argc, current_context->argv)); } static void -xbt_ucontext_suspend(xbt_context_t context) +xbt_ctx_sysv_suspend(xbt_context_t context) { int rv; - xbt_ucontext_t prev_context = ((xbt_ucontext_t)context)->prev; + xbt_ctx_sysv_t prev_context = ((xbt_ctx_sysv_t)context)->prev; - current_context = (xbt_context_t)(((xbt_ucontext_t)context)->prev); + current_context = (xbt_context_t)(((xbt_ctx_sysv_t)context)->prev); - ((xbt_ucontext_t)context)->prev = NULL; + ((xbt_ctx_sysv_t)context)->prev = NULL; - rv = swapcontext(&(((xbt_ucontext_t)context)->uc), &(prev_context->uc)); + rv = swapcontext(&(((xbt_ctx_sysv_t)context)->uc), &(prev_context->uc)); xbt_assert0((rv == 0), "Context swapping failure"); } static void -xbt_ucontext_resume(xbt_context_t context) +xbt_ctx_sysv_resume(xbt_context_t context) { int rv; - ((xbt_ucontext_t)context)->prev = (xbt_ucontext_t)current_context; + ((xbt_ctx_sysv_t)context)->prev = (xbt_ctx_sysv_t)current_context; current_context = context; - rv = swapcontext(&(((xbt_ucontext_t)context)->prev->uc), &(((xbt_ucontext_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/xbt/xbt_thread_context.c b/src/xbt/xbt_context_thread.c similarity index 55% rename from src/xbt/xbt_thread_context.c rename to src/xbt/xbt_context_thread.c index 60e6b26021..e39ff91e6f 100644 --- a/src/xbt/xbt_thread_context.c +++ b/src/xbt/xbt_context_thread.c @@ -1,87 +1,87 @@ #include "xbt/function_types.h" -#include "xbt/xbt_context_factory.h" +#include "xbt/xbt_context_private.h" #include "portable.h" /* loads context system definitions */ #include "xbt/swag.h" #include "xbt/xbt_os_thread.h" -typedef struct s_xbt_thread_context { +typedef struct s_xbt_ctx_thread { XBT_CTX_BASE_T; xbt_os_thread_t thread; /* a plain dumb thread (portable to posix or windows) */ xbt_os_sem_t begin; /* this semaphore is used to schedule/yield the process */ xbt_os_sem_t end; /* this semaphore is used to schedule/unschedule the process */ -} s_xbt_thread_context_t,* xbt_thread_context_t; +} s_xbt_ctx_thread_t,* xbt_ctx_thread_t; static xbt_context_t -xbt_thread_context_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv); +xbt_ctx_thread_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv); static int -xbt_thread_context_factory_create_master_context(xbt_context_t* maestro); +xbt_ctx_thread_factory_create_master_context(xbt_context_t* maestro); static int -xbt_thread_context_factory_finalize(xbt_context_factory_t* factory); +xbt_ctx_thread_factory_finalize(xbt_context_factory_t* factory); static void -xbt_thread_context_free(xbt_context_t context); +xbt_ctx_thread_free(xbt_context_t context); static void -xbt_thread_context_kill(xbt_context_t context); +xbt_ctx_thread_kill(xbt_context_t context); static void -xbt_thread_context_schedule(xbt_context_t context); +xbt_ctx_thread_schedule(xbt_context_t context); static void -xbt_thread_context_yield(void); +xbt_ctx_thread_yield(void); static void -xbt_thread_context_start(xbt_context_t context); +xbt_ctx_thread_start(xbt_context_t context); static void -xbt_thread_context_stop(int exit_code); +xbt_ctx_thread_stop(int exit_code); static void -xbt_thread_context_swap(xbt_context_t context); +xbt_ctx_thread_swap(xbt_context_t context); static void -xbt_thread_context_schedule(xbt_context_t context); +xbt_ctx_thread_schedule(xbt_context_t context); static void -xbt_thread_context_yield(void); +xbt_ctx_thread_yield(void); static void -xbt_thread_context_suspend(xbt_context_t context); +xbt_ctx_thread_suspend(xbt_context_t context); static void -xbt_thread_context_resume(xbt_context_t context); +xbt_ctx_thread_resume(xbt_context_t context); static void* -xbt_thread_context_wrapper(void* param); +xbt_ctx_thread_wrapper(void* param); int -xbt_thread_context_factory_init(xbt_context_factory_t* factory) +xbt_ctx_thread_factory_init(xbt_context_factory_t* factory) { *factory = xbt_new0(s_xbt_context_factory_t,1); - (*factory)->create_context = xbt_thread_context_factory_create_context; - (*factory)->finalize = xbt_thread_context_factory_finalize; - (*factory)->create_maestro_context = xbt_thread_context_factory_create_master_context; - (*factory)->name = "thread_context_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)->name = "ctx_thread_factory"; return 0; } static int -xbt_thread_context_factory_create_master_context(xbt_context_t* maestro) +xbt_ctx_thread_factory_create_master_context(xbt_context_t* maestro) { - *maestro = (xbt_context_t)xbt_new0(s_xbt_thread_context_t, 1); + *maestro = (xbt_context_t)xbt_new0(s_xbt_ctx_thread_t, 1); return 0; } static int -xbt_thread_context_factory_finalize(xbt_context_factory_t* factory) +xbt_ctx_thread_factory_finalize(xbt_context_factory_t* factory) { free(*factory); *factory = NULL; @@ -89,9 +89,9 @@ xbt_thread_context_factory_finalize(xbt_context_factory_t* factory) } static xbt_context_t -xbt_thread_context_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv) +xbt_ctx_thread_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv) { - xbt_thread_context_t context = xbt_new0(s_xbt_thread_context_t, 1); + xbt_ctx_thread_t context = xbt_new0(s_xbt_ctx_thread_t, 1); context->code = code; context->name = xbt_strdup(name); @@ -105,42 +105,42 @@ xbt_thread_context_factory_create_context(const char* name, xbt_main_func_t code context->cleanup_func = cleanup_func; context->cleanup_arg = cleanup_arg; - context->free = xbt_thread_context_free; - context->kill = xbt_thread_context_kill; - context->schedule = xbt_thread_context_schedule; - context->yield = xbt_thread_context_yield; - context->start = xbt_thread_context_start; - context->stop = xbt_thread_context_stop; + 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; } static void -xbt_thread_context_free(xbt_context_t context) +xbt_ctx_thread_free(xbt_context_t context) { if(context) { - xbt_thread_context_t thread_context = (xbt_thread_context_t)context; + xbt_ctx_thread_t ctx_thread = (xbt_ctx_thread_t)context; - free(thread_context->name); + free(ctx_thread->name); - if(thread_context->argv) + if(ctx_thread->argv) { int i; - for(i = 0; i < thread_context->argc; i++) - if(thread_context->argv[i]) - free(thread_context->argv[i]); + for(i = 0; i < ctx_thread->argc; i++) + if(ctx_thread->argv[i]) + free(ctx_thread->argv[i]); - free(thread_context->argv); + free(ctx_thread->argv); } /* wait about the thread terminason */ - xbt_os_thread_join(thread_context->thread, NULL); + xbt_os_thread_join(ctx_thread->thread, NULL); /* destroy the synchronisation objects */ - xbt_os_sem_destroy(thread_context->begin); - xbt_os_sem_destroy(thread_context->end); + xbt_os_sem_destroy(ctx_thread->begin); + xbt_os_sem_destroy(ctx_thread->end); /* finally destroy the context */ free(context); @@ -148,10 +148,10 @@ xbt_thread_context_free(xbt_context_t context) } static void -xbt_thread_context_kill(xbt_context_t context) +xbt_ctx_thread_kill(xbt_context_t context) { context->iwannadie = 1; - xbt_thread_context_swap(context); + xbt_ctx_thread_swap(context); } /** @@ -164,10 +164,10 @@ xbt_thread_context_kill(xbt_context_t context) * Only the maestro can call this function to run a given process. */ static void -xbt_thread_context_schedule(xbt_context_t context) +xbt_ctx_thread_schedule(xbt_context_t context) { xbt_assert0((current_context == maestro_context),"You are not supposed to run this function here!"); - xbt_thread_context_swap(context); + xbt_ctx_thread_swap(context); } /** @@ -179,26 +179,26 @@ xbt_thread_context_schedule(xbt_context_t context) * to the maestro */ static void -xbt_thread_context_yield(void) +xbt_ctx_thread_yield(void) { xbt_assert0((current_context != maestro_context),"You are not supposed to run this function here!"); - xbt_thread_context_swap(current_context); + xbt_ctx_thread_swap(current_context); } static void -xbt_thread_context_start(xbt_context_t context) +xbt_ctx_thread_start(xbt_context_t context) { - xbt_thread_context_t thread_context = (xbt_thread_context_t)context; + xbt_ctx_thread_t ctx_thread = (xbt_ctx_thread_t)context; /* create and start the process */ - thread_context->thread = xbt_os_thread_create(thread_context->name,xbt_thread_context_wrapper,thread_context); + ctx_thread->thread = xbt_os_thread_create(ctx_thread->name,xbt_ctx_thread_wrapper,ctx_thread); /* wait the starting of the newly created process */ - xbt_os_sem_acquire(thread_context->end); + xbt_os_sem_acquire(ctx_thread->end); } static void -xbt_thread_context_stop(int exit_code) +xbt_ctx_thread_stop(int exit_code) { if(current_context->cleanup_func) ((*current_context->cleanup_func))(current_context->cleanup_arg); @@ -207,21 +207,21 @@ xbt_thread_context_stop(int exit_code) xbt_swag_insert(current_context, context_to_destroy); /* signal to the maestro that it has finished */ - xbt_os_sem_release(((xbt_thread_context_t)current_context)->end); + xbt_os_sem_release(((xbt_ctx_thread_t)current_context)->end); /* exit*/ xbt_os_thread_exit(NULL); /* We should provide return value in case other wants it */ } static void -xbt_thread_context_swap(xbt_context_t context) +xbt_ctx_thread_swap(xbt_context_t context) { if((current_context != maestro_context) && !context->iwannadie) { /* (0) it's not the scheduler and the process doesn't want to die, it just wants to yield */ /* yield itself, resume the maestro */ - xbt_thread_context_suspend(context); + xbt_ctx_thread_suspend(context); } else { @@ -249,19 +249,19 @@ xbt_thread_context_swap(xbt_context_t context) * -> goto (3.1) */ /* schedule the process associated with this context */ - xbt_thread_context_resume(context); + xbt_ctx_thread_resume(context); } /* (4) the current process wants to die */ if(current_context->iwannadie) - xbt_thread_context_stop(1); + xbt_ctx_thread_stop(1); } static void* -xbt_thread_context_wrapper(void* param) +xbt_ctx_thread_wrapper(void* param) { - xbt_thread_context_t context = (xbt_thread_context_t)param; + xbt_ctx_thread_t context = (xbt_ctx_thread_t)param; /* Tell the maestro we are starting, and wait for its green light */ xbt_os_sem_release(context->end); @@ -271,12 +271,12 @@ xbt_thread_context_wrapper(void* param) (*(context->startup_func))(context->startup_arg); - xbt_thread_context_stop((context->code) (context->argc, context->argv)); + xbt_ctx_thread_stop((context->code) (context->argc, context->argv)); return NULL; } static void -xbt_thread_context_suspend(xbt_context_t context) +xbt_ctx_thread_suspend(xbt_context_t context) { /* save the current context */ xbt_context_t self = current_context; @@ -284,15 +284,15 @@ xbt_thread_context_suspend(xbt_context_t context) /* update the current context to this context */ current_context = context; - xbt_os_sem_release(((xbt_thread_context_t)context)->end); - xbt_os_sem_acquire(((xbt_thread_context_t)context)->begin); + xbt_os_sem_release(((xbt_ctx_thread_t)context)->end); + xbt_os_sem_acquire(((xbt_ctx_thread_t)context)->begin); /* restore the current context to the previously saved context */ current_context = self; } static void -xbt_thread_context_resume(xbt_context_t context) +xbt_ctx_thread_resume(xbt_context_t context) { /* save the current context */ xbt_context_t self = current_context; @@ -300,8 +300,8 @@ xbt_thread_context_resume(xbt_context_t context) /* update the current context */ current_context = context; - xbt_os_sem_release(((xbt_thread_context_t)context)->begin); - xbt_os_sem_acquire(((xbt_thread_context_t)context)->end); + xbt_os_sem_release(((xbt_ctx_thread_t)context)->begin); + xbt_os_sem_acquire(((xbt_ctx_thread_t)context)->end); /* restore the current context to the previously saved context */ current_context = self; -- 2.20.1