From: Gabriel Corona Date: Mon, 30 Nov 2015 14:55:58 +0000 (+0100) Subject: [surf] Expose (and use) storageCreatedCallbacks in C X-Git-Tag: v3_13~1519 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/514236282cc9b3e2eb76a2f41fdbbd6103b4c862?ds=sidebyside [surf] Expose (and use) storageCreatedCallbacks in C --- diff --git a/src/simix/smx_environment.c b/src/simix/smx_environment.c index 9217866240..9b4c6db82b 100644 --- a/src/simix/smx_environment.c +++ b/src/simix/smx_environment.c @@ -45,15 +45,5 @@ void SIMIX_create_environment(const char *file) void SIMIX_post_create_environment(void) { - void **storage = NULL; - xbt_lib_cursor_t cursor = NULL; - char *name = NULL; - - /* Create storage at SIMIX level */ - xbt_lib_foreach(storage_lib, cursor, name, storage) { - if(storage[SURF_STORAGE_LEVEL]) - SIMIX_storage_create(name, storage[SURF_STORAGE_LEVEL], NULL); - } - surf_presolve(); } diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 83ef7f340e..c501208e8d 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -159,6 +159,12 @@ static void kill_process(smx_process_t process) SIMIX_process_kill(process, NULL); } +static void SIMIX_storage_create_(smx_storage_t storage) +{ + const char* key = xbt_dict_get_elm_key(storage); + SIMIX_storage_create(key, storage, NULL); +} + /** * \ingroup SIMIX_API * \brief Initialize SIMIX internal data. @@ -222,6 +228,7 @@ void SIMIX_global_init(int *argc, char **argv) sg_platf_init(); sg_platf_postparse_add_cb(SIMIX_post_create_environment); surf_host_created_callback(SIMIX_host_create); + surf_storage_created_callback(SIMIX_storage_create_); } if (!simix_timers) { diff --git a/src/surf/callbacks.cpp b/src/surf/callbacks.cpp index d8d48c729a..4d1d04148e 100644 --- a/src/surf/callbacks.cpp +++ b/src/surf/callbacks.cpp @@ -19,3 +19,14 @@ void surf_host_created_callback(void (*callback)(sg_host_t)) callback(h); }); } + +void surf_storage_created_callback(void (*callback)(sg_storage_t)) +{ + storageCreatedCallbacks.connect([callback](Storage* storage) { + const char* id = storage->getName(); + // TODO, create sg_storage_by_name + sg_storage_t s = xbt_lib_get_elm_or_null(storage_lib, id); + xbt_assert(s != NULL, "Storage not found for name %s", id); + callback(s); + }); +} diff --git a/src/surf/callbacks.h b/src/surf/callbacks.h index efc947b4c3..4d8d66c91a 100644 --- a/src/surf/callbacks.h +++ b/src/surf/callbacks.h @@ -14,10 +14,12 @@ #include #include "simgrid/host.h" +#include "simgrid/msg.h" SG_BEGIN_DECL(); XBT_PRIVATE void surf_host_created_callback(void (*callback)(sg_host_t)); +XBT_PRIVATE void surf_storage_created_callback(void (*callback)(sg_storage_t)); SG_END_DECL();