git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5652
48e7efb5-ca39-0410-a469-
dd3cf9ba447f
static void xbt_ctx_java_stop(int exit_code)
{
jobject jprocess = NULL;
static void xbt_ctx_java_stop(int exit_code)
{
jobject jprocess = NULL;
xbt_ctx_java_t ctx_java;
if (current_context->cleanup_func)
xbt_ctx_java_t ctx_java;
if (current_context->cleanup_func)
/* *********************** */
/* 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 */
/* *********************** */
/* 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_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_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_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 */
/* each context type must contain this macro at its begining -- OOP in C :/ */
typedef void (*xbt_pfn_context_stop_t) (int); /* pointer type to the function used to stop the current context */
/* each context type must contain this macro at its begining -- OOP in C :/ */
/* Important guys */
extern xbt_context_t current_context;
/* Important guys */
extern xbt_context_t current_context;
extern xbt_context_t maestro_context;
/* All dudes lists */
extern xbt_swag_t context_living;
extern xbt_context_t maestro_context;
/* All dudes lists */
extern xbt_swag_t context_living;
extern xbt_swag_t context_to_destroy;
/* *********************** */
extern xbt_swag_t context_to_destroy;
/* *********************** */
- int (*xbt_pfn_context_factory_create_maestro_context_t) (xbt_context_t
- *);
+ 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 function finalize the specified context factory */
typedef int (*xbt_pfn_context_factory_finalize_t) (xbt_context_factory_t
* If the factory cannot be found, an exception is raised.
*/
void
* If the factory cannot be found, an exception is raised.
*/
void
xbt_context_init_factory_by_name(xbt_context_factory_t * factory,
const char *name);
xbt_context_init_factory_by_name(xbt_context_factory_t * factory,
const char *name);
/* All factories init */
void xbt_ctx_thread_factory_init(xbt_context_factory_t * factory);
/* All factories init */
void xbt_ctx_thread_factory_init(xbt_context_factory_t * factory);
void xbt_ctx_sysv_factory_init(xbt_context_factory_t * factory);
void xbt_ctx_sysv_factory_init(xbt_context_factory_t * factory);
void xbt_ctx_java_factory_init(xbt_context_factory_t * factory);
void xbt_ctx_java_factory_init(xbt_context_factory_t * factory);
#define STACK_SIZE 128*1024 /* lower this if you want to reduce the memory consumption */
#ifdef HAVE_VALGRIND_VALGRIND_H
# include <valgrind/valgrind.h>
#define STACK_SIZE 128*1024 /* lower this if you want to reduce the memory consumption */
#ifdef HAVE_VALGRIND_VALGRIND_H
# include <valgrind/valgrind.h>
-#endif /* HAVE_VALGRIND_VALGRIND_H */
+#endif /* HAVE_VALGRIND_VALGRIND_H */
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_context);
typedef struct s_xbt_ctx_sysv {
XBT_CTX_BASE_T;
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_context);
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_ctx_sysv *prev; /* the previous thread */
+ ucontext_t uc; /* the thread that execute the code */
+ char stack[STACK_SIZE]; /* the thread stack size */
+ struct s_xbt_ctx_sysv *prev; /* the previous thread */
#ifdef HAVE_VALGRIND_VALGRIND_H
#ifdef HAVE_VALGRIND_VALGRIND_H
- unsigned int valgrind_stack_id; /* the valgrind stack id. */
-#endif /* HAVE_VALGRIND_VALGRIND_H */
+ unsigned int valgrind_stack_id; /* the valgrind stack id. */
+#endif /* HAVE_VALGRIND_VALGRIND_H */
} s_xbt_ctx_sysv_t, *xbt_ctx_sysv_t;
} s_xbt_ctx_sysv_t, *xbt_ctx_sysv_t;
xbt_ctx_sysv_factory_create_maestro_context(xbt_context_t * maestro);
static void xbt_ctx_sysv_free(xbt_context_t context);
xbt_ctx_sysv_factory_create_maestro_context(xbt_context_t * maestro);
static void xbt_ctx_sysv_free(xbt_context_t context);
static void xbt_ctx_sysv_kill(xbt_context_t context);
static void xbt_ctx_sysv_kill(xbt_context_t context);
static void xbt_ctx_sysv_schedule(xbt_context_t context);
static void xbt_ctx_sysv_schedule(xbt_context_t context);
static void xbt_ctx_sysv_yield(void);
static void xbt_ctx_sysv_yield(void);
static void xbt_ctx_sysv_start(xbt_context_t context);
static void xbt_ctx_sysv_start(xbt_context_t context);
static void xbt_ctx_sysv_stop(int exit_code);
static void xbt_ctx_sysv_stop(int exit_code);
static void xbt_ctx_sysv_swap(xbt_context_t context);
static void xbt_ctx_sysv_swap(xbt_context_t context);
static void xbt_ctx_sysv_schedule(xbt_context_t context);
static void xbt_ctx_sysv_schedule(xbt_context_t context);
static void xbt_ctx_sysv_yield(void);
static void xbt_ctx_sysv_yield(void);
static void xbt_ctx_sysv_suspend(xbt_context_t context);
static void xbt_ctx_sysv_suspend(xbt_context_t context);
static void xbt_ctx_sysv_resume(xbt_context_t context);
static void xbt_ctx_sysv_resume(xbt_context_t context);
static void xbt_ctx_sysv_wrapper(void);
/* callback: context fetching */
static void xbt_ctx_sysv_wrapper(void);
/* callback: context fetching */
{
xbt_ctx_sysv_t context = xbt_new0(s_xbt_ctx_sysv_t, 1);
{
xbt_ctx_sysv_t context = xbt_new0(s_xbt_ctx_sysv_t, 1);
- context->name = (char*)"maestro";
+
+ context->name = (char *) "maestro";
context->exception = xbt_new(ex_ctx_t, 1);
XBT_CTX_INITIALIZE(context->exception);
context->exception = xbt_new(ex_ctx_t, 1);
XBT_CTX_INITIALIZE(context->exception);
void_f_pvoid_t cleanup_func,
void *cleanup_arg, int argc, char **argv)
{
void_f_pvoid_t cleanup_func,
void *cleanup_arg, int argc, char **argv)
{
- VERB1("Create context %s",name);
+ VERB1("Create context %s", name);
xbt_ctx_sysv_t context = xbt_new0(s_xbt_ctx_sysv_t, 1);
context->code = code;
xbt_ctx_sysv_t context = xbt_new0(s_xbt_ctx_sysv_t, 1);
context->code = code;
pth_skaddr_makecontext(context->stack, STACK_SIZE);
context->uc.uc_stack.ss_size =
pth_sksize_makecontext(context->stack, STACK_SIZE);
pth_skaddr_makecontext(context->stack, STACK_SIZE);
context->uc.uc_stack.ss_size =
pth_sksize_makecontext(context->stack, STACK_SIZE);
- #ifdef HAVE_VALGRIND_VALGRIND_H
- context->valgrind_stack_id = VALGRIND_STACK_REGISTER(
- context->uc.uc_stack.ss_sp,
- ((char *)context->uc.uc_stack.ss_sp) + context->uc.uc_stack.ss_size
- );
- #endif /* HAVE_VALGRIND_VALGRIND_H */
+#ifdef HAVE_VALGRIND_VALGRIND_H
+ context->valgrind_stack_id =
+ VALGRIND_STACK_REGISTER(context->uc.uc_stack.ss_sp,
+ ((char *) context->uc.uc_stack.ss_sp) +
+ context->uc.uc_stack.ss_size);
+#endif /* HAVE_VALGRIND_VALGRIND_H */
context->exception = xbt_new(ex_ctx_t, 1);
XBT_CTX_INITIALIZE(context->exception);
context->exception = xbt_new(ex_ctx_t, 1);
XBT_CTX_INITIALIZE(context->exception);
if (context->exception)
free(context->exception);
if (context->exception)
free(context->exception);
- #ifdef HAVE_VALGRIND_VALGRIND_H
- VALGRIND_STACK_DEREGISTER(((xbt_ctx_sysv_t)context)->valgrind_stack_id);
- #endif /* HAVE_VALGRIND_VALGRIND_H */
+#ifdef HAVE_VALGRIND_VALGRIND_H
+ VALGRIND_STACK_DEREGISTER(((xbt_ctx_sysv_t) context)->valgrind_stack_id);
+#endif /* HAVE_VALGRIND_VALGRIND_H */
/* finally destroy the context */
free(context);
/* finally destroy the context */
free(context);
static void xbt_ctx_sysv_kill(xbt_context_t context)
{
static void xbt_ctx_sysv_kill(xbt_context_t context)
{
- DEBUG2("Kill context '%s' (from '%s')",context->name,current_context->name);
+ DEBUG2("Kill context '%s' (from '%s')", context->name,
+ current_context->name);
context->iwannadie = 1;
xbt_ctx_sysv_swap(context);
}
context->iwannadie = 1;
xbt_ctx_sysv_swap(context);
}
*/
static void xbt_ctx_sysv_schedule(xbt_context_t context)
{
*/
static void xbt_ctx_sysv_schedule(xbt_context_t context)
{
- DEBUG1("Schedule context '%s'",context->name);
+ DEBUG1("Schedule context '%s'", context->name);
xbt_assert0((current_context == maestro_context),
"You are not supposed to run this function here!");
xbt_ctx_sysv_swap(context);
xbt_assert0((current_context == maestro_context),
"You are not supposed to run this function here!");
xbt_ctx_sysv_swap(context);
*/
static void xbt_ctx_sysv_yield(void)
{
*/
static void xbt_ctx_sysv_yield(void)
{
- DEBUG1("Yielding context '%s'",current_context->name);
+ DEBUG1("Yielding context '%s'", current_context->name);
xbt_assert0((current_context != maestro_context),
"You are not supposed to run this function here!");
xbt_ctx_sysv_swap(current_context);
xbt_assert0((current_context != maestro_context),
"You are not supposed to run this function here!");
xbt_ctx_sysv_swap(current_context);
static void xbt_ctx_sysv_start(xbt_context_t context)
{
static void xbt_ctx_sysv_start(xbt_context_t context)
{
- DEBUG1("Start context '%s'",context->name);
+ DEBUG1("Start context '%s'", context->name);
makecontext(&(((xbt_ctx_sysv_t) context)->uc), xbt_ctx_sysv_wrapper, 0);
}
makecontext(&(((xbt_ctx_sysv_t) context)->uc), xbt_ctx_sysv_wrapper, 0);
}
static void xbt_ctx_sysv_swap(xbt_context_t context)
{
static void xbt_ctx_sysv_swap(xbt_context_t context)
{
- DEBUG2("Swap context: '%s' -> '%s'",current_context->name,context->name);
+ DEBUG2("Swap context: '%s' -> '%s'", current_context->name, context->name);
xbt_assert0(current_context, "You have to call context_init() first.");
xbt_assert0(context, "Invalid argument");
xbt_assert0(current_context, "You have to call context_init() first.");
xbt_assert0(context, "Invalid argument");
- DEBUG1("Suspend context: '%s'",current_context->name);
+ DEBUG1("Suspend context: '%s'", current_context->name);
xbt_ctx_sysv_t prev_context = ((xbt_ctx_sysv_t) context)->prev;
current_context = (xbt_context_t) (((xbt_ctx_sysv_t) context)->prev);
xbt_ctx_sysv_t prev_context = ((xbt_ctx_sysv_t) context)->prev;
current_context = (xbt_context_t) (((xbt_ctx_sysv_t) context)->prev);
- DEBUG2("Resume context: '%s' (from '%s')",context->name,current_context->name);
+ DEBUG2("Resume context: '%s' (from '%s')", context->name,
+ current_context->name);
((xbt_ctx_sysv_t) context)->prev = (xbt_ctx_sysv_t) current_context;
current_context = context;
((xbt_ctx_sysv_t) context)->prev = (xbt_ctx_sysv_t) current_context;
current_context = context;
xbt_ctx_thread_factory_create_master_context(xbt_context_t * maestro);
static int xbt_ctx_thread_factory_finalize(xbt_context_factory_t * factory);
xbt_ctx_thread_factory_create_master_context(xbt_context_t * maestro);
static int xbt_ctx_thread_factory_finalize(xbt_context_factory_t * factory);
static void xbt_ctx_thread_free(xbt_context_t context);
static void xbt_ctx_thread_free(xbt_context_t context);
static void xbt_ctx_thread_kill(xbt_context_t context);
static void xbt_ctx_thread_kill(xbt_context_t context);
static void xbt_ctx_thread_schedule(xbt_context_t context);
static void xbt_ctx_thread_schedule(xbt_context_t context);
static void xbt_ctx_thread_yield(void);
static void xbt_ctx_thread_yield(void);
static void xbt_ctx_thread_start(xbt_context_t context);
static void xbt_ctx_thread_start(xbt_context_t context);
static void xbt_ctx_thread_stop(int exit_code);
static void xbt_ctx_thread_stop(int exit_code);
static void xbt_ctx_thread_swap(xbt_context_t context);
static void xbt_ctx_thread_swap(xbt_context_t context);
static void xbt_ctx_thread_schedule(xbt_context_t context);
static void xbt_ctx_thread_schedule(xbt_context_t context);
static void xbt_ctx_thread_yield(void);
static void xbt_ctx_thread_yield(void);
static void xbt_ctx_thread_suspend(xbt_context_t context);
static void xbt_ctx_thread_suspend(xbt_context_t context);
static void xbt_ctx_thread_resume(xbt_context_t context);
static void xbt_ctx_thread_resume(xbt_context_t context);
static void *xbt_ctx_thread_wrapper(void *param);
void xbt_ctx_thread_factory_init(xbt_context_factory_t * factory)
static void *xbt_ctx_thread_wrapper(void *param);
void xbt_ctx_thread_factory_init(xbt_context_factory_t * factory)
xbt_ctx_thread_factory_create_master_context(xbt_context_t * maestro)
{
*maestro = (xbt_context_t) xbt_new0(s_xbt_ctx_thread_t, 1);
xbt_ctx_thread_factory_create_master_context(xbt_context_t * maestro)
{
*maestro = (xbt_context_t) xbt_new0(s_xbt_ctx_thread_t, 1);
- (*maestro)->name = (char*)"maestro";
+ (*maestro)->name = (char *) "maestro";
{
xbt_ctx_thread_t context = xbt_new0(s_xbt_ctx_thread_t, 1);
{
xbt_ctx_thread_t context = xbt_new0(s_xbt_ctx_thread_t, 1);
- VERB1("Create context %s",name);
+ VERB1("Create context %s", name);
context->code = code;
context->name = xbt_strdup(name);
context->begin = xbt_os_sem_init(0);
context->code = code;
context->name = xbt_strdup(name);
context->begin = xbt_os_sem_init(0);
static void xbt_ctx_thread_kill(xbt_context_t context)
{
static void xbt_ctx_thread_kill(xbt_context_t context)
{
- DEBUG1("Kill context '%s'",context->name);
+ DEBUG1("Kill context '%s'", context->name);
context->iwannadie = 1;
xbt_ctx_thread_swap(context);
}
context->iwannadie = 1;
xbt_ctx_thread_swap(context);
}
*/
static void xbt_ctx_thread_schedule(xbt_context_t context)
{
*/
static void xbt_ctx_thread_schedule(xbt_context_t context)
{
- DEBUG1("Schedule context '%s'",context->name);
+ DEBUG1("Schedule context '%s'", context->name);
xbt_assert0((current_context == maestro_context),
"You are not supposed to run this function here!");
xbt_ctx_thread_swap(context);
xbt_assert0((current_context == maestro_context),
"You are not supposed to run this function here!");
xbt_ctx_thread_swap(context);
*/
static void xbt_ctx_thread_yield(void)
{
*/
static void xbt_ctx_thread_yield(void)
{
- DEBUG1("Yield context '%s'",current_context->name);
+ DEBUG1("Yield context '%s'", current_context->name);
xbt_assert0((current_context != maestro_context),
"You are not supposed to run this function here!");
xbt_ctx_thread_swap(current_context);
xbt_assert0((current_context != maestro_context),
"You are not supposed to run this function here!");
xbt_ctx_thread_swap(current_context);
{
xbt_ctx_thread_t ctx_thread = (xbt_ctx_thread_t) context;
{
xbt_ctx_thread_t ctx_thread = (xbt_ctx_thread_t) context;
- DEBUG1("Start context '%s'",context->name);
+ DEBUG1("Start context '%s'", context->name);
/* create and start the process */
ctx_thread->thread =
xbt_os_thread_create(ctx_thread->name, xbt_ctx_thread_wrapper,
/* create and start the process */
ctx_thread->thread =
xbt_os_thread_create(ctx_thread->name, xbt_ctx_thread_wrapper,
}
static void xbt_ctx_thread_swap(xbt_context_t context)
}
static void xbt_ctx_thread_swap(xbt_context_t context)
-{
- DEBUG2("Swap context: '%s' -> '%s'",current_context->name,context->name);
+{
+ DEBUG2("Swap context: '%s' -> '%s'", current_context->name, context->name);
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 */
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 */
/* save the current context */
xbt_context_t self = current_context;
/* save the current context */
xbt_context_t self = current_context;
- DEBUG1("Suspend context '%s'",context->name);
-
+ DEBUG1("Suspend context '%s'", context->name);
+
/* update the current context to this context */
current_context = context;
/* update the current context to this context */
current_context = context;
/* save the current context */
xbt_context_t self = current_context;
/* save the current context */
xbt_context_t self = current_context;
- DEBUG1("Resume context '%s'",context->name);
+ DEBUG1("Resume context '%s'", context->name);
/* update the current context */
current_context = context;
/* update the current context */
current_context = context;