Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New function: sg_hosts_as_dynar
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 18 Jul 2015 12:26:59 +0000 (14:26 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 18 Jul 2015 18:07:03 +0000 (20:07 +0200)
This was implemented several times, in each layer

include/simgrid/host.h
src/msg/msg_host.c
src/simdag/sd_workstation.c
src/simgrid/host.cpp

index 72d6d99..a005912 100644 (file)
@@ -8,6 +8,7 @@
 #define SIMGRID_HOST_H_
 
 #include <xbt/dict.h>
+#include <xbt/dynar.h>
 SG_BEGIN_DECL()
 
 typedef xbt_dictelm_t sg_host_t;
@@ -16,6 +17,7 @@ XBT_PUBLIC(sg_host_t) sg_host_by_name_or_create(const char *name);
 static XBT_INLINE char *sg_host_get_name(sg_host_t host){
        return host->key;
 }
+XBT_PUBLIC(xbt_dynar_t) sg_hosts_as_dynar(void);
 
 #ifdef __cplusplus
 #define DEFINE_EXTERNAL_CLASS(klass) class klass;
index ceaa015..27aa5e9 100644 (file)
@@ -206,18 +206,7 @@ msg_host_t *MSG_get_host_table(void)
  * \remark The host order in the returned array is generally different from the host creation/declaration order in the XML platform (we use a hash table internally)
  */
 xbt_dynar_t MSG_hosts_as_dynar(void) {
-  xbt_lib_cursor_t cursor;
-  char *key;
-  void **data;
-  xbt_dynar_t res = xbt_dynar_new(sizeof(msg_host_t),NULL);
-
-  xbt_lib_foreach(host_lib, cursor, key, data) {
-    if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) {
-      xbt_dictelm_t elm = xbt_dict_cursor_get_elm(cursor);
-      xbt_dynar_push(res, &elm);
-    }
-  }
-  return res;
+  return sg_hosts_as_dynar();
 }
 
 /** \ingroup m_host_management
index bfe57d9..697d5ee 100644 (file)
@@ -83,26 +83,12 @@ SD_workstation_t SD_workstation_get_by_name(const char *name)
  * \remark The workstation order in the returned array is generally different from the workstation creation/declaration order in the XML platform (we use a hash table internally).
  * \see SD_workstation_get_number()
  */
-const SD_workstation_t *SD_workstation_get_list(void)
-{
-
-  xbt_lib_cursor_t cursor;
-  char *key;
-  void **data;
-  int i;
-
+const SD_workstation_t *SD_workstation_get_list(void) {
   xbt_assert(SD_workstation_get_number() > 0, "There is no workstation!");
 
-  if (sd_global->workstation_list == NULL) {    /* this is the first time the function is called */
-    sd_global->workstation_list =
-      xbt_new(SD_workstation_t, xbt_lib_length(host_lib));
+  if (sd_global->workstation_list == NULL)     /* this is the first time the function is called */
+    sd_global->workstation_list = xbt_dynar_to_array(sg_hosts_as_dynar());
 
-    i = 0;
-    xbt_lib_foreach(host_lib, cursor, key, data) {
-      if(data[SD_HOST_LEVEL])
-        sd_global->workstation_list[i++] = xbt_dict_cursor_get_elm(cursor);
-    }
-  }
   return sd_global->workstation_list;
 }
 
index 61d2dac..7eb97bf 100644 (file)
@@ -7,6 +7,7 @@
 #include "xbt/dict.h"
 #include "simgrid/host.h"
 #include "surf/surf_routing.h" // SIMIX_HOST_LEVEL and friends FIXME: make private here
+#include "surf/surf.h" // routing_get_network_element_type FIXME:killme
 
 sg_host_t sg_host_by_name(const char *name){
   return xbt_lib_get_elm_or_null(host_lib, name);
@@ -20,6 +21,20 @@ sg_host_t sg_host_by_name_or_create(const char *name) {
        }
        return res;
 }
+xbt_dynar_t sg_hosts_as_dynar(void) {
+       xbt_lib_cursor_t cursor;
+       char *key;
+       void **data;
+       xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t),NULL);
+
+       xbt_lib_foreach(host_lib, cursor, key, data) {
+               if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) {
+                       xbt_dictelm_t elm = xbt_dict_cursor_get_elm(cursor);
+                       xbt_dynar_push(res, &elm);
+               }
+       }
+       return res;
+}
 
 // ========= Layering madness ==============