Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Align host get/set_data() with the Extendable version of that feature
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 14 Sep 2019 20:42:53 +0000 (22:42 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 14 Sep 2019 20:42:53 +0000 (22:42 +0200)
examples/deprecated/simdag/scheduling/sd_scheduling.c
include/simgrid/host.h
include/simgrid/s4u/Host.hpp
src/msg/msg_legacy.cpp
src/s4u/s4u_Host.cpp
src/surf/surf_interface.cpp
src/xbt/xbt_main.cpp

index fb39c8a..be2963a 100644 (file)
@@ -24,26 +24,26 @@ struct _HostAttribute {
 
 static double sg_host_get_available_at(sg_host_t host)
 {
-  HostAttribute attr = (HostAttribute) sg_host_user(host);
+  HostAttribute attr = (HostAttribute)sg_host_get_data(host);
   return attr->available_at;
 }
 
 static void sg_host_set_available_at(sg_host_t host, double time)
 {
-  HostAttribute attr = (HostAttribute) sg_host_user(host);
+  HostAttribute attr = (HostAttribute)sg_host_get_data(host);
   attr->available_at = time;
-  sg_host_user_set(host, attr);
+  sg_host_set_data(host, attr);
 }
 
 static SD_task_t sg_host_get_last_scheduled_task( sg_host_t host){
-  HostAttribute attr = (HostAttribute) sg_host_user(host);
+  HostAttribute attr = (HostAttribute)sg_host_get_data(host);
   return attr->last_scheduled_task;
 }
 
 static void sg_host_set_last_scheduled_task(sg_host_t host, SD_task_t task){
-  HostAttribute attr = (HostAttribute) sg_host_user(host);
+  HostAttribute attr       = (HostAttribute)sg_host_get_data(host);
   attr->last_scheduled_task=task;
-  sg_host_user_set(host, attr);
+  sg_host_set_data(host, attr);
 }
 
 static xbt_dynar_t get_ready_tasks(xbt_dynar_t dax)
@@ -155,11 +155,11 @@ int main(int argc, char **argv)
   SD_create_environment(argv[1]);
 
   /*  Allocating the host attribute */
-  int total_nhosts = sg_host_count();
+  unsigned int total_nhosts = sg_host_count();
   sg_host_t *hosts = sg_host_list();
 
   for (cursor = 0; cursor < total_nhosts; cursor++)
-    sg_host_user_set(hosts[cursor], xbt_new0(struct _HostAttribute, 1));
+    sg_host_set_data(hosts[cursor], xbt_new0(struct _HostAttribute, 1));
 
   /* load the DAX file */
   xbt_dynar_t dax = SD_daxload(argv[2]);
@@ -246,8 +246,8 @@ int main(int argc, char **argv)
   xbt_dynar_free_container(&dax);
 
   for (cursor = 0; cursor < total_nhosts; cursor++) {
-    free(sg_host_user(hosts[cursor]));
-    sg_host_user_set(hosts[cursor], NULL);
+    free(sg_host_get_data(hosts[cursor]));
+    sg_host_set_data(hosts[cursor], NULL);
   }
 
   xbt_free(hosts);
index bdb3d89..30db249 100644 (file)
@@ -47,15 +47,18 @@ XBT_PUBLIC const char* sg_host_get_name(sg_host_t host);
 // ========== User Data ==============
 /** @brief Return the user data of a #sg_host_t.
  *
- * This functions returns the user data associated to @a host if it is possible.
+ * This functions returns the user data associated to @a host if any.
  */
-XBT_PUBLIC void* sg_host_user(sg_host_t host);
+XBT_PUBLIC void* sg_host_get_data(sg_host_t host);
+XBT_ATTRIB_DEPRECATED_v327("Please use sg_host_get_data()") XBT_PUBLIC void* sg_host_user(sg_host_t host);
 /** @brief Set the user data of a #sg_host_t.
  *
- * This functions attach @a data to @a host if it is possible.
+ * This functions attach @a data to @a 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);
+XBT_PUBLIC void sg_host_set_data(sg_host_t host, void* userdata);
+XBT_ATTRIB_DEPRECATED_v327("Please use sg_host_set_data()") XBT_PUBLIC
+    void sg_host_user_set(sg_host_t host, void* userdata);
+XBT_ATTRIB_DEPRECATED_v327("Please use sg_host_set_data(h, NULL)") XBT_PUBLIC void sg_host_user_destroy(sg_host_t host);
 
 // ========= storage related functions ============
 /** @brief Return the list of mount point names on an host.
index 7702d6b..c136667 100644 (file)
@@ -157,6 +157,4 @@ public:
 } // namespace s4u
 } // namespace simgrid
 
-extern int USER_HOST_LEVEL;
-
 #endif /* SIMGRID_S4U_HOST_HPP */
index ab142c8..0456773 100644 (file)
@@ -282,11 +282,11 @@ const char* MSG_host_get_name(sg_host_t host)
 }
 void* MSG_host_get_data(sg_host_t host)
 {
-  return sg_host_user(host);
+  return sg_host_get_data(host);
 }
 void MSG_host_set_data(sg_host_t host, void* data)
 {
-  return sg_host_user_set(host, data);
+  return sg_host_set_data(host, data);
 }
 xbt_dict_t MSG_host_get_mounted_storage_list(sg_host_t host)
 {
index 29eb24b..0453276 100644 (file)
@@ -18,8 +18,6 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_host, s4u, "Logging specific to the S4U hosts");
 XBT_LOG_EXTERNAL_CATEGORY(surf_route);
 
-int USER_HOST_LEVEL = -1;
-
 namespace simgrid {
 namespace xbt {
 template class Extendable<s4u::Host>;
@@ -387,17 +385,25 @@ xbt_dynar_t sg_hosts_as_dynar()
 // ========= Layering madness ==============*
 
 // ========== User data Layer ==========
-void* sg_host_user(sg_host_t host)
+void* sg_host_get_data(sg_host_t host)
+{
+  return host->get_data();
+}
+void sg_host_set_data(sg_host_t host, void* userdata)
+{
+  host->set_data(userdata);
+}
+void* sg_host_user(sg_host_t host) // deprecated
 {
-  return host->extension(USER_HOST_LEVEL);
+  return host->get_data();
 }
-void sg_host_user_set(sg_host_t host, void* userdata)
+void sg_host_user_set(sg_host_t host, void* userdata) // deprecated
 {
-  host->extension_set(USER_HOST_LEVEL, userdata);
+  host->set_data(userdata);
 }
-void sg_host_user_destroy(sg_host_t host)
+void sg_host_user_destroy(sg_host_t host) // deprecated
 {
-  host->extension_set(USER_HOST_LEVEL, nullptr);
+  host->set_data(nullptr);
 }
 
 // ========= storage related functions ============
index b657ce6..6123158 100644 (file)
@@ -12,6 +12,7 @@
 #include "src/simgrid/version.h"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/xml/platf.hpp"
+#include "src/xbt_modinter.h" /* whether initialization was already done */
 #include "surf/surf.hpp"
 #include "xbt/module.h"
 
@@ -287,12 +288,9 @@ void sg_version()
 
 void surf_init(int *argc, char **argv)
 {
-  if (USER_HOST_LEVEL != -1) // Already initialized
+  if (xbt_initialized > 0)
     return;
 
-  XBT_DEBUG("Create all Libs");
-  USER_HOST_LEVEL = simgrid::s4u::Host::extension_create(nullptr);
-
   xbt_init(argc, argv);
 
   sg_config_init(argc, argv);
index d60ccb0..bfdf869 100644 (file)
@@ -116,14 +116,14 @@ static void xbt_postexit()
 /** @brief Initialize the xbt mechanisms. */
 void xbt_init(int *argc, char **argv)
 {
-  simgrid::xbt::install_exception_handler();
-
   xbt_initialized++;
   if (xbt_initialized > 1) {
     XBT_DEBUG("XBT has been initialized %d times.", xbt_initialized);
     return;
   }
 
+  simgrid::xbt::install_exception_handler();
+
   xbt_binary_name = argv[0];
   xbt_cmdline     = xbt_dynar_new(sizeof(char*), NULL);
   for (int i = 0; i < *argc; i++)