summaryrefslogtreecommitdiff
path: root/src/systemc/core/python.cc
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-10-07 03:59:56 -0700
committerGabe Black <gabeblack@google.com>2018-10-16 01:12:26 +0000
commit3420f0e223888bf70cd502efb5a534e651891b5c (patch)
treeb8482805bf9b7febebb9775aa87cc0d82787c1f7 /src/systemc/core/python.cc
parentb366cbcde953e2adddc10a2825e2803b5f8a9bdd (diff)
downloadgem5-3420f0e223888bf70cd502efb5a534e651891b5c.tar.xz
systemc: Don't depend on the order of static initializers.
STL containers may need to be constructed before they're used. Don't count on being able to insert into them during a static initializer. Change-Id: Icb05d5084a470e1ebd976ae6e1954b1a78aabd6a Reviewed-on: https://gem5-review.googlesource.com/c/13329 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/core/python.cc')
-rw-r--r--src/systemc/core/python.cc31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/systemc/core/python.cc b/src/systemc/core/python.cc
index 99d6cc9a0..e4a0dd0cb 100644
--- a/src/systemc/core/python.cc
+++ b/src/systemc/core/python.cc
@@ -40,14 +40,25 @@ namespace sc_gem5
namespace
{
-std::vector<PythonReadyFunc *> pythonReadyFuncs;
-std::vector<PythonInitFunc *> pythonInitFuncs;
+PythonReadyFunc *&
+firstReadyFunc()
+{
+ static PythonReadyFunc *first = nullptr;
+ return first;
+}
+
+PythonInitFunc *&
+firstInitFunc()
+{
+ static PythonInitFunc *first = nullptr;
+ return first;
+}
void
python_ready(pybind11::args args)
{
- for (auto &func: pythonReadyFuncs)
- func->run();
+ for (auto ptr = firstReadyFunc(); ptr; ptr = ptr->next)
+ ptr->run();
}
void
@@ -55,21 +66,21 @@ systemc_pybind(pybind11::module &m_internal)
{
pybind11::module m = m_internal.def_submodule("systemc");
m.def("python_ready", &python_ready);
- for (auto &func: pythonInitFuncs)
- func->run(m);
+ for (auto ptr = firstInitFunc(); ptr; ptr = ptr->next)
+ ptr->run(m);
}
EmbeddedPyBind embed_("systemc", &systemc_pybind);
} // anonymous namespace
-PythonReadyFunc::PythonReadyFunc()
+PythonReadyFunc::PythonReadyFunc() : next(firstReadyFunc())
{
- pythonReadyFuncs.push_back(this);
+ firstReadyFunc() = this;
}
-PythonInitFunc::PythonInitFunc()
+PythonInitFunc::PythonInitFunc() : next(firstInitFunc())
{
- pythonInitFuncs.push_back(this);
+ firstInitFunc() = this;
}
} // namespace sc_gem5