Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use a dict to store the smx_hosts since we lookup by name
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 18 Jun 2008 19:32:15 +0000 (19:32 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 18 Jun 2008 19:32:15 +0000 (19:32 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5758 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/include/simix/simix.h
src/simix/private.h
src/simix/smx_global.c
src/simix/smx_host.c

index 4bf6348..6f147c0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id$     */
+/*     $Id: simix.h 5610 2008-06-12 09:38:58Z alegrand $        */
 
 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
    All rights reserved.                                          */
@@ -69,7 +69,8 @@ XBT_PUBLIC(double) SIMIX_host_get_speed(smx_host_t host);
 XBT_PUBLIC(double) SIMIX_host_get_available_speed(smx_host_t host);
 
 XBT_PUBLIC(int) SIMIX_host_get_number(void);
-XBT_PUBLIC(smx_host_t *)SIMIX_host_get_table(void);
+XBT_PUBLIC(smx_host_t *) SIMIX_host_get_table(void);
+XBT_PUBLIC(xbt_dict_t) SIMIX_host_get_dict(void);
 
 XBT_PUBLIC(void) SIMIX_create_environment(const char *file);
 XBT_PUBLIC(smx_host_t) SIMIX_host_get_by_name(const char *name);
index 8a31f69..dd2c343 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id$     */
+/*     $Id: private.h 5071 2007-11-27 15:41:57Z mquinson $      */
 
 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
    All rights reserved.                                          */
@@ -32,7 +32,7 @@ typedef struct s_smx_simdata_host {
 /********************************* Simix Global ******************************/
 
 typedef struct SIMIX_Global {
-  xbt_fifo_t host;
+  xbt_dict_t host;
   xbt_swag_t process_to_run;
   xbt_swag_t process_list;
 
@@ -118,7 +118,7 @@ extern xbt_cfg_t _simix_cfg_set;
 
 smx_host_t __SIMIX_host_create(const char *name, void *workstation,
                               void *data);
-void __SIMIX_host_destroy(smx_host_t host);
+void __SIMIX_host_destroy(void* host);
 
 void __SIMIX_cond_wait(smx_cond_t cond);
 
index fc1135f..4c933f7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id$     */
+/*     $Id: smx_global.c 5483 2008-05-21 09:53:01Z alegrand $   */
 
 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donassolo.
    All rights reserved.                                          */
@@ -113,7 +113,7 @@ void SIMIX_global_init(int *argc, char **argv)
 
     simix_global = xbt_new0(s_SIMIX_Global_t, 1);
 
-    simix_global->host = xbt_fifo_new();
+    simix_global->host = xbt_dict_new();
     simix_global->process_to_run =
        xbt_swag_new(xbt_swag_offset(proc, synchro_hookup));
     simix_global->process_list =
@@ -278,18 +278,13 @@ void SIMIX_process_killall()
  */
 void SIMIX_clean(void)
 {
-  xbt_fifo_item_t i = NULL;
-  smx_host_t h = NULL;
   smx_process_t p = NULL;
 
   while ((p = xbt_swag_extract(simix_global->process_list))) {
     SIMIX_process_kill(p);
   }
 
-  xbt_fifo_foreach(simix_global->host, i, h, smx_host_t) {
-    __SIMIX_host_destroy(h);
-  }
-  xbt_fifo_free(simix_global->host);
+  xbt_dict_free(&(simix_global->host));
   xbt_swag_free(simix_global->process_to_run);
   xbt_swag_free(simix_global->process_list);
   xbt_dict_free(&(simix_global->registered_functions));
index e26ffb6..57ea0d6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id$     */
+/*     $Id: smx_host.c 4895 2007-10-27 07:34:39Z mquinson $     */
 
 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donassolo.
    All rights reserved.                                          */
@@ -9,6 +9,7 @@
 #include "private.h"
 #include "xbt/sysdep.h"
 #include "xbt/log.h"
+#include "xbt/dict.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix,
                                "Logging specific to SIMIX (hosts)");
@@ -32,7 +33,7 @@ smx_host_t __SIMIX_host_create(const char *name,
       xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
   /* Update global variables */
 
-  xbt_fifo_unshift(simix_global->host, host);
+  xbt_dict_set(simix_global->host,host->name, host,&__SIMIX_host_destroy);
 
   return host;
 }
@@ -102,8 +103,9 @@ smx_host_t SIMIX_host_self(void)
  * MSG_host_destroy is just  a front_end that also removes it from 
  * msg_global->host
  */
-void __SIMIX_host_destroy(smx_host_t host)
+void __SIMIX_host_destroy(void* h)
 {
+  smx_host_t host = (smx_host_t)h;
   smx_simdata_host_t simdata = NULL;
 
   xbt_assert0((host != NULL), "Invalid parameters");
@@ -144,19 +146,36 @@ void __SIMIX_host_destroy(smx_host_t host)
  */
 int SIMIX_host_get_number(void)
 {
-  return (xbt_fifo_size(simix_global->host));
+  return (xbt_dict_size(simix_global->host));
 }
 
+
 /**
- * \brief Return a array of all the #smx_host_t.
+ * \brief Return an array of all the #smx_host_t.
  *
- * \return List of all hosts
+ * \return List of all hosts (in a newly allocated table)
  */
-smx_host_t *SIMIX_host_get_table(void)
-{
-  return ((smx_host_t *) xbt_fifo_to_array(simix_global->host));
+smx_host_t* SIMIX_host_get_table(void) {
+   smx_host_t *res = xbt_new(smx_host_t,xbt_dict_size(simix_global->host));
+   smx_host_t h;
+   xbt_dict_cursor_t c;
+   char *name;
+   int i=0;
+   
+   xbt_dict_foreach(simix_global->host,c,name,h)
+     res[i++] = h;
+   
+   return res;
 }
 
+/**
+ * \brief Return a dict of all the #smx_host_t.
+ *
+ * \return List of all hosts (as a #xbt_dict_t)
+ */
+xbt_dict_t SIMIX_host_get_dict(void) {
+   return simix_global->host;
+}
 
 /**
  * \brief Return the speed of the processor.
@@ -196,18 +215,11 @@ double SIMIX_host_get_available_speed(smx_host_t host)
  */
 smx_host_t SIMIX_host_get_by_name(const char *name)
 {
-  xbt_fifo_item_t i = NULL;
-  smx_host_t host = NULL;
-
   xbt_assert0(((simix_global != NULL)
               && (simix_global->host != NULL)),
              "Environment not set yet");
 
-  xbt_fifo_foreach(simix_global->host, i, host, smx_host_t) {
-    if (strcmp(host->name, name) == 0)
-      return host;
-  }
-  return NULL;
+  return xbt_dict_get_or_null(simix_global->host, name);
 }
 
 /**