-Unify smx_current_context variable for both sequential and // raw/sysv contexts.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9553
48e7efb5-ca39-0410-a469-
dd3cf9ba447f
#include "xbt/swag.h"
#include "simix/datatypes.h"
#include "xbt/swag.h"
#include "simix/datatypes.h"
+#include "gras_config.h"
SG_BEGIN_DECL()
/******************************** Context *************************************/
SG_BEGIN_DECL()
/******************************** Context *************************************/
extern smx_ctx_factory_initializer_t smx_factory_initializer_to_use;
extern char* smx_context_factory_name;
extern int smx_context_stack_size;
extern smx_ctx_factory_initializer_t smx_factory_initializer_to_use;
extern char* smx_context_factory_name;
extern int smx_context_stack_size;
+
+#ifdef CONTEXT_THREADS
+extern __thread smx_context_t smx_current_context;
+#else
extern smx_context_t smx_current_context;
extern smx_context_t smx_current_context;
/* *********************** */
/* Context type definition */
/* *********************** */
/* Context type definition */
#include "xbt/swag.h"
#include "private.h"
#include "simix/context.h"
#include "xbt/swag.h"
#include "private.h"
#include "simix/context.h"
+#include "gras_config.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix,
"Context switching mecanism");
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix,
"Context switching mecanism");
char* smx_context_factory_name = NULL; /* factory name specified by --cfg=contexts/factory:value */
smx_ctx_factory_initializer_t smx_factory_initializer_to_use = NULL;
int smx_context_stack_size = 128 * 1024;
char* smx_context_factory_name = NULL; /* factory name specified by --cfg=contexts/factory:value */
smx_ctx_factory_initializer_t smx_factory_initializer_to_use = NULL;
int smx_context_stack_size = 128 * 1024;
+
+#ifdef CONTEXT_THREADS
+__thread smx_context_t smx_current_context;
+#else
smx_context_t smx_current_context;
smx_context_t smx_current_context;
static int smx_parallel_contexts = 1;
/**
static int smx_parallel_contexts = 1;
/**
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
-static xbt_parmap_t parmap;
-
-static __thread smx_context_t current_context;
+static xbt_parmap_t parmap;
#endif
static void smx_ctx_raw_wrapper(smx_ctx_raw_t context);
#endif
static void smx_ctx_raw_wrapper(smx_ctx_raw_t context);
}else{
maestro_raw_context = context;
}else{
maestro_raw_context = context;
- current_context = (smx_context_t) maestro_raw_context;
}
return (smx_context_t) context;
}
return (smx_context_t) context;
static void smx_ctx_raw_resume_parallel(smx_process_t process)
{
smx_ctx_raw_t context = (smx_ctx_raw_t)process->context;
static void smx_ctx_raw_resume_parallel(smx_process_t process)
{
smx_ctx_raw_t context = (smx_ctx_raw_t)process->context;
- current_context = (smx_context_t)context;
+ smx_current_context = (smx_context_t)context;
raw_swapcontext(
&context->old_stack_top,
context->stack_top);
raw_swapcontext(
&context->old_stack_top,
context->stack_top);
- current_context = (smx_context_t)maestro_raw_context;
+ smx_current_context = (smx_context_t)maestro_raw_context;
}
static void smx_ctx_raw_runall_parallel(xbt_dynar_t processes)
}
static void smx_ctx_raw_runall_parallel(xbt_dynar_t processes)
static smx_context_t smx_ctx_raw_self_parallel(void)
{
static smx_context_t smx_ctx_raw_self_parallel(void)
{
- return current_context;
+ return smx_current_context;
}
static int smx_ctx_raw_get_thread_id(){
}
static int smx_ctx_raw_get_thread_id(){
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
static xbt_parmap_t parmap;
static xbt_parmap_t parmap;
static smx_context_t
smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv,
static smx_context_t
smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv,
parmap = xbt_parmap_new(2);
(*factory)->runall = smx_ctx_sysv_runall_parallel;
(*factory)->self = smx_ctx_sysv_self_parallel;
parmap = xbt_parmap_new(2);
(*factory)->runall = smx_ctx_sysv_runall_parallel;
(*factory)->self = smx_ctx_sysv_self_parallel;
+ (*factory)->get_thread_id = smx_ctx_sysv_get_thread_id;
#else
THROW0(arg_error, 0, "No thread support for parallel context execution");
#endif
#else
THROW0(arg_error, 0, "No thread support for parallel context execution");
#endif
void smx_ctx_sysv_resume_parallel(smx_process_t process)
{
smx_context_t context = process->context;
void smx_ctx_sysv_resume_parallel(smx_process_t process)
{
smx_context_t context = process->context;
- xbt_os_thread_set_extra_data(context);
+ smx_current_context = (smx_context_t)context;
int rv = swapcontext(&((smx_ctx_sysv_t)context)->old_uc, &((smx_ctx_sysv_t) context)->uc);
int rv = swapcontext(&((smx_ctx_sysv_t)context)->old_uc, &((smx_ctx_sysv_t) context)->uc);
- xbt_os_thread_set_extra_data(NULL);
+ smx_current_context = (smx_context_t)maestro_context;
xbt_assert0((rv == 0), "Context swapping failure");
}
xbt_assert0((rv == 0), "Context swapping failure");
}
smx_context_t smx_ctx_sysv_self_parallel(void)
{
smx_context_t smx_ctx_sysv_self_parallel(void)
{
- smx_context_t self_context = (smx_context_t) xbt_os_thread_get_extra_data();
- return self_context ? self_context : (smx_context_t) maestro_context;
+ /*smx_context_t self_context = (smx_context_t) xbt_os_thread_get_extra_data();
+ return self_context ? self_context : (smx_context_t) maestro_context;*/
+ return smx_current_context;
+}
+
+int smx_ctx_sysv_get_thread_id(void)
+{
+ return (int)(unsigned long)xbt_os_thread_get_extra_data();
void smx_ctx_sysv_runall(xbt_dynar_t processes);
void smx_ctx_sysv_resume_parallel(smx_process_t new_context);
void smx_ctx_sysv_runall_parallel(xbt_dynar_t processes);
void smx_ctx_sysv_runall(xbt_dynar_t processes);
void smx_ctx_sysv_resume_parallel(smx_process_t new_context);
void smx_ctx_sysv_runall_parallel(xbt_dynar_t processes);
+int smx_ctx_sysv_get_thread_id(void);
smx_context_t smx_ctx_sysv_self_parallel(void);
SG_END_DECL()
smx_context_t smx_ctx_sysv_self_parallel(void);
SG_END_DECL()