TLM-2.0: include/tlm/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_put_get.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# include/tlm/tlm_1/tlm_req_rsp/tlm_channels/tlm_fifo/tlm_fifo_put_get.h

Go to the documentation of this file.

    00001 /*****************************************************************************
    00002
    00003   The following code is derived, directly or indirectly, from the SystemC
    00004   source code Copyright (c) 1996-2008 by all Contributors.
    00005   All Rights reserved.
    00006
    00007   The contents of this file are subject to the restrictions and limitations
    00008   set forth in the SystemC Open Source License Version 3.0 (the "License");
    00009   You may not use this file except in compliance with such restrictions and
    00010   limitations. You may obtain instructions on how to receive a copy of the
    00011   License at http://www.systemc.org/. Software distributed by Contributors
    00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
    00013   ANY KIND, either express or implied. See the License for the specific
    00014   language governing rights and limitations under the License.
    00015
    00016  *****************************************************************************/
    00017
    00018 #ifndef __TLM_FIFO_PUT_GET_IF_H__
    00019 #define __TLM_FIFO_PUT_GET_IF_H__
    00020
    00021 namespace tlm {
    00022
    00023 /******************************************************************
    00024 //
    00025 // get interface
    00026 //
    00027 ******************************************************************/
    00028
    00029 template <typename T>
    00030 inline
    00031 T
    00032 tlm_fifo<T>::get( tlm_tag<T> * )
    00033 {
    00034
    00035   while( is_empty() ) {
    00036     wait( m_data_written_event );
    00037   }
    00038
    00039   m_num_read ++;
    00040   request_update();
    00041
    00042   return buffer->read();
    00043
    00044 }
    00045
    00046 // non-blocking read
    00047
    00048 template <typename T>
    00049 inline
    00050 bool
    00051 tlm_fifo<T>::nb_get( T& val_ )
    00052 {
    00053
    00054   if( is_empty() ) {
    00055     return false;
    00056   }
    00057
    00058   m_num_read ++;
    00059   request_update();
    00060
    00061   val_ = buffer->read();
    00062
    00063   return true;
    00064
    00065 }
    00066
    00067 template <typename T>
    00068 inline
    00069 bool
    00070 tlm_fifo<T>::nb_can_get( tlm_tag<T> * ) const {
    00071
    00072   return !is_empty();
    00073
    00074 }
    00075
    00076
    00077 /******************************************************************
    00078 //
    00079 // put interface
    00080 //
    00081 ******************************************************************/
    00082
    00083 template <typename T>
    00084 inline
    00085 void
    00086 tlm_fifo<T>::put( const T& val_ )
    00087 {
    00088     while( is_full() ) {
    00089         wait( m_data_read_event );
    00090     }
    00091
    00092     if( buffer->is_full() ) {
    00093
    00094       buffer->resize( buffer->size() * 2 );
    00095
    00096     }
    00097
    00098     m_num_written ++;
    00099     buffer->write( val_ );
    00100
    00101     request_update();
    00102 }
    00103
    00104 template <typename T>
    00105 inline
    00106 bool
    00107 tlm_fifo<T>::nb_put( const T& val_ )
    00108 {
    00109
    00110   if( is_full() ) {
    00111     return false;
    00112   }
    00113
    00114   if( buffer->is_full() ) {
    00115
    00116     buffer->resize( buffer->size() * 2 );
    00117
    00118   }
    00119
    00120   m_num_written ++;
    00121   buffer->write( val_ );
    00122   request_update();
    00123
    00124   return true;
    00125 }
    00126
    00127 template < typename T >
    00128 inline
    00129 bool
    00130 tlm_fifo<T>::nb_can_put( tlm_tag<T> * ) const {
    00131
    00132   return !is_full();
    00133
    00134 }
    00135
    00136 } // namespace tlm
    00137
    00138 #endif