#include "xbt.h" /* calloc, printf */
#include "simgrid_config.h" /* getline */
#include "instr/instr_private.h"
-void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory);
+void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory);
XBT_LOG_NEW_DEFAULT_CATEGORY(actions,
"Messages specific for this msg example");
{
MSG_error_t res = MSG_OK;
- factory_initializer_to_use = SIMIX_ctx_raw_factory_init;
+ smx_factory_initializer_to_use = SIMIX_ctx_raw_factory_init;
+
/* Check the given arguments */
MSG_global_init(&argc, argv);
if (argc < 3) {
-/*Hack: let msg load directly the right factory */
-typedef void (*SIMIX_ctx_factory_initializer_t)(smx_context_factory_t*);
-extern SIMIX_ctx_factory_initializer_t factory_initializer_to_use;
-
-extern int _surf_parallel_contexts;
+/* Hack: let msg load directly the right factory */
+typedef void (*smx_ctx_factory_initializer_t)(smx_context_factory_t*);
+extern smx_ctx_factory_initializer_t smx_factory_initializer_to_use;
+extern char* smx_context_factory_name;
+extern int smx_parallel_contexts;
smx_context_t smx_current_context;
/* *********************** */
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix,
"Context switching mecanism");
-SIMIX_ctx_factory_initializer_t factory_initializer_to_use = NULL;
+char* smx_context_factory_name = NULL; /* factory name specified by --cfg=simix/context=value */
+smx_ctx_factory_initializer_t smx_factory_initializer_to_use = NULL;
/**
* This function is called by SIMIX_global_init() to initialize the context module.
void SIMIX_context_mod_init(void)
{
if (!simix_global->context_factory) {
- /* select context factory to use to create the context(depends of the macro definitions) */
- if (factory_initializer_to_use) {
- (*factory_initializer_to_use)(&(simix_global->context_factory));
+ /* select the context factory to use to create the contexts */
+ if (smx_factory_initializer_to_use) {
+ (*smx_factory_initializer_to_use)(&(simix_global->context_factory));
}
- else {
-#ifdef CONTEXT_UCONTEXT /* use ucontext */
- SIMIX_ctx_sysv_factory_init(&simix_global->context_factory);
-#elif defined(CONTEXT_THREADS) /* Use os threads (either pthreads or windows ones) */
- SIMIX_ctx_thread_factory_init(&simix_global->context_factory);
-#else
-#error ERROR [__FILE__, line __LINE__]: no context implementation specified.
-#endif
+ else { /* use the factory specified by --cfg=simix/ctx:value */
+ if (smx_context_factory_name == NULL || !strcmp(smx_context_factory_name, "ucontext")) {
+ /* use ucontext */
+ SIMIX_ctx_sysv_factory_init(&simix_global->context_factory);
+ }
+ else if (!strcmp(smx_context_factory_name, "thread")) {
+ /* use os threads (either pthreads or windows ones) */
+ SIMIX_ctx_thread_factory_init(&simix_global->context_factory);
+ }
+ else if (!strcmp(smx_context_factory_name, "raw")) {
+ /* use raw contexts */
+ SIMIX_ctx_raw_factory_init(&simix_global->context_factory);
+ }
+ else {
+ xbt_die("Invalid context factory specified");
+ }
}
}
}
finalize_factory = simix_global->context_factory->finalize;
(*finalize_factory) (&simix_global->context_factory);
}
+ xbt_free(smx_context_factory_name);
}
(*factory)->suspend = smx_ctx_raw_suspend;
(*factory)->name = "smx_raw_context_factory";
- if(_surf_parallel_contexts){
+ if (smx_parallel_contexts) {
#ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */
parmap = xbt_parmap_new(2);
(*factory)->runall = smx_ctx_raw_runall_parallel;
(*factory)->suspend = smx_ctx_sysv_suspend;
(*factory)->name = "smx_sysv_context_factory";
- if(_surf_parallel_contexts){
+ if (smx_parallel_contexts) {
#ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */
parmap = xbt_parmap_new(2);
(*factory)->runall = smx_ctx_sysv_runall_parallel;
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
+int smx_parallel_contexts = 0;
+
typedef struct s_smx_ctx_thread {
s_smx_ctx_base_t super; /* Fields of super implementation */
xbt_os_thread_t thread; /* a plain dumb thread (portable to posix or windows) */
(*factory)->stop = smx_ctx_thread_stop;
(*factory)->suspend = smx_ctx_thread_suspend;
- if(_surf_parallel_contexts)
+ if (smx_parallel_contexts)
(*factory)->runall = smx_ctx_thread_runall_parallel;
else
(*factory)->runall = smx_ctx_thread_runall_serial;
if (issuer != simix_global->maestro_process){
issuer->request.issuer = issuer;
- if (_surf_parallel_contexts)
+ if (smx_parallel_contexts)
xbt_os_mutex_acquire(sync_req_positions);
xbt_heap_push(req_todo,&issuer->request,issuer->pid);
DEBUG4("Pushed request %s (%d) of %s; now %d requests waiting",
SIMIX_request_name(issuer->request.call), issuer->request.call,
issuer->name,xbt_heap_size(req_todo));
- if (_surf_parallel_contexts)
+ if (smx_parallel_contexts)
xbt_os_mutex_release(sync_req_positions);
DEBUG3("Yield process '%s' on request of type %s (%d)", issuer->name,
#include "xbt/config.h"
#include "xbt/str.h"
#include "surf/surf_private.h"
+#include "simix/context.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
"About the configuration of surf (and the rest of the simulation)");
xbt_cfg_t _surf_cfg_set = NULL;
-
/* Parse the command line, looking for options */
static void surf_config_cmd_line(int *argc, char **argv)
{
xbt_dict_preinit();
}
-int _surf_parallel_contexts = 0;
+static void _surf_cfg_cb_context_factory(const char *name, int pos)
+{
+ smx_context_factory_name = xbt_cfg_get_string(_surf_cfg_set, name);
+}
static void _surf_cfg_cb_parallel_contexts(const char *name, int pos)
{
- _surf_parallel_contexts = 1;
+ smx_parallel_contexts = 1;
}
static void _surf_cfg_cb__surf_network_fullduplex(const char *name,
_surf_cfg_cb_model_check which sets it's value to 1 (instead of the defalut value 0)
xbt_cfg_set_int(_surf_cfg_set, "model-check", default_value_int); */
+ /* context factory */
+ default_value = xbt_strdup("ucontext");
+ xbt_cfg_register(&_surf_cfg_set, "simix/context",
+ "Context factory to use in SIMIX (ucontext, thread or raw)",
+ xbt_cfgelm_string, &default_value, 1, 1, _surf_cfg_cb_context_factory, NULL);
+
/* parallel contexts */
default_value_int = 0;
xbt_cfg_register(&_surf_cfg_set, "parallel-contexts",