dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / fsm / scd_stm_idle.cpp
diff --git a/dol/src/dol/visitor/hdsd/scd/fsm/scd_stm_idle.cpp b/dol/src/dol/visitor/hdsd/scd/fsm/scd_stm_idle.cpp
new file mode 100644 (file)
index 0000000..1138ab7
--- /dev/null
@@ -0,0 +1,50 @@
+#include "fsm/scd_stm_idle.h"
+
+#include "scd_logging.h"
+#include "scd_exception.h"
+#include "scd_cont_man_master.h"
+
+
+void scd_stm_idle::set_busy()
+{
+    _fsm.set_state(_st_busy);
+}
+
+
+void scd_stm_idle::set_done()
+{
+    _time_step = sc_core::SC_ZERO_TIME;
+    _fsm.set_state(_st_done);
+}
+
+
+void scd_stm_idle::process()
+{
+    if (!_check_slaves())
+        return;
+    
+    std::list<scd_cont_slave_wrapper*>::iterator iter;
+
+    for (iter = _slaves.begin(); iter != _slaves.end(); iter++)
+    {
+        if (!(*iter)->idle() && !(*iter)->done())
+        {
+            // this slave is not ready yet
+            return;
+        }
+    }
+
+    /* all slaves seem idle or done. wait a short moment, to prevent
+     * race conditions (channel data in transit but both endpoints done).
+     * if no socket activity occured we can move on, else we cancel.
+     */
+    if (_sim.get_poller().wait(SCD_CONT_DELAY))
+        return;
+
+    // all slaves seem to be ready to advance time
+    for (iter = _slaves.begin(); iter != _slaves.end(); iter++)
+        (*iter)->send_time_req();
+
+    _fsm.save_state();
+    _fsm.set_state(_st_time_req);
+}