summaryrefslogtreecommitdiff
path: root/src/systemc
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-09-11 01:51:00 -0700
committerGabe Black <gabeblack@google.com>2018-10-09 21:46:26 +0000
commit055b8df385393ebb995cac67f63ff63a858a3bc0 (patch)
treef7d8dce0bda408cd312a95f7e0cb063a20bcc93d /src/systemc
parent845433025772e7d5fda6bcde1cd804a36f46a4e8 (diff)
downloadgem5-055b8df385393ebb995cac67f63ff63a858a3bc0.tar.xz
systemc: Implement sc_semaphore.
Change-Id: I778d41bd81880e76caa71dc92359a00127d8f987 Reviewed-on: https://gem5-review.googlesource.com/c/12617 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc')
-rw-r--r--src/systemc/channel/sc_semaphore.cc28
-rw-r--r--src/systemc/ext/channel/sc_semaphore.hh6
2 files changed, 18 insertions, 16 deletions
diff --git a/src/systemc/channel/sc_semaphore.cc b/src/systemc/channel/sc_semaphore.cc
index cfae59804..ba52c199b 100644
--- a/src/systemc/channel/sc_semaphore.cc
+++ b/src/systemc/channel/sc_semaphore.cc
@@ -34,43 +34,41 @@
namespace sc_core
{
-sc_semaphore::sc_semaphore(int) :
+sc_semaphore::sc_semaphore(int value) :
sc_interface(), sc_semaphore_if(),
- sc_object(sc_gen_unique_name("semaphore"))
+ sc_object(sc_gen_unique_name("semaphore")), _value(value)
{}
-sc_semaphore::sc_semaphore(const char *name, int) :
- sc_interface(), sc_semaphore_if(), sc_object(name)
+sc_semaphore::sc_semaphore(const char *name, int value) :
+ sc_interface(), sc_semaphore_if(), sc_object(name), _value(value)
{}
int
sc_semaphore::wait()
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ while (trywait() == -1)
+ ::sc_core::wait(posted);
return 0;
}
int
sc_semaphore::trywait()
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return 0;
-}
+ if (!_value)
+ return -1;
-int
-sc_semaphore::post()
-{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ _value--;
return 0;
}
int
-sc_semaphore::get_value() const
+sc_semaphore::post()
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ if (_value++ == 0)
+ posted.notify();
return 0;
}
-const char *sc_semaphore::kind() const { return "sc_semaphore"; }
+int sc_semaphore::get_value() const { return _value; }
} // namespace sc_core
diff --git a/src/systemc/ext/channel/sc_semaphore.hh b/src/systemc/ext/channel/sc_semaphore.hh
index fb1e82547..31af9c708 100644
--- a/src/systemc/ext/channel/sc_semaphore.hh
+++ b/src/systemc/ext/channel/sc_semaphore.hh
@@ -30,6 +30,7 @@
#ifndef __SYSTEMC_EXT_CHANNEL_SC_SEMAPHORE_HH__
#define __SYSTEMC_EXT_CHANNEL_SC_SEMAPHORE_HH__
+#include "../core/sc_event.hh"
#include "../core/sc_object.hh"
#include "sc_semaphore_if.hh"
@@ -47,7 +48,7 @@ class sc_semaphore : public sc_semaphore_if, public sc_object
virtual int post();
virtual int get_value() const;
- virtual const char *kind() const;
+ virtual const char *kind() const { return "sc_semaphore"; }
private:
// Disabled
@@ -56,6 +57,9 @@ class sc_semaphore : public sc_semaphore_if, public sc_object
{}
sc_semaphore &operator = (const sc_semaphore &) { return *this; }
+
+ int _value;
+ sc_event posted;
};
} // namespace sc_core