Index: sources/src/gen_code.cc
===================================================================
--- sources/src/gen_code.cc	(revision 63)
+++ sources/src/gen_code.cc	(revision 65)
@@ -50,6 +50,8 @@
 #include <fstream>
 #ifdef _OPENMP
-    #include <omp.h>
-#endif
+#include <omp.h>
+#endif
+#include <sys/types.h>
+#include <unistd.h>
 
 #include "internal.h"
@@ -240,11 +242,12 @@
 }
 
-
-char * gen_scheduling_code_for_dynamic_link(method_process_list_t & transition_func_list,
-        method_process_list_t & moore_func_list,
-        strong_component_list_t * strongcomponents) {
-    if (dump_stage) {
-        cerr << "Generating C code for scheduling...\n";
-    }
+char *
+gen_scheduling_code_for_dynamic_link (
+               method_process_list_t           &transition_func_list,
+               method_process_list_t           &moore_func_list,
+               strong_component_list_t         *strongcomponents)
+{
+  if (dump_stage)
+    cerr << "Generating C code for scheduling...\n";
 
     // open temporary file
@@ -258,10 +261,11 @@
     }
 
-    o << "// generated by " << sc_version() << endl
-        << "#include <casc.h>\n\n" << "#include <cstdio>\n\n"
-        //  << "#include <iostream>\n\n"
-        << "namespace sc_core {\n"
-        << " typedef void (sc_module::*SC_ENTRY_FUNC)();\n"
-        << " typedef void (*CASC_ENTRY_FUNC)(void *);\n";
+  o << "// generated by " << sc_version () << endl
+    << "#include <casc.h>\n\n"
+    << "#include <cstdio>\n\n"
+//  << "#include <iostream>\n\n"
+    << "namespace sc_core {\n"
+    << " typedef void (sc_module::*SC_ENTRY_FUNC)();\n"
+    << " typedef void (*CASC_ENTRY_FUNC)(void *);\n";
 
     const char * pmf_type = get_pmf_type();
@@ -533,14 +537,15 @@
 }
 
