Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
It worries me however, to realize how tough an ass-hole I have had to be, in
[simgrid.git] / src / surf / workstation.c
index f201e08..26d4602 100644 (file)
@@ -15,7 +15,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(workstation, surf,
 
 surf_workstation_resource_t surf_workstation_resource = NULL;
 
-static xbt_dict_t workstation_set = NULL;
+xbt_dict_t workstation_set = NULL;
 
 static workstation_t workstation_new(const char *name,
                                     void *cpu, void *card)
@@ -30,6 +30,12 @@ static workstation_t workstation_new(const char *name,
   return workstation;
 }
 
+static void workstation_free(void *workstation)
+{
+  xbt_free(((workstation_t)workstation)->name);
+  xbt_free(workstation);
+}
+
 static void create_workstations(void)
 {
   xbt_dict_cursor_t cursor = NULL;
@@ -42,7 +48,7 @@ static void create_workstations(void)
     xbt_dict_get(network_card_set, name, (void *) &nw_card);
     xbt_assert0(nw_card, "No corresponding card found");
     xbt_dict_set(workstation_set, name,
-                workstation_new(name, cpu, nw_card), NULL);
+                workstation_new(name, cpu, nw_card), workstation_free);
   }
 }
 
@@ -137,10 +143,11 @@ static void action_resume(surf_action_t action)
 
 static int action_is_suspended(surf_action_t action)
 {
-  xbt_assert0(action->resource_type ==
-             ((surf_resource_t) surf_cpu_resource),
-             "Resource type mismatch");
-  return surf_cpu_resource->extension_public->is_suspended(action);
+  if(action->resource_type==(surf_resource_t)surf_network_resource) 
+    return 0;
+  if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
+    return surf_cpu_resource->extension_public->is_suspended(action);
+  DIE_IMPOSSIBLE;
 }
 
 static surf_action_t communicate(void *workstation_src,
@@ -159,6 +166,20 @@ static e_surf_cpu_state_t get_state(void *workstation)
 
 static void finalize(void)
 {
+  xbt_dict_free(&workstation_set);
+  xbt_swag_free(surf_workstation_resource->common_public->states.ready_action_set);
+  xbt_swag_free(surf_workstation_resource->common_public->states.
+               running_action_set);
+  xbt_swag_free(surf_workstation_resource->common_public->states.
+               failed_action_set);
+  xbt_swag_free(surf_workstation_resource->common_public->states.done_action_set);
+
+  xbt_free(surf_workstation_resource->common_public);
+  xbt_free(surf_workstation_resource->common_private);
+  xbt_free(surf_workstation_resource->extension_public);
+
+  xbt_free(surf_workstation_resource);
+  surf_workstation_resource = NULL;
 }
 
 static void surf_workstation_resource_init_internal(void)
@@ -195,6 +216,7 @@ static void surf_workstation_resource_init_internal(void)
       action_recycle;
   surf_workstation_resource->common_public->action_change_state =
       action_change_state;
+  surf_workstation_resource->common_public->action_set_data = surf_action_set_data;
   surf_workstation_resource->common_public->name = "Workstation";
 
   surf_workstation_resource->common_private->resource_used = resource_used;
@@ -219,14 +241,25 @@ static void surf_workstation_resource_init_internal(void)
   xbt_assert0(maxmin_system, "surf_init has to be called first!");
 }
 
-void surf_workstation_resource_init(const char *filename)
+/********************************************************************/
+/* The model used in MSG and presented at CCGrid03                  */
+/********************************************************************/
+/* @InProceedings{Casanova.CLM_03, */
+/*   author = {Henri Casanova and Arnaud Legrand and Loris Marchal}, */
+/*   title = {Scheduling Distributed Applications: the SimGrid Simulation Framework}, */
+/*   booktitle = {Proceedings of the third IEEE International Symposium on Cluster Computing and the Grid (CCGrid'03)}, */
+/*   publisher = {"IEEE Computer Society Press"}, */
+/*   month = {may}, */
+/*   year = {2003} */
+/* } */
+void surf_workstation_resource_init_CLM03(const char *filename)
 {
 /*   int i ; */
 /*   surf_resource_t resource =  NULL; */
 
   surf_workstation_resource_init_internal();
-  surf_cpu_resource_init(filename);
-  surf_network_resource_init(filename);
+  surf_cpu_resource_init_Cas01(filename);
+  surf_network_resource_init_CM02(filename);
   create_workstations();
   xbt_dynar_push(resource_list, &surf_workstation_resource);
 /*   xbt_dynar_foreach(resource_list, i, resource) { */