Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ensure that the create_resource functions do call strdup by themselves
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 4 Nov 2011 09:41:34 +0000 (10:41 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 4 Nov 2011 10:18:18 +0000 (11:18 +0100)
Also, ensure that the CPU models use surf_resource_new() instead of
dupplicating its code

src/include/surf/surf.h
src/include/surf/surf_resource.h
src/include/surf/surf_resource_lmm.h
src/surf/cpu.c
src/surf/cpu_im.c
src/surf/cpu_ti.c
src/surf/network.c
src/surf/network_im.c
src/surf/workstation_ptask_L07.c

index 52d11f3..062d9ea 100644 (file)
@@ -169,7 +169,7 @@ typedef struct surf_cpu_model_extension_public {
   e_surf_resource_state_t(*get_state) (void *cpu);
   double (*get_speed) (void *cpu, double load);
   double (*get_available_speed) (void *cpu);
-  void* (*create_resource) (char *name, double power_peak,
+  void* (*create_resource) (const char *name, double power_peak,
                            double power_scale,
                            tmgr_trace_t power_trace,
                            int core,
@@ -195,7 +195,7 @@ typedef struct surf_network_model_extension_public {
   double (*get_link_latency) (const void *link);
   int (*link_shared) (const void *link);
   void (*add_traces) (void);
-  void* (*create_resource) (char *name,
+  void* (*create_resource) (const char *name,
                            double bw_initial,
                            tmgr_trace_t bw_trace,
                            double lat_initial,
@@ -233,7 +233,7 @@ typedef struct surf_workstation_model_extension_public {
   double (*get_link_latency) (const void *link);                                           /**< Return the current latency of a network link */
   int (*link_shared) (const void *link);
    xbt_dict_t(*get_properties) (const void *resource);
-  void* (*link_create_resource) (char *name,
+  void* (*link_create_resource) (const char *name,
                                 double bw_initial,
                                 tmgr_trace_t bw_trace,
                                 double lat_initial,
@@ -243,7 +243,7 @@ typedef struct surf_workstation_model_extension_public {
                                 tmgr_trace_t state_trace,
                                 e_surf_link_sharing_policy_t
                                 policy, xbt_dict_t properties);
-  void* (*cpu_create_resource) (char *name, double power_peak,
+  void* (*cpu_create_resource) (const char *name, double power_peak,
                                double power_scale,
                                tmgr_trace_t power_trace,
                                e_surf_resource_state_t state_initial,
index 625fd9f..d0a14d5 100644 (file)
 
 static XBT_INLINE
     surf_resource_t surf_resource_new(size_t childsize,
-                                      surf_model_t model, char *name,
+                                      surf_model_t model, const char *name,
                                       xbt_dict_t props)
 {
   surf_resource_t res = xbt_malloc0(childsize);
   res->model = model;
-  res->name = name;
+  res->name = xbt_strdup(name);
   res->properties = props;
   return res;
 }
index 237c7b1..e1c3a0b 100644 (file)
@@ -14,7 +14,7 @@ static XBT_INLINE
     surf_resource_lmm_t surf_resource_lmm_new(size_t childsize,
                                               /* for superclass */
                                               surf_model_t model,
-                                              char *name, xbt_dict_t props,
+                                              const char *name, xbt_dict_t props,
                                               lmm_system_t system,
                                               double constraint_value,
                                               tmgr_history_t history,
index 3be6a3f..2124426 100644 (file)
@@ -32,7 +32,7 @@ lmm_system_t cpu_maxmin_system = NULL;
 static xbt_swag_t cpu_running_action_set_that_does_not_need_being_checked =
     NULL;
 
-static void* cpu_create_resource(char *name, double power_peak,
+static void* cpu_create_resource(const char *name, double power_peak,
                            double power_scale,
                            tmgr_trace_t power_trace,
                            int core,
@@ -41,13 +41,12 @@ static void* cpu_create_resource(char *name, double power_peak,
                            xbt_dict_t cpu_properties)
 {
 
-  cpu_Cas01_t cpu = xbt_new0(s_cpu_Cas01_t, 1);
+  cpu_Cas01_t cpu = NULL;
   xbt_assert(!surf_cpu_resource_by_name(name),
               "Host '%s' declared several times in the platform file",
               name);
-  cpu->generic_resource.model = surf_cpu_model;
-  cpu->generic_resource.name = name;
-  cpu->generic_resource.properties = cpu_properties;
+  cpu = (cpu_Cas01_t) surf_resource_new(sizeof(s_cpu_Cas01_t),
+          surf_cpu_model, name,cpu_properties);
   cpu->power_peak = power_peak;
   xbt_assert(cpu->power_peak > 0, "Power has to be >0");
   cpu->power_scale = power_scale;
index ccf3e56..caa3a9d 100644 (file)
@@ -47,7 +47,7 @@ extern int sg_maxmin_selective_update;
 static xbt_swag_t
     cpu_im_running_action_set_that_does_not_need_being_checked = NULL;
 
-static void* cpu_im_create_resource(char *name, double power_peak,
+static void* cpu_im_create_resource(const char *name, double power_peak,
                                  double power_scale,
                                  tmgr_trace_t power_trace,
                                  int core,
@@ -57,14 +57,12 @@ static void* cpu_im_create_resource(char *name, double power_peak,
 {
   cpu_Cas01_im_t cpu = NULL;
   s_surf_action_cpu_Cas01_im_t action;
-  cpu = xbt_new0(s_cpu_Cas01_im_t, 1);
 
   xbt_assert(!surf_cpu_resource_by_name(name),
               "Host '%s' declared several times in the platform file",
               name);
-  cpu->generic_resource.model = surf_cpu_model;
-  cpu->generic_resource.name = name;
-  cpu->generic_resource.properties = cpu_properties;
+  cpu = (cpu_Cas01_im_t) surf_resource_new(sizeof(s_cpu_Cas01_im_t),
+          surf_cpu_model, name,cpu_properties);
   cpu->power_peak = power_peak;
   xbt_assert(cpu->power_peak > 0, "Power has to be >0");
   cpu->power_scale = power_scale;
@@ -143,10 +141,10 @@ static void cpu_im_define_callbacks()
                        &cpu_im_add_traces_cpu);
 }
 
-static int cpu_im_resource_used(void *resource_id)
+static int cpu_im_resource_used(void *resource)
 {
   return lmm_constraint_used(cpu_im_maxmin_system,
-                             ((cpu_Cas01_im_t) resource_id)->constraint);
+                             ((cpu_Cas01_im_t) resource)->constraint);
 }
 
 static int cpu_im_action_unref(surf_action_t action)
index 41e3bc1..b18b735 100644 (file)
@@ -143,7 +143,7 @@ static surf_cpu_ti_tgmr_t cpu_ti_parse_trace(tmgr_trace_t power_trace,
 }
 
 
-static void* cpu_ti_create_resource(char *name, double power_peak,
+static void* cpu_ti_create_resource(const char *name, double power_peak,
                            double power_scale,
                            tmgr_trace_t power_trace,
                            int core,
@@ -153,18 +153,17 @@ static void* cpu_ti_create_resource(char *name, double power_peak,
 {
   tmgr_trace_t empty_trace;
   s_tmgr_event_t val;
-  cpu_ti_t cpu = xbt_new0(s_cpu_ti_t, 1);
+  cpu_ti_t cpu = NULL;
   s_surf_action_cpu_ti_t ti_action;
   xbt_assert(core==1,"Multi-core not handled with this model yet");
   xbt_assert(!surf_cpu_resource_by_name(name),
               "Host '%s' declared several times in the platform file",
               name);
   xbt_assert(core==1,"Multi-core not handled with this model yet");
+  cpu = (cpu_ti_t) surf_resource_new(sizeof(s_cpu_ti_t),
+          surf_cpu_model, name,cpu_properties);
   cpu->action_set =
       xbt_swag_new(xbt_swag_offset(ti_action, cpu_list_hookup));
-  cpu->generic_resource.model = surf_cpu_model;
-  cpu->generic_resource.name = name;
-  cpu->generic_resource.properties = cpu_properties;
   cpu->power_peak = power_peak;
   xbt_assert(cpu->power_peak > 0, "Power has to be >0");
   XBT_DEBUG("power scale %lf", power_scale);
index 8984b41..2d4158c 100644 (file)
@@ -155,7 +155,7 @@ static double (*bandwidth_constraint_callback) (double, double, double) =
     &constant_bandwidth_constraint;
 
 
-static void* net_create_resource(char *name,
+static void* net_create_resource(const char *name,
                                 double bw_initial,
                                 tmgr_trace_t bw_trace,
                                 double lat_initial,
index 668c2f2..7a4887c 100644 (file)
@@ -150,7 +150,7 @@ static double (*im_bandwidth_constraint_callback) (double, double, double) =
     &im_constant_bandwidth_constraint;
 
 
-static void* im_net_create_resource(char *name,
+static void* im_net_create_resource(const char *name,
                                 double bw_initial,
                                 tmgr_trace_t bw_trace,
                                 double lat_initial,
index 709e1a9..1878ea4 100644 (file)
@@ -614,22 +614,22 @@ static int ptask_link_shared(const void *link)
 /*** Resource Creation & Destruction **/
 /**************************************/
 
-static void* ptask_cpu_create_resource(char *name, double power_scale,
+static void* ptask_cpu_create_resource(const char *name, double power_scale,
                                double power_initial,
                                tmgr_trace_t power_trace,
                                e_surf_resource_state_t state_initial,
                                tmgr_trace_t state_trace,
                                xbt_dict_t cpu_properties)
 {
-  cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
+  cpu_L07_t cpu = NULL;
   xbt_assert(!surf_workstation_resource_by_name(name),
               "Host '%s' declared several times in the platform file.",
               name);
 
-  cpu->generic_resource.model = surf_workstation_model;
+  cpu = (cpu_L07_t) surf_resource_new(sizeof(s_cpu_L07_t),
+          surf_workstation_model, name,cpu_properties);
+
   cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
-  cpu->generic_resource.name = xbt_strdup(name);
-  cpu->generic_resource.properties = cpu_properties;
   cpu->id = ptask_host_count++;
 
   cpu->power_scale = power_scale;
@@ -667,7 +667,7 @@ static void ptask_parse_cpu_init(void)
   current_property_set=NULL;
 }
 
-static void* ptask_link_create_resource(char *name,
+static void* ptask_link_create_resource(const char *name,
                                  double bw_initial,
                                  tmgr_trace_t bw_trace,
                                  double lat_initial,
@@ -685,7 +685,7 @@ static void* ptask_link_create_resource(char *name,
 
   nw_link->generic_resource.model = surf_workstation_model;
   nw_link->generic_resource.properties = properties;
-  nw_link->generic_resource.name = name;
+  nw_link->generic_resource.name = xbt_strdup(name);
   nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
   nw_link->bw_current = bw_initial;
   if (bw_trace)