-
-void call_functions_in_parallel(function_call & fc) {
-    int n = fc.func_number;
-    int i;
-    for (i = 0; i < n; ++i) {
-#if 0
-        //defined(CONFIG_DEBUG)
-        sc_module *m = (sc_module *) (fc.instance[i]);
-        cerr << m->name() << endl;
-        cerr << "thread #" << omp_get_thread_num() << endl;
+void
+call_functions_in_parallel (function_call &fc)
+{
+  int n = fc.func_number;
+  int i;
+  for (i = 0; i < n; ++i)
+  {
+#if 0 //defined(CONFIG_DEBUG)
+    sc_module *m = (sc_module*)(fc.instance[i]);
+    cerr << m->name () << endl;
+    cerr << "thread #" << omp_get_thread_num () << endl;
 #endif
         fc.function[i].pf(fc.instance[i]);
@@ -566,6 +571,6 @@
  */
 
-unsigned int nb_func[2];
-static method_process_t **func_list[2];
+unsigned int              nb_func[2];
+static method_process_t        **func_list[2];
 static strong_component_list_t quasistatic_list;
 
@@ -578,11 +583,12 @@
 #endif
 
-static void Call(const method_process_t & m) {
-    sc_module * mod = m.module;
-    SC_ENTRY_FUNC func = m.func;
-    //  CASC_ENTRY_FUNC   func = reinterpret_cast<CASC_ENTRY_FUNC> (m.func);
-    // QM
-    //cerr << "Exec " << mod->name() << "->" << m.name << endl;
-    (mod->*func) ();
+static 
+void
+Call         (const method_process_t &m)
+{
+  sc_module        *mod  = m.module;
+  SC_ENTRY_FUNC     func = m.func;
+//  CASC_ENTRY_FUNC   func = reinterpret_cast<CASC_ENTRY_FUNC> (m.func);
+  (mod->*func) ();
 }
 
@@ -620,22 +626,22 @@
 unsigned int num_omp_threads;
 
-void quasistatic_simulate_1_cycle(void) {
-    int i;
-
-    for (i = 0; i < nb_func[0]; ++i) {
-        Call(*(func_list[0][i]));
-    }
+void quasistatic_simulate_1_cycle (void) 
+{
+	int i;
+
+	for (i = 0; i < nb_func[0]; ++i)
+		Call (*(func_list[0][i]));
+#ifdef _OPENMP
 #define USE_BUSY_WAIT 1
-    update();
+#if 0
 #if USE_BUSY_WAIT
-    expected_globaltime += num_omp_threads;
-    if (__sync_add_and_fetch(&globaltime, 1) == expected_globaltime) {
-        last_wait_up++;
-    }
-    __asm volatile("mfence");
-    while (globaltime < expected_globaltime) {
-        busy_wait_up++;
-        __asm volatile("lfence");
-    }
+	expected_globaltime += num_omp_threads;
+	if (__sync_add_and_fetch(&globaltime, 1) == expected_globaltime)
+		last_wait_f0++;
+	__asm volatile("mfence");
+	while (globaltime < expected_globaltime) {
+		busy_wait_f0++;
+		__asm volatile("lfence");
+	}
 #else
     #ifdef _OPENMP
@@ -643,19 +649,20 @@
     #endif
 #endif
-
-    for (i = 0; i < nb_func[1]; ++i) {
-        Call(*(func_list[1][i]));
-    }
-
+#endif
+#endif // _OPENMP
+
+	update();
+
+#ifdef _OPENMP
 #if USE_BUSY_WAIT
-    expected_globaltime += num_omp_threads;
-    if (__sync_add_and_fetch(&globaltime, 1) == expected_globaltime) {
-        last_wait_f1++;
-    }
-    __asm volatile("mfence");
-    while (globaltime < expected_globaltime) {
-        busy_wait_f1++;
-        __asm volatile("lfence");
-    }
+	expected_globaltime += num_omp_threads;
+	if (__sync_add_and_fetch(&globaltime, 1) == expected_globaltime)
+		last_wait_up++;
+	__asm volatile("mfence");
+	while (globaltime < expected_globaltime) {
+		busy_wait_up++;
+		__asm volatile("lfence");
+	}
+
 #else
     #ifdef _OPENMP
@@ -663,21 +670,39 @@
     #endif
 #endif
-    if (!quasistatic_list.empty()) {
+#endif // _OPENMP
+
+	for (i = 0; i < nb_func[1]; ++i)
+		Call (*(func_list[1][i]));
+
 #ifdef _OPENMP
+#if USE_BUSY_WAIT
+	expected_globaltime += num_omp_threads;
+	if (__sync_add_and_fetch(&globaltime, 1) == expected_globaltime)
+		last_wait_f1++;
+	__asm volatile("mfence");
+	while (globaltime < expected_globaltime) {
+		busy_wait_f1++;
+		__asm volatile("lfence");
+	}
+#else
+#pragma omp barrier
+#endif
+#endif // _OPENMP
+
+	if (!quasistatic_list.empty()) {
 #pragma omp master
-#endif
-        {
-            quasistatic_mealy_generation();
-        }
+		{
+		quasistatic_mealy_generation ();
+		}
+#ifdef _OPENMP
 #if USE_BUSY_WAIT
-        expected_globaltime += num_omp_threads;
-        if (__sync_add_and_fetch(&globaltime, 1) == expected_globaltime) {
-            last_wait_ml++;
-        }
-        __asm volatile("mfence");
-        while (globaltime < expected_globaltime) {
-            busy_wait_ml++;
-            __asm volatile("lfence");
-        }
+		expected_globaltime += num_omp_threads;
+		if (__sync_add_and_fetch(&globaltime, 1) == expected_globaltime)
+			last_wait_ml++;
+		__asm volatile("mfence");
+		while (globaltime < expected_globaltime) {
+			busy_wait_ml++;
+			__asm volatile("lfence");
+		}
 #else
     #ifdef _OPENMP
@@ -685,37 +710,36 @@
     #endif
 #endif
-    }
-}
-
-
-void gen_scheduling_code_for_quasistatic_func(method_process_list_t & transition_func_list,
-        method_process_list_t & moore_func_list,
-        strong_component_list_t * mealy_func_list) {
-    if (dump_stage) {
-        cerr << "Generating quasi static scheduling...\n";
-    }
-
-    nb_func[0] = transition_func_list.size();
-    nb_func[1] = moore_func_list.size();
-
-    func_list[0] = (method_process_t**) malloc(sizeof (method_process_t*) * nb_func[0]);
-    func_list[1] = (method_process_t**) malloc(sizeof (method_process_t*) * nb_func[1]);
-
-    unsigned int i;
-    for (i = 0; i < nb_func[0]; ++i) {
-        func_list[0][i] = (transition_func_list[i]);
-    }
-
-    for (i = 0; i < nb_func[1]; ++i) {
-        func_list[1][i] = (moore_func_list[i]);
-    }
-
-    if (mealy_func_list != NULL) {
-        quasistatic_list = *mealy_func_list;
-    }
-
-    if (dump_stage) {
-        cerr << "Generating quasi static scheduling done.\n";
-    }
+#endif // _OPENMP
+	}
+
+}
+
+void
+gen_scheduling_code_for_quasistatic_func (
+            method_process_list_t   &transition_func_list,
+            method_process_list_t   &moore_func_list,
+            strong_component_list_t *mealy_func_list)
+{
+  if (dump_stage)
+    cerr << "Generating quasi static scheduling...\n";
+
+  nb_func[0] = transition_func_list.size();
+  nb_func[1] = moore_func_list     .size();
+
+  func_list[0] = (method_process_t**) malloc (sizeof (method_process_t*) * nb_func[0]);
+  func_list[1] = (method_process_t**) malloc (sizeof (method_process_t*) * nb_func[1]);
+
+  unsigned int i;
+  for (i = 0; i < nb_func[0]; ++i)
+    func_list[0][i] = (transition_func_list[i]);
+
+  for (i = 0; i < nb_func[1]; ++i)
+    func_list[1][i] = (moore_func_list[i]);
+
+  if (mealy_func_list != NULL)
+    quasistatic_list = *mealy_func_list;
+
+  if (dump_stage)
+    cerr << "Generating quasi static scheduling done.\n";
 }
 } // end of sc_core namespace
