diff options
Diffstat (limited to 'src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo')
5 files changed, 442 insertions, 527 deletions
diff --git a/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/circular_buffer.h b/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/circular_buffer.h index 50309e31b..c00fe4881 100644 --- a/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/circular_buffer.h +++ b/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/circular_buffer.h @@ -17,252 +17,239 @@ *****************************************************************************/ -// -// To the LRM writer : this class is purely an artifact of the implementation. -// - -#ifndef __CIRCULAR_BUFFER_H__ -#define __CIRCULAR_BUFFER_H__ +#ifndef \ + __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_CIRCULAR_BUFFER_H__ +#define \ + __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_CIRCULAR_BUFFER_H__ #include <iostream> -namespace tlm { +namespace tlm +{ -template < typename T > +template <typename T> class circular_buffer { -public: - - explicit - circular_buffer( int size = 0 ); - ~circular_buffer(); - - void resize( int size ); - void clear(); - - T read(); - void write( const T & ); - - bool is_empty() const { return used() == 0; } - bool is_full() const { return free() == 0; } - - int size() const { return m_size; } - int used() const { return m_used; } - int free() const { return m_free; } - - const T& read_data() const - { return buf_read( m_buf, m_ri ); } - - const T& peek_data( int i ) const - { return buf_read( m_buf, (m_ri + i) % size() ); } - - T & poke_data( int i ) - { return buf_read( m_buf , (m_wi + i) % size() ); } - - void debug() const; - -private: - void increment_write_pos( int i = 1 ); - void increment_read_pos( int i = 1 ); - - void init(); - - circular_buffer( const circular_buffer<T> &b ); // disabled - circular_buffer<T> &operator=( const circular_buffer<T> & ); // disabled - - void* buf_alloc( int size ); - void buf_free( void*& buf ); - void buf_write( void* buf, int n, const T & t ); - T& buf_read( void* buf, int n ) const; - void buf_clear( void* buf, int n ); - -private: - int m_size; // size of the buffer - void* m_buf; // the buffer - int m_free; // number of free spaces - int m_used; // number of used spaces - int m_ri; // index of next read - int m_wi; // index of next write - + public: + explicit circular_buffer(int size=0); + ~circular_buffer(); + + void resize(int size); + void clear(); + + T read(); + void write(const T &); + + bool is_empty() const { return used() == 0; } + bool is_full() const { return free() == 0; } + + int size() const { return m_size; } + int used() const { return m_used; } + int free() const { return m_free; } + + const T &read_data() const { return buf_read(m_buf, m_ri); } + const T & + peek_data(int i) const + { + return buf_read(m_buf, (m_ri + i) % size()); + } + + T & + poke_data(int i) + { + return buf_read(m_buf, (m_wi + i) % size()); + } + + void debug() const; + + private: + void increment_write_pos(int i=1); + void increment_read_pos(int i=1); + + void init(); + + // Disabled. + circular_buffer(const circular_buffer<T> &b); + circular_buffer<T> &operator = (const circular_buffer<T> &); + + void *buf_alloc(int size); + void buf_free(void *&buf); + void buf_write(void *buf, int n, const T &t); + T &buf_read(void *buf, int n) const; + void buf_clear(void *buf, int n); + + private: + int m_size; // size of the buffer + void *m_buf; // the buffer + int m_free; // number of free spaces + int m_used; // number of used spaces + int m_ri; // index of next read + int m_wi; // index of next write }; -template< typename T > +template <typename T> void circular_buffer<T>::debug() const { - - std::cout << "Buffer debug" << std::endl; - std::cout << "Size : " << size() << std::endl; - std::cout << "Free/Used " << free() << "/" << used() << std::endl; - std::cout << "Indices : r/w = " << m_ri << "/" << m_wi << std::endl; - - if( is_empty() ) { - - std::cout << "empty" << std::endl; - - } - - if( is_full() ) { - - std::cout << "full" << std::endl; - - } - - std::cout << "Data : " << std::endl; - for( int i = 0; i < used(); i++ ) { - - std::cout << peek_data( i ) << std::endl; - - } - - + std::cout << "Buffer debug" << std::endl; + std::cout << "Size : " << size() << std::endl; + std::cout << "Free/Used " << free() << "/" << used() << std::endl; + std::cout << "Indices : r/w = " << m_ri << "/" << m_wi << std::endl; + + if (is_empty()) { + std::cout << "empty" << std::endl; + } + + if (is_full()) { + std::cout << "full" << std::endl; + } + + std::cout << "Data : " << std::endl; + for (int i = 0; i < used(); i++) { + std::cout << peek_data( i ) << std::endl; + } } -template < typename T > -circular_buffer<T>::circular_buffer( int size ) - : m_size(size) - , m_buf(0) +template <typename T> +circular_buffer<T>::circular_buffer(int size) : m_size(size), m_buf(0) { - init(); - + init(); } -template < typename T > +template <typename T> void circular_buffer<T>::clear() { - for( int i=0; i < used(); i++ ) { - buf_clear( m_buf, (m_ri + i) % m_size ); - } - m_free = m_size; - m_used = m_ri = m_wi = 0; + for (int i = 0; i < used(); i++) { + buf_clear(m_buf, (m_ri + i) % m_size); + } + m_free = m_size; + m_used = m_ri = m_wi = 0; } -template < typename T > +template <typename T> circular_buffer<T>::~circular_buffer() { - clear(); - buf_free( m_buf ); + clear(); + buf_free(m_buf); } -template < typename T > +template <typename T> void -circular_buffer<T>::resize( int size ) +circular_buffer<T>::resize(int size) { + int i; + void *new_buf = buf_alloc(size); - int i; - void * new_buf = buf_alloc(size); - - for( i = 0; i < size && i < used(); i++ ) { + for (i = 0; i < size && i < used(); i++) { + buf_write(new_buf, i, peek_data(i)); + buf_clear(m_buf, (m_ri + i) % m_size); + } - buf_write( new_buf, i, peek_data( i ) ); - buf_clear( m_buf, (m_ri + i) % m_size ); + buf_free(m_buf); - } + m_size = size; + m_ri = 0; + m_wi = i % m_size; + m_used = i; + m_free = m_size - m_used; - buf_free( m_buf ); - - m_size = size; - m_ri = 0; - m_wi = i % m_size; - m_used = i; - m_free = m_size - m_used; - - m_buf = new_buf; + m_buf = new_buf; } -template < typename T > +template <typename T> void -circular_buffer<T>::init() { - - if( m_size > 0 ) { - m_buf = buf_alloc( m_size ); - } - - m_free = m_size; - m_used = 0; - m_ri = 0; - m_wi = 0; - +circular_buffer<T>::init() +{ + if (m_size > 0) { + m_buf = buf_alloc(m_size); + } + + m_free = m_size; + m_used = 0; + m_ri = 0; + m_wi = 0; } -template < typename T > +template <typename T> T circular_buffer<T>::read() { - T t = read_data(); + T t = read_data(); - buf_clear( m_buf, m_ri ); - increment_read_pos(); + buf_clear(m_buf, m_ri); + increment_read_pos(); - return t; + return t; } -template < typename T > +template <typename T> void -circular_buffer<T>::write( const T &t ) +circular_buffer<T>::write(const T &t) { - buf_write( m_buf, m_wi, t ); - increment_write_pos(); + buf_write(m_buf, m_wi, t); + increment_write_pos(); } - -template < typename T > +template <typename T> void -circular_buffer<T>::increment_write_pos( int i ) { - - m_wi = ( m_wi + i ) % m_size; - m_used += i; - m_free -= i; - +circular_buffer<T>::increment_write_pos(int i) +{ + m_wi = (m_wi + i) % m_size; + m_used += i; + m_free -= i; } -template < typename T > +template <typename T> void -circular_buffer<T>::increment_read_pos( int i ) { - - m_ri = ( m_ri + i ) % m_size; - m_used -= i; - m_free += i; - +circular_buffer<T>::increment_read_pos(int i) +{ + m_ri = (m_ri + i) % m_size; + m_used -= i; + m_free += i; } -template < typename T > -inline void* -circular_buffer<T>::buf_alloc( int size ) - { return new unsigned char[ size * sizeof(T) ]; } +template <typename T> +inline void * +circular_buffer<T>::buf_alloc(int size) +{ + return new unsigned char [size * sizeof(T)]; +} -template < typename T > +template <typename T> inline void -circular_buffer<T>::buf_free( void* & buf ) - { delete [] static_cast<unsigned char*>(buf); buf = 0; } +circular_buffer<T>::buf_free(void *&buf) +{ + delete [] static_cast<unsigned char *>(buf); + buf = nullptr; +} -template < typename T > +template <typename T> inline void -circular_buffer<T>::buf_write( void* buf, int n, const T & t ) +circular_buffer<T>::buf_write(void *buf, int n, const T &t) { - T* p = static_cast<T*>(buf) + n; - new (p) T(t); + T *p = static_cast<T *>(buf) + n; + new (p)T(t); } -template < typename T > -inline T& -circular_buffer<T>::buf_read( void* buf, int n ) const +template <typename T> +inline T & +circular_buffer<T>::buf_read(void *buf, int n) const { - T* p = static_cast<T*>(buf) + n; - return *p; + T *p = static_cast<T *>(buf) + n; + return *p; } -template < typename T > +template <typename T> inline void -circular_buffer<T>::buf_clear( void* buf, int n ) +circular_buffer<T>::buf_clear(void *buf, int n) { - T* p = static_cast<T*>(buf) + n; - p->~T(); + T *p = static_cast<T *>(buf) + n; + p->~T(); } } // namespace tlm #endif - +/* __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_CIRCULAR_BUFFER_H__ */ diff --git a/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo.h b/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo.h index 7b44a32ee..25a183459 100644 --- a/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo.h +++ b/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo.h @@ -17,8 +17,10 @@ *****************************************************************************/ -#ifndef __TLM_FIFO_H__ -#define __TLM_FIFO_H__ +#ifndef \ + __SYSTEMC_EXT_TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_H__ +#define \ + __SYSTEMC_EXT_TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_H__ // // This implements put, get and peek @@ -34,171 +36,147 @@ // actual physical buffer. // -//#include <systemc> - #include "tlm_core/tlm_1/tlm_req_rsp/tlm_1_interfaces/tlm_fifo_ifs.h" #include "tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/circular_buffer.h" -namespace tlm { +namespace tlm +{ template <typename T> -class tlm_fifo : - public virtual tlm_fifo_get_if<T>, - public virtual tlm_fifo_put_if<T>, - public sc_core::sc_prim_channel +class tlm_fifo : public virtual tlm_fifo_get_if<T>, + public virtual tlm_fifo_put_if<T>, public sc_core::sc_prim_channel { -public: - - // constructors - - explicit tlm_fifo( int size_ = 1 ) - : sc_core::sc_prim_channel( sc_core::sc_gen_unique_name( "fifo" ) ) { - - init( size_ ); - + public: + // Constructors. + explicit tlm_fifo(int size_=1) : + sc_core::sc_prim_channel(sc_core::sc_gen_unique_name("fifo")) + { + init(size_); } - explicit tlm_fifo( const char* name_, int size_ = 1 ) - : sc_core::sc_prim_channel( name_ ) { - - init( size_ ); - + explicit tlm_fifo(const char *name_, int size_=1) : + sc_core::sc_prim_channel(name_) + { + init(size_); } - // destructor - + // Destructor.. virtual ~tlm_fifo() {} - // tlm get interface - - T get( tlm_tag<T> * = 0 ); + // Tlm get interface. + T get(tlm_tag<T> * =nullptr); - bool nb_get( T& ); - bool nb_can_get( tlm_tag<T> * = 0 ) const; - const sc_core::sc_event &ok_to_get( tlm_tag<T> * = 0 ) const { - return m_data_written_event; + bool nb_get(T &); + bool nb_can_get(tlm_tag<T> * =nullptr) const; + const sc_core::sc_event & + ok_to_get(tlm_tag<T> * =nullptr) const + { + return m_data_written_event; } - // tlm peek interface + // Tlm peek interface. + T peek(tlm_tag<T> * =nullptr) const; - T peek( tlm_tag<T> * = 0 ) const; - - bool nb_peek( T& ) const; - bool nb_can_peek( tlm_tag<T> * = 0 ) const; - const sc_core::sc_event &ok_to_peek( tlm_tag<T> * = 0 ) const { - return m_data_written_event; + bool nb_peek(T &) const; + bool nb_can_peek(tlm_tag<T> * =nullptr) const; + const sc_core::sc_event & + ok_to_peek(tlm_tag<T> * =nullptr) const + { + return m_data_written_event; } - // tlm put interface - - void put( const T& ); - - bool nb_put( const T& ); - bool nb_can_put( tlm_tag<T> * = 0 ) const; + // Tlm put interface. + void put(const T &); - const sc_core::sc_event& ok_to_put( tlm_tag<T> * = 0 ) const { - return m_data_read_event; + bool nb_put(const T &); + bool nb_can_put(tlm_tag<T> * =nullptr) const; + const sc_core::sc_event & + ok_to_put(tlm_tag<T> * =nullptr) const + { + return m_data_read_event; } - // resize if - - void nb_expand( unsigned int n = 1 ); - void nb_unbound( unsigned int n = 16 ); - - bool nb_reduce( unsigned int n = 1 ); - bool nb_bound( unsigned int n ); - - // debug interface - - bool nb_peek( T & , int n ) const; - bool nb_poke( const T & , int n = 0 ); - - int used() const { - return m_num_readable - m_num_read; - } - - int size() const { - return m_size; + // Resize if. + void nb_expand(unsigned int n=1); + void nb_unbound(unsigned int n=16); + + bool nb_reduce(unsigned int n=1); + bool nb_bound(unsigned int n); + + // Debug interface. + bool nb_peek(T &, int n) const; + bool nb_poke(const T &, int n=0); + + int used() const { return m_num_readable - m_num_read; } + int size() const { return m_size; } + + void + debug() const + { + if (is_empty()) + std::cout << "empty" << std::endl; + if (is_full()) + std::cout << "full" << std::endl; + + std::cout << "size " << size() << " - " << used() << " used " + << std::endl; + std::cout << "readable " << m_num_readable << std::endl; + std::cout << "written/read " << m_num_written << "/" << m_num_read + << std::endl; } - void debug() const { - - if( is_empty() ) std::cout << "empty" << std::endl; - if( is_full() ) std::cout << "full" << std::endl; - - std::cout << "size " << size() << " - " << used() << " used " - << std::endl; - std::cout << "readable " << m_num_readable - << std::endl; - std::cout << "written/read " << m_num_written << "/" << m_num_read - << std::endl; + // Support functions. + static const char * const kind_string; + const char *kind() const { return kind_string; } + protected: + sc_core::sc_event & + read_event(tlm_tag<T> * =nullptr) + { + return m_data_read_event; } - // support functions - - static const char* const kind_string; - - const char* kind() const - { return kind_string; } - - -protected: - sc_core::sc_event &read_event( tlm_tag<T> * = 0 ) { - return m_data_read_event; - } - -protected: - void update(); - - // support methods - - void init( int ); - -protected: + void init(int); circular_buffer<T> buffer; - int m_size; // logical size of fifo + int m_size; // logical size of fifo - int m_num_readable; // #samples readable - int m_num_read; // #samples read during this delta cycle - int m_num_written; // #samples written during this delta cycle - bool m_expand; // has an expand occurred during this delta cycle ? - int m_num_read_no_notify; // #samples read without notify during this delta cycle + int m_num_readable; // #samples readable + int m_num_read; // #samples read during this delta cycle + int m_num_written; // #samples written during this delta cycle + bool m_expand; // has an expand occurred during this delta cycle ? + // #samples read without notify during this delta cycle + int m_num_read_no_notify; sc_core::sc_event m_data_read_event; sc_core::sc_event m_data_written_event; -private: - + private: // disabled - tlm_fifo( const tlm_fifo<T>& ); - tlm_fifo& operator = ( const tlm_fifo<T>& ); + tlm_fifo(const tlm_fifo<T> &); + tlm_fifo &operator = (const tlm_fifo<T> &); // // use nb_can_get() and nb_can_put() rather than the following two // private functions // - bool is_empty() const { - return used() == 0; - } + bool is_empty() const { return used() == 0; } - bool is_full() const { - //return size() == m_num_readable + m_num_written; // Old buggy code - if( size() < 0 ) - return false; - else - return size() <= m_num_readable + m_num_written; + bool + is_full() const + { + if (size() < 0) + return false; + else + return size() <= m_num_readable + m_num_written; } - }; template <typename T> -const char* const tlm_fifo<T>::kind_string = "tlm_fifo"; - +const char *const tlm_fifo<T>::kind_string = "tlm_fifo"; /****************************************************************** // @@ -206,43 +184,36 @@ const char* const tlm_fifo<T>::kind_string = "tlm_fifo"; // ******************************************************************/ -template< typename T > -inline -void -tlm_fifo<T>::init( int size_ ) { - - if( size_ > 0 ) { - buffer.resize( size_ ); - } - - else if( size_ < 0 ) { - buffer.resize( -size_ ); - } - - else { - buffer.resize( 16 ); - } - - m_size = size_; - m_num_readable = 0; - m_num_read = 0; - m_num_written = 0; - m_expand = false; - m_num_read_no_notify = false; +template <typename T> +inline void +tlm_fifo<T>::init(int size_) +{ + if (size_ > 0) { + buffer.resize( size_ ); + } else if (size_ < 0) { + buffer.resize(-size_); + } else { + buffer.resize(16); + } + m_size = size_; + m_num_readable = 0; + m_num_read = 0; + m_num_written = 0; + m_expand = false; + m_num_read_no_notify = false; } -template < typename T> -inline -void +template <typename T> +inline void tlm_fifo<T>::update() { - if( m_num_read > m_num_read_no_notify || m_expand ) { - m_data_read_event.notify( sc_core::SC_ZERO_TIME ); + if (m_num_read > m_num_read_no_notify || m_expand) { + m_data_read_event.notify(sc_core::SC_ZERO_TIME); } - if( m_num_written > 0 ) { - m_data_written_event.notify( sc_core::SC_ZERO_TIME ); + if (m_num_written > 0) { + m_data_written_event.notify(sc_core::SC_ZERO_TIME); } m_expand = false; @@ -250,7 +221,6 @@ tlm_fifo<T>::update() m_num_written = 0; m_num_readable = buffer.used(); m_num_read_no_notify = 0; - } } // namespace tlm @@ -260,4 +230,4 @@ tlm_fifo<T>::update() #include "tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_resize.h" #endif - +/*__SYSTEMC_EXT_TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_H__*/ diff --git a/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_peek.h b/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_peek.h index e856c5657..540f72de6 100644 --- a/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_peek.h +++ b/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_peek.h @@ -17,82 +17,74 @@ *****************************************************************************/ -#ifndef __TLM_FIFO_PEEK_H__ -#define __TLM_FIFO_PEEK_H__ +#ifndef \ + __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_PEEK_H__ +#define \ + __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_PEEK_H__ -namespace tlm { - -template < typename T> -inline -T -tlm_fifo<T>::peek( tlm_tag<T> * ) const { - - while( is_empty() ) { - - // call free-standing sc_core::wait(), - // since sc_prim_channel::wait(.) is not const - - sc_core::wait( m_data_written_event ); - } - - return buffer.read_data(); +namespace tlm +{ +template <typename T> +inline T +tlm_fifo<T>::peek(tlm_tag<T> *) const +{ + while (is_empty()) { + // call free-standing sc_core::wait(), + // since sc_prim_channel::wait(.) is not const + sc_core::wait(m_data_written_event); + } + return buffer.read_data(); } -template < typename T> -inline -bool -tlm_fifo<T>::nb_peek( T &t ) const { - - if( used() < 1 ) { - return false; - } - - t = buffer.peek_data( 0 ); - return true; +template <typename T> +inline bool +tlm_fifo<T>::nb_peek(T &t) const +{ + if (used() < 1) { + return false; + } + t = buffer.peek_data(0); + return true; } -template < typename T> -inline -bool -tlm_fifo<T>::nb_peek( T &t , int n ) const { - - if( n >= used() || n < -1 ) { - return false; - } - - if( n == -1 ) { - n = used() - 1; - } +template <typename T> +inline bool +tlm_fifo<T>::nb_peek(T &t, int n) const +{ + if (n >= used() || n < -1) { + return false; + } - t = buffer.peek_data( n ); - return true; + if (n == -1) { + n = used() - 1; + } + t = buffer.peek_data(n); + return true; } -template< typename T > -inline -bool -tlm_fifo<T>::nb_can_peek( tlm_tag<T> * ) const +template <typename T> +inline bool +tlm_fifo<T>::nb_can_peek(tlm_tag<T> *) const { - return !is_empty(); + return !is_empty(); } -template < typename T> -inline -bool -tlm_fifo<T>::nb_poke( const T &t , int n ) { - - if( n >= used() || n < 0 ) { - return false; - } - - buffer.poke_data( n ) = t; - return true; +template <typename T> +inline bool +tlm_fifo<T>::nb_poke(const T &t, int n) +{ + if (n >= used() || n < 0) { + return false; + } + buffer.poke_data(n) = t; + return true; } } // namespace tlm #endif +/* __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_PEEK_H__ */ diff --git a/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_put_get.h b/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_put_get.h index 2728e0394..a9a8ee3f4 100644 --- a/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_put_get.h +++ b/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_put_get.h @@ -17,124 +17,100 @@ *****************************************************************************/ -#ifndef __TLM_FIFO_PUT_GET_IF_H__ -#define __TLM_FIFO_PUT_GET_IF_H__ +#ifndef \ + __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_PUT_GET_H__ +#define \ + __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_PUT_GET_H__ -namespace tlm { - -/****************************************************************** -// -// get interface -// -******************************************************************/ +namespace tlm +{ +// Get interface. template <typename T> -inline -T -tlm_fifo<T>::get( tlm_tag<T> * ) +inline T +tlm_fifo<T>::get(tlm_tag<T> *) { + while (is_empty()) { + wait(m_data_written_event); + } - while( is_empty() ) { - wait( m_data_written_event ); - } - - m_num_read ++; - request_update(); - - return buffer.read(); + m_num_read++; + request_update(); + return buffer.read(); } -// non-blocking read - +// Non-blocking read. template <typename T> -inline -bool -tlm_fifo<T>::nb_get( T& val_ ) +inline bool +tlm_fifo<T>::nb_get(T &val_) { + if (is_empty()) { + return false; + } - if( is_empty() ) { - return false; - } - - m_num_read ++; - request_update(); - - val_ = buffer.read(); + m_num_read++; + request_update(); - return true; + val_ = buffer.read(); + return true; } template <typename T> -inline -bool -tlm_fifo<T>::nb_can_get( tlm_tag<T> * ) const { - - return !is_empty(); - +inline bool +tlm_fifo<T>::nb_can_get(tlm_tag<T> *) const +{ + return !is_empty(); } -/****************************************************************** -// -// put interface -// -******************************************************************/ - +// Put interface. template <typename T> -inline -void -tlm_fifo<T>::put( const T& val_ ) +inline void +tlm_fifo<T>::put(const T &val_) { - while( is_full() ) { - wait( m_data_read_event ); + while (is_full()) { + wait(m_data_read_event); } - if( buffer.is_full() ) { - - buffer.resize( buffer.size() * 2 ); - + if (buffer.is_full()) { + buffer.resize(buffer.size() * 2); } - m_num_written ++; - buffer.write( val_ ); + m_num_written++; + buffer.write(val_); request_update(); } template <typename T> -inline -bool -tlm_fifo<T>::nb_put( const T& val_ ) +inline bool +tlm_fifo<T>::nb_put(const T &val_) { + if (is_full()) { + return false; + } - if( is_full() ) { - return false; - } - - if( buffer.is_full() ) { - - buffer.resize( buffer.size() * 2 ); - - } + if (buffer.is_full()) { + buffer.resize(buffer.size() * 2); + } - m_num_written ++; - buffer.write( val_ ); - request_update(); + m_num_written++; + buffer.write(val_); + request_update(); - return true; + return true; } -template < typename T > -inline -bool -tlm_fifo<T>::nb_can_put( tlm_tag<T> * ) const { - - return !is_full(); - +template <typename T> +inline bool +tlm_fifo<T>::nb_can_put(tlm_tag<T> *) const +{ + return !is_full(); } } // namespace tlm #endif +/* __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_PUT_GET_H__ */ diff --git a/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_resize.h b/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_resize.h index 39932fea1..79292fd78 100644 --- a/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_resize.h +++ b/src/systemc/ext/tlm_core/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_resize.h @@ -17,77 +17,67 @@ *****************************************************************************/ -#ifndef __TLM_FIFO_RESIZE_H__ -#define __TLM_FIFO_RESIZE_H__ - -/****************************************************************** -// -// resize interface -// -******************************************************************/ - -namespace tlm { - -template < typename T> -inline -void -tlm_fifo<T>::nb_expand( unsigned int n ) { - - if( m_size >= 0 ) { - m_expand = true; - m_size += n; - request_update(); - } +#ifndef \ + __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_RESIZE_H__ +#define \ + __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_RESIZE_H__ + +// Resize interface. +namespace tlm +{ + +template <typename T> +inline void +tlm_fifo<T>::nb_expand(unsigned int n) +{ + if (m_size >= 0) { + m_expand = true; + m_size += n; + request_update(); + } } -template < typename T> -inline -void -tlm_fifo<T>::nb_unbound( unsigned int n ) { - - m_expand = true; - m_size = -n; - - if( buffer.size() < static_cast<int>( n ) ) { - buffer.resize( n ); - } +template <typename T> +inline void +tlm_fifo<T>::nb_unbound(unsigned int n) +{ + m_expand = true; + m_size = -n; - request_update(); + if (buffer.size() < static_cast<int>(n)) { + buffer.resize(n); + } + request_update(); } -template < typename T> -inline -bool -tlm_fifo<T>::nb_reduce( unsigned int n ) { - - if( m_size < 0 ) { - return false; - } - - return nb_bound( size() - n ); +template <typename T> +inline bool +tlm_fifo<T>::nb_reduce(unsigned int n) +{ + if (m_size < 0) { + return false; + } + return nb_bound(size() - n); } -template < typename T> -inline -bool -tlm_fifo<T>::nb_bound( unsigned int new_size ) { - - bool ret = true; - - if( static_cast<int>( new_size ) < used() ) { - - new_size = used(); - ret = false; - - } +template <typename T> +inline bool +tlm_fifo<T>::nb_bound(unsigned int new_size) +{ + bool ret = true; - m_size = new_size; - return ret; + if (static_cast<int>(new_size) < used()) { + new_size = used(); + ret = false; + } + m_size = new_size; + return ret; } } // namespace tlm #endif +/* __TLM_CORE_TLM_1_TLM_REQ_RSP_TLM_CHANNELS_TLM_FIFO_TLM_FIFO_RESIZE_H__ */ |