Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Expose (and use) storageCreatedCallbacks in C
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 30 Nov 2015 14:55:58 +0000 (15:55 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 30 Nov 2015 14:55:58 +0000 (15:55 +0100)
src/simix/smx_environment.c
src/simix/smx_global.c
src/surf/callbacks.cpp
src/surf/callbacks.h

index 9217866..9b4c6db 100644 (file)
@@ -45,15 +45,5 @@ void SIMIX_create_environment(const char *file)
 
 void SIMIX_post_create_environment(void)
 {
 
 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();
 }
   surf_presolve();
 }
index 83ef7f3..c501208 100644 (file)
@@ -159,6 +159,12 @@ static void kill_process(smx_process_t process)
   SIMIX_process_kill(process, NULL);
 }
 
   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.
 /**
  * \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);
     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) {
 
   }
   if (!simix_timers) {
index d8d48c7..4d1d041 100644 (file)
@@ -19,3 +19,14 @@ void surf_host_created_callback(void (*callback)(sg_host_t))
     callback(h);
   });
 }
     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);
+  });
+}
index efc947b..4d8d66c 100644 (file)
 
 #include <xbt/base.h>
 #include "simgrid/host.h"
 
 #include <xbt/base.h>
 #include "simgrid/host.h"
+#include "simgrid/msg.h"
 
 SG_BEGIN_DECL();
 
 XBT_PRIVATE void surf_host_created_callback(void (*callback)(sg_host_t));
 
 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();
 
 
 SG_END_DECL();