diff options
author | Gabe Black <gabeblack@google.com> | 2018-09-11 01:51:27 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-10-09 21:46:45 +0000 |
commit | 19fbeb515aacbf954dba1d4066007736b1252c0e (patch) | |
tree | 25e8cf29b9886bf1bd5781941e9025522f8cd2e3 /src/systemc/channel | |
parent | 055b8df385393ebb995cac67f63ff63a858a3bc0 (diff) | |
download | gem5-19fbeb515aacbf954dba1d4066007736b1252c0e.tar.xz |
systemc: Implement sc_mutex.
Change-Id: I8a5bd03b46d44aeca3bba15a01a5f2180b4ed5c7
Reviewed-on: https://gem5-review.googlesource.com/c/12618
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/channel')
-rw-r--r-- | src/systemc/channel/sc_mutex.cc | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/systemc/channel/sc_mutex.cc b/src/systemc/channel/sc_mutex.cc index 80d086f55..9c5e9c20c 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 @@ sc_mutex::sc_mutex(const char *name) : 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 |