#include #include struct mutex // platform/OS specific synchronisation primitive { mutex(); void lock(); void unlock(); ~mutex(); private: // disabled mutex( const mutex & ); mutex& operator=( const mutex& ); // ... }; struct scoped_lock { explicit scoped_lock( mutex & mtx ) // locking constructor : mtx_(mtx) { mtx_.lock(); } ~scoped_lock() { mtx_.unlock(); } // unlocking destructor private: mutex& mtx_; // disabled scoped_lock( const scoped_lock& ); }; template class async_signal : public sc_signal_inout_if , public sc_prim_channel { public: async_signal( const char* nm = sc_gen_unique_name("async_signal") ) : sc_prim_channel( nm ) , m_new_val(), m_cur_val() {} // sc_signal_in_if -- only called from SystemC processes virtual const T& read() const { return m_cur_val; } virtual const sc_event& value_changed_event() const; virtual bool event() const; // sc_signal_write_if -- written from outside of SystemC virtual void write( const T& val ) { scoped_lock lock(m_mutex); // lock m_new_val sc_prim_channel::async_request_update(); m_new_val = val; } virtual void update() { scoped_lock lock(m_mutex); // lock m_new_val if( m_new_val != m_cur_val ){ m_value_changed_event.notify( SC_ZERO_TIME ); m_cur_val = m_new_val; } } private: T m_new_val, m_cur_val; sc_event m_value_changed_event; mutex m_mutex; // platform/OS specific synchronisation primitive };