Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sanitizes host user_data: create a lib level
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 8 Nov 2015 20:57:27 +0000 (21:57 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 8 Nov 2015 20:57:27 +0000 (21:57 +0100)
include/simgrid/host.h
src/msg/msg_host.c
src/simdag/private.h
src/simdag/sd_workstation.c
src/simgrid/host.cpp

index 1b38065..b422c4f 100644 (file)
@@ -25,6 +25,10 @@ class Cpu;
 #else
 #define DEFINE_EXTERNAL_CLASS(klass) typedef struct klass klass;
 #endif
+// ========== User Data ==============
+XBT_PUBLIC(void*) sg_host_user(sg_host_t host);
+XBT_PUBLIC(void) sg_host_user_set(sg_host_t host, void* userdata);
+XBT_PUBLIC(void) sg_host_user_destroy(sg_host_t host);
 
 // ========== MSG Layer ==============
 typedef struct s_msg_host_priv *msg_host_priv_t;
index 02d7f40..f96e1ee 100644 (file)
@@ -75,7 +75,6 @@ msg_host_t MSG_host_by_name(const char *name)
   return (msg_host_t) xbt_lib_get_elm_or_null(host_lib,name);
 }
 
-static const char *msg_data = "data";
 /** \ingroup m_host_management
  *
  * \brief Set the user data of a #msg_host_t.
@@ -83,9 +82,8 @@ static const char *msg_data = "data";
  * This functions checks whether some data has already been associated to \a host
    or not and attach \a data to \a host if it is possible.
  */
-msg_error_t MSG_host_set_data(msg_host_t host, void *data)
-{
-  MSG_host_set_property_value(host, msg_data, data, NULL);
+msg_error_t MSG_host_set_data(msg_host_t host, void *data) {
+  sg_host_user_set(host, data);
   return MSG_OK;
 }
 
@@ -96,9 +94,8 @@ msg_error_t MSG_host_set_data(msg_host_t host, void *data)
  * This functions checks whether \a host is a valid pointer or not and return
    the user data associated to \a host if it is possible.
  */
-void *MSG_host_get_data(msg_host_t host)
-{
-  return (void *)MSG_host_get_property_value(host, msg_data);
+void *MSG_host_get_data(msg_host_t host) {
+  return sg_host_user(host);
 }
 
 /** \ingroup m_host_management
index b99e992..906a85b 100644 (file)
@@ -53,7 +53,6 @@ extern XBT_PRIVATE SD_global_t sd_global;
 /* Workstation */
 typedef s_xbt_dictelm_t s_SD_workstation_t;
 typedef struct SD_workstation {
-  void *data;                   /* user data */
   e_SD_workstation_access_mode_t access_mode;
 
   xbt_fifo_t task_fifo;         /* only used in sequential mode */
index c92d07d..a5cb1b8 100644 (file)
@@ -25,7 +25,6 @@ SD_workstation_t __SD_workstation_create(void *surf_workstation,
   const char *name;
 
   workstation = xbt_new(s_SD_workstation_priv_t, 1);
-  workstation->data = data;     /* user data */
   workstation->access_mode = SD_WORKSTATION_SHARED_ACCESS;      /* default mode is shared */
   workstation->task_fifo = NULL;
   workstation->current_task = NULL;
@@ -33,6 +32,7 @@ SD_workstation_t __SD_workstation_create(void *surf_workstation,
   name = surf_resource_name(surf_workstation);
   sg_host_t sg_host = sg_host_by_name(name);
   sg_host_sd_set(sg_host,workstation);
+  sg_host_user_set(sg_host,data);
   return sg_host;
 }
 
@@ -113,7 +113,7 @@ int SD_workstation_get_number(void)
  */
 void *SD_workstation_get_data(SD_workstation_t workstation)
 {
-  return sg_host_sd(workstation)->data;
+  return sg_host_user(workstation);
 }
 
 /**
@@ -128,7 +128,7 @@ void *SD_workstation_get_data(SD_workstation_t workstation)
  */
 void SD_workstation_set_data(SD_workstation_t workstation, void *data)
 {
-       sg_host_sd(workstation)->data = data;
+       sg_host_user_set(workstation, data);
 }
 
 /**
index 74e03b0..0d2785c 100644 (file)
@@ -42,7 +42,7 @@ int SD_HOST_LEVEL;
 int SIMIX_HOST_LEVEL;
 int ROUTING_HOST_LEVEL;
 int SURF_CPU_LEVEL;
-
+int USER_HOST_LEVEL;
 
 #include "src/msg/msg_private.h" // MSG_host_priv_free. FIXME: killme
 #include "src/simdag/private.h" // __SD_workstation_destroy. FIXME: killme
@@ -57,14 +57,24 @@ static XBT_INLINE void routing_asr_host_free(void *p) {
   delete static_cast<RoutingEdge*>(p);
 }
 
-
-void sg_host_init() { // FIXME: only add the needed levels
+void sg_host_init() {
   MSG_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __MSG_host_priv_free);
   SD_HOST_LEVEL = xbt_lib_add_level(host_lib,__SD_workstation_destroy);
 
   SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy);
   SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_cpu_free);
   ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free);
+  USER_HOST_LEVEL = xbt_lib_add_level(host_lib,NULL);
+}
+// ========== User data Layer ==========
+void *sg_host_user(sg_host_t host) {
+       return xbt_lib_get_level(host, USER_HOST_LEVEL);
+}
+void sg_host_user_set(sg_host_t host, void* userdata) {
+       xbt_lib_set(host_lib,host->key,USER_HOST_LEVEL,userdata);
+}
+void sg_host_user_destroy(sg_host_t host) {
+       xbt_lib_unset(host_lib,host->key,USER_HOST_LEVEL,1);
 }
 
 // ========== MSG Layer ==============