Allen yang Posted October 22, 2023 Report Share Posted October 22, 2023 Here is my code. When I use get_next_transaction to get deley transaction. It failed. I found that get_next_transaction used for pointer. So here is my question, can we use smart pointer with peq_with_get? class A : public sc_module { public: SC_HAS_PROCESS(A); A(const sc_module_name& name) : sc_module(name) , m_period (sc_time(1000,SC_PS)) , m_test_peq("test_peq") { SC_THREAD(PushPeq_1); SC_THREAD(PushPeq_2); SC_THREAD(GetPeq); sensitive<<m_test_peq.get_event();//sensitive event list }; public: void PushPeq_1(); void PushPeq_2(); void GetPeq(); ~A() {;} public: sc_time m_period; tlm_utils::peq_with_get<shared_ptr<int>> m_test_peq; }; void A::GetPeq() { shared_ptr<int> t_get = NULL; while(1) { wait(); while((t_get = m_test_peq.get_next_transaction()) != NULL) { delete t_get; //dynamic memory space, delete when no use t_get = NULL; } } } Quote Link to comment Share on other sites More sharing options...
Eyck Posted October 22, 2023 Report Share Posted October 22, 2023 I don't think so. Although you call notify with a reference it internally stores the pointer to to the object. You as modeler are in charge of the lifetime of the object pointed to. So if you have a shared_ptr with local lifetime (which is the use-model of a shared_ptr) the peq has a danglng pointer once the local shared_ptr is destroyed (not the object it pointed to). This is one reason we wrote our own peq at https://github.com/Minres/SystemC-Components/blob/main/src/sysc/scc/peq.h Allen yang 1 Quote Link to comment Share on other sites More sharing options...
Allen yang Posted October 23, 2023 Author Report Share Posted October 23, 2023 Thanks a lot. Do you have an example about how to use peq.h? Quote Link to comment Share on other sites More sharing options...
Eyck Posted October 23, 2023 Report Share Posted October 23, 2023 One example is a APB initiator: https://github.com/Minres/SystemC-Components/blob/develop/src/bus_interfaces/apb/pe/apb_initiator.cpp#L40 for the notification and https://github.com/Minres/SystemC-Components/blob/develop/src/bus_interfaces/apb/pe/apb_initiator.cpp#L63 for pulling entries Allen yang 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.