python.cc (13038:7bf84150855b) | python.cc (13323:1cfcaaf573b9) |
---|---|
1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright --- 26 unchanged lines hidden (view full) --- 35#include "sim/init.hh" 36 37namespace sc_gem5 38{ 39 40namespace 41{ 42 | 1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright --- 26 unchanged lines hidden (view full) --- 35#include "sim/init.hh" 36 37namespace sc_gem5 38{ 39 40namespace 41{ 42 |
43std::vector<PythonReadyFunc *> pythonReadyFuncs; 44std::vector<PythonInitFunc *> pythonInitFuncs; | 43PythonReadyFunc *& 44firstReadyFunc() 45{ 46 static PythonReadyFunc *first = nullptr; 47 return first; 48} |
45 | 49 |
50PythonInitFunc *& 51firstInitFunc() 52{ 53 static PythonInitFunc *first = nullptr; 54 return first; 55} 56 |
|
46void 47python_ready(pybind11::args args) 48{ | 57void 58python_ready(pybind11::args args) 59{ |
49 for (auto &func: pythonReadyFuncs) 50 func->run(); | 60 for (auto ptr = firstReadyFunc(); ptr; ptr = ptr->next) 61 ptr->run(); |
51} 52 53void 54systemc_pybind(pybind11::module &m_internal) 55{ 56 pybind11::module m = m_internal.def_submodule("systemc"); 57 m.def("python_ready", &python_ready); | 62} 63 64void 65systemc_pybind(pybind11::module &m_internal) 66{ 67 pybind11::module m = m_internal.def_submodule("systemc"); 68 m.def("python_ready", &python_ready); |
58 for (auto &func: pythonInitFuncs) 59 func->run(m); | 69 for (auto ptr = firstInitFunc(); ptr; ptr = ptr->next) 70 ptr->run(m); |
60} 61EmbeddedPyBind embed_("systemc", &systemc_pybind); 62 63} // anonymous namespace 64 | 71} 72EmbeddedPyBind embed_("systemc", &systemc_pybind); 73 74} // anonymous namespace 75 |
65PythonReadyFunc::PythonReadyFunc() | 76PythonReadyFunc::PythonReadyFunc() : next(firstReadyFunc()) |
66{ | 77{ |
67 pythonReadyFuncs.push_back(this); | 78 firstReadyFunc() = this; |
68} 69 | 79} 80 |
70PythonInitFunc::PythonInitFunc() | 81PythonInitFunc::PythonInitFunc() : next(firstInitFunc()) |
71{ | 82{ |
72 pythonInitFuncs.push_back(this); | 83 firstInitFunc() = this; |
73} 74 75} // namespace sc_gem5 | 84} 85 86} // namespace sc_gem5 |