Jump to content

Can we use smart pointer in peq_with_get?


Recommended Posts

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 : 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;
 
        }
    }
}
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...