Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Make 'colors' variable static
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 15 Mar 2016 13:42:04 +0000 (14:42 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 15 Mar 2016 14:09:57 +0000 (15:09 +0100)
src/mc/mc_global.cpp
src/mc/mc_private.h
src/mc/mc_request.cpp

index 6f985f1..f3d14ae 100644 (file)
@@ -77,29 +77,13 @@ xbt_automaton_t property_automaton = nullptr;
 
 /* Dot output */
 FILE *dot_output = nullptr;
-const char *colors[13];
 
 
 /*******************************  Initialisation of MC *******************************/
 /*********************************************************************************/
 
 void MC_init_dot_output()
-{                               /* FIXME : more colors */
-
-  colors[0] = "blue";
-  colors[1] = "red";
-  colors[2] = "green3";
-  colors[3] = "goldenrod";
-  colors[4] = "brown";
-  colors[5] = "purple";
-  colors[6] = "magenta";
-  colors[7] = "turquoise4";
-  colors[8] = "gray25";
-  colors[9] = "forestgreen";
-  colors[10] = "hotpink";
-  colors[11] = "lightblue";
-  colors[12] = "tan";
-
+{
   dot_output = fopen(_sg_mc_dot_output_file, "w");
 
   if (dot_output == nullptr) {
index 189e52f..5045c9f 100644 (file)
@@ -44,7 +44,6 @@ SG_BEGIN_DECL()
 XBT_PRIVATE void MC_init_dot_output();
 
 XBT_PRIVATE extern FILE *dot_output;
-XBT_PRIVATE extern const char* colors[13];
 
 XBT_PRIVATE extern int user_max_depth_reached;
 
index 9500f33..91f02cc 100644 (file)
@@ -465,6 +465,27 @@ bool process_is_enabled(smx_process_t process)
   return simgrid::mc::request_is_enabled(&process->simcall);
 }
 
+static const char* colors[] = {
+  "blue",
+  "red",
+  "green3",
+  "goldenrod",
+  "brown",
+  "purple",
+  "magenta",
+  "turquoise4",
+  "gray25",
+  "forestgreen",
+  "hotpink",
+  "lightblue",
+  "tan",
+};
+
+static inline const char* get_color(int id)
+{
+  return colors[id % (sizeof(colors) / sizeof(colors[0])) ];
+}
+
 char *request_get_dot_output(smx_simcall_t req, int value)
 {
   char *label = nullptr;
@@ -602,9 +623,10 @@ char *request_get_dot_output(smx_simcall_t req, int value)
     THROW_UNIMPLEMENTED;
   }
 
+  const char* color = get_color(issuer->pid - 1);
   char* str =
       bprintf("label = \"%s\", color = %s, fontcolor = %s", label,
-              colors[issuer->pid - 1], colors[issuer->pid - 1]);
+              color, color);
   xbt_free(label);
   return str;