summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-10-05 16:12:11 -0700
committerGabe Black <gabeblack@google.com>2018-10-16 00:58:23 +0000
commit1f4e37911934a90088a8c68dc981ed6cc1be7b9c (patch)
treec35a06945bc7f707ef97227dcd5b376b37c6d6c4
parent3287171e087ecfe6d22a86703aab29a2bbd3519a (diff)
downloadgem5-1f4e37911934a90088a8c68dc981ed6cc1be7b9c.tar.xz
systemc: Add a range check to the intial value of sc_semaphore.
Change-Id: I4e1ef90b14074e5a2794a4386e411397213b2789 Reviewed-on: https://gem5-review.googlesource.com/c/13304 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
-rw-r--r--src/systemc/channel/sc_semaphore.cc18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/systemc/channel/sc_semaphore.cc b/src/systemc/channel/sc_semaphore.cc
index ba52c199b..59191be4e 100644
--- a/src/systemc/channel/sc_semaphore.cc
+++ b/src/systemc/channel/sc_semaphore.cc
@@ -27,21 +27,29 @@
* Authors: Gabe Black
*/
+#include <string>
+
#include "base/logging.hh"
#include "systemc/ext/channel/sc_semaphore.hh"
#include "systemc/ext/core/sc_module.hh" // for sc_gen_unique_name
+#include "systemc/ext/utils/sc_report_handler.hh"
namespace sc_core
{
sc_semaphore::sc_semaphore(int value) :
- sc_interface(), sc_semaphore_if(),
- sc_object(sc_gen_unique_name("semaphore")), _value(value)
+ sc_semaphore(sc_gen_unique_name("semaphore"), value)
{}
-sc_semaphore::sc_semaphore(const char *name, int value) :
- sc_interface(), sc_semaphore_if(), sc_object(name), _value(value)
-{}
+sc_semaphore::sc_semaphore(const char *_name, int value) :
+ sc_interface(), sc_semaphore_if(), sc_object(_name), _value(value)
+{
+ if (value < 0) {
+ std::string msg = "semaphore '" + std::string(name()) + "'";
+ SC_REPORT_ERROR("(E119) sc_semaphore requires an initial value >= 0",
+ msg.c_str());
+ }
+}
int
sc_semaphore::wait()