Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/12615

Change subject: systemc: Implement SC_FORK, SC_JOIN, and SC_CJOIN.
......................................................................

systemc: Implement SC_FORK, SC_JOIN, and SC_CJOIN.

SC_CJOIN is non-standard, but relied on by the Accellera tests.

Change-Id: Ia4ddcb1749a07891157a58398137e94fcaa8e815
---
M src/systemc/core/process.cc
M src/systemc/core/process.hh
M src/systemc/core/sc_join.cc
M src/systemc/ext/core/sc_join.hh
M src/systemc/ext/core/sc_spawn.hh
5 files changed, 51 insertions(+), 33 deletions(-)



diff --git a/src/systemc/core/process.cc b/src/systemc/core/process.cc
index 553f332..1c7a9d7 100644
--- a/src/systemc/core/process.cc
+++ b/src/systemc/core/process.cc
@@ -32,6 +32,7 @@
 #include "base/logging.hh"
 #include "systemc/core/event.hh"
 #include "systemc/core/scheduler.hh"
+#include "systemc/ext/core/sc_join.hh"
 #include "systemc/ext/core/sc_main.hh"
 #include "systemc/ext/core/sc_process_handle.hh"
 #include "systemc/ext/utils/sc_report_handler.hh"
@@ -419,6 +420,10 @@
     staticSensitivities.clear();

     _terminatedEvent.notify();
+
+    for (auto jw: joinWaiters)
+        jw->signal();
+    joinWaiters.clear();
 }

 Process *Process::_newest;
diff --git a/src/systemc/core/process.hh b/src/systemc/core/process.hh
index 4d88e27..d399d7a 100644
--- a/src/systemc/core/process.hh
+++ b/src/systemc/core/process.hh
@@ -49,6 +49,13 @@
 #include "systemc/ext/core/sc_process_handle.hh"
 #include "systemc/ext/utils/sc_report.hh"

+namespace sc_core
+{
+
+class sc_join;
+
+} // namespace sc_core
+
 namespace sc_gem5
 {

@@ -347,6 +354,8 @@
     bool dontInitialize() { return _dontInitialize; }
     void dontInitialize(bool di) { _dontInitialize = di; }

+ void joinWait(::sc_core::sc_join *join) { joinWaiters.push_back(join); }
+
   protected:
Process(const char *name, ProcessFuncWrapper *func, bool internal=false);

@@ -396,6 +405,8 @@
     Sensitivity *dynamicSensitivity;

     std::unique_ptr<::sc_core::sc_report> _lastReport;
+
+    std::vector<::sc_core::sc_join *> joinWaiters;
 };

 inline void
diff --git a/src/systemc/core/sc_join.cc b/src/systemc/core/sc_join.cc
index 4d53143..3e4c6ee 100644
--- a/src/systemc/core/sc_join.cc
+++ b/src/systemc/core/sc_join.cc
@@ -28,45 +28,29 @@
  */

 #include "base/logging.hh"
+#include "systemc/core/process.hh"
+#include "systemc/ext/core/sc_event.hh"
 #include "systemc/ext/core/sc_join.hh"
+#include "systemc/ext/core/sc_module.hh"

 namespace sc_core
 {

-sc_join::sc_join()
-{
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
+sc_join::sc_join() : remaining(0) {}

 void
-sc_join::add_process(sc_process_handle)
+sc_join::add_process(sc_process_handle h)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    auto p = (::sc_gem5::Process *)h;
+    assert(p);
+
+    remaining++;
+    p->joinWait(this);
 }

-int
-sc_join::process_count()
-{
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-    return 0;
-}
-
-void
-sc_join::signal(sc_thread_handle thread_p, int type)
-{
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
-
-void
-sc_join::wait()
-{
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
-
-void
-sc_join::wait_clocked()
-{
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
+int sc_join::process_count() { return remaining; }
+void sc_join::signal() { if (!--remaining) joinEvent.notify(); }
+void sc_join::wait() { ::sc_core::wait(joinEvent); }
+void sc_join::wait_clocked() { do { ::sc_core::wait(); } while (remaining); }

 } // namespace sc_core
diff --git a/src/systemc/ext/core/sc_join.hh b/src/systemc/ext/core/sc_join.hh
index 18119ae..49e54ce 100644
--- a/src/systemc/ext/core/sc_join.hh
+++ b/src/systemc/ext/core/sc_join.hh
@@ -30,6 +30,7 @@
 #ifndef __SYSTEMC_EXT_CORE_SC_JOIN_HH__
 #define __SYSTEMC_EXT_CORE_SC_JOIN_HH__

+#include "sc_event.hh"
 #include "sc_process_handle.hh"

 namespace sc_core
@@ -43,11 +44,16 @@
 {
   public:
     sc_join();
+
     void add_process(sc_process_handle);
     int process_count();
-    virtual void signal(sc_thread_handle thread_p, int type);
+    void signal();
     void wait();
     void wait_clocked();
+
+  private:
+    sc_event joinEvent;
+    int remaining;
 };

 } // namespace sc_core
diff --git a/src/systemc/ext/core/sc_spawn.hh b/src/systemc/ext/core/sc_spawn.hh
index 8285154..d978830 100644
--- a/src/systemc/ext/core/sc_spawn.hh
+++ b/src/systemc/ext/core/sc_spawn.hh
@@ -32,6 +32,7 @@

 #include <vector>

+#include "sc_join.hh"
 #include "sc_process_handle.hh"

 namespace sc_core
@@ -166,11 +167,22 @@
     ::sc_core::sc_process_handle forkees[] = {

 #define SC_JOIN \
-    }; /* TODO wait for the forkees. */ \
+    }; \
+    ::sc_core::sc_join join; \
+    for (int i = 0; i < sizeof(forkees) / sizeof(forkees[0]); i++) \
+        join.add_process(forkees[i]); \
+    join.wait(); \
 }

 // Non-standard
-#define SC_CJOIN SC_JOIN
+#define SC_CJOIN \
+    }; \
+    ::sc_core::sc_join join; \
+    for (int i = 0; i < sizeof(forkees) / sizeof(forkees[0]); i++) \
+        join.add_process(forkees[i]); \
+    join.wait_clocked(); \
+}
+

 } // namespace sc_core


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12615
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ia4ddcb1749a07891157a58398137e94fcaa8e815
Gerrit-Change-Number: 12615
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to