Gabe Black has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/12618 )

Change subject: systemc: Implement sc_mutex.
......................................................................

systemc: Implement sc_mutex.

Change-Id: I8a5bd03b46d44aeca3bba15a01a5f2180b4ed5c7
Reviewed-on: https://gem5-review.googlesource.com/c/12618
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
---
M src/systemc/channel/sc_mutex.cc
M src/systemc/ext/channel/sc_mutex.hh
2 files changed, 17 insertions(+), 6 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved



diff --git a/src/systemc/channel/sc_mutex.cc b/src/systemc/channel/sc_mutex.cc
index 80d086f..9c5e9c2 100644
--- a/src/systemc/channel/sc_mutex.cc
+++ b/src/systemc/channel/sc_mutex.cc
@@ -28,6 +28,7 @@
  */

 #include "base/logging.hh"
+#include "systemc/core/scheduler.hh"
 #include "systemc/ext/channel/sc_mutex.hh"
 #include "systemc/ext/core/sc_module.hh" // for sc_gen_unique_name

@@ -45,24 +46,29 @@
 int
 sc_mutex::lock()
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    while (trylock() == -1)
+        wait(unlockEvent);
     return 0;
 }

 int
 sc_mutex::trylock()
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    if (holder.valid())
+        return -1;
+    holder = ::sc_gem5::scheduler.current();
     return 0;
 }

 int
 sc_mutex::unlock()
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    if (holder != ::sc_gem5::scheduler.current())
+        return -1;
+
+    holder = nullptr;
+    unlockEvent.notify();
     return 0;
 }

-const char *sc_mutex::kind() const { return "sc_mutex"; }
-
 } // namespace sc_core
diff --git a/src/systemc/ext/channel/sc_mutex.hh b/src/systemc/ext/channel/sc_mutex.hh
index af35bdd..12205da 100644
--- a/src/systemc/ext/channel/sc_mutex.hh
+++ b/src/systemc/ext/channel/sc_mutex.hh
@@ -30,7 +30,9 @@
 #ifndef __SYSTEMC_EXT_CHANNEL_SC_MUTEX_HH__
 #define __SYSTEMC_EXT_CHANNEL_SC_MUTEX_HH__

+#include "../core/sc_event.hh"
 #include "../core/sc_object.hh"
+#include "../core/sc_process_handle.hh"
 #include "sc_mutex_if.hh"

 namespace sc_core
@@ -46,12 +48,15 @@
     virtual int trylock();
     virtual int unlock();

-    virtual const char *kind() const;
+    virtual const char *kind() const { return "sc_mutex"; }

   private:
     // Disabled
sc_mutex(const sc_mutex &) : sc_interface(), sc_mutex_if(), sc_object() {}
     sc_mutex &operator = (const sc_mutex &) { return *this; }
+
+    sc_process_handle holder;
+    sc_event unlockEvent;
 };

 } // namespace sc_core

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12618
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: I8a5bd03b46d44aeca3bba15a01a5f2180b4ed5c7
Gerrit-Change-Number: 12618
Gerrit-PatchSet: 7
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Matthias Jung <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to