TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
tlm_fifo_put_get.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 #ifndef __TLM_FIFO_PUT_GET_IF_H__
19 #define __TLM_FIFO_PUT_GET_IF_H__
20 
21 namespace tlm {
22 
23 /******************************************************************
24 //
25 // get interface
26 //
27 ******************************************************************/
28 
29 template <typename T>
30 inline
31 T
33 {
34 
35  while( is_empty() ) {
36  wait( m_data_written_event );
37  }
38 
39  m_num_read ++;
40  request_update();
41 
42  return buffer.read();
43 
44 }
45 
46 // non-blocking read
47 
48 template <typename T>
49 inline
50 bool
52 {
53 
54  if( is_empty() ) {
55  return false;
56  }
57 
58  m_num_read ++;
59  request_update();
60 
61  val_ = buffer.read();
62 
63  return true;
64 
65 }
66 
67 template <typename T>
68 inline
69 bool
71 
72  return !is_empty();
73 
74 }
75 
76 
77 /******************************************************************
78 //
79 // put interface
80 //
81 ******************************************************************/
82 
83 template <typename T>
84 inline
85 void
86 tlm_fifo<T>::put( const T& val_ )
87 {
88  while( is_full() ) {
89  wait( m_data_read_event );
90  }
91 
92  if( buffer.is_full() ) {
93 
94  buffer.resize( buffer.size() * 2 );
95 
96  }
97 
98  m_num_written ++;
99  buffer.write( val_ );
100 
101  request_update();
102 }
103 
104 template <typename T>
105 inline
106 bool
107 tlm_fifo<T>::nb_put( const T& val_ )
108 {
109 
110  if( is_full() ) {
111  return false;
112  }
113 
114  if( buffer.is_full() ) {
115 
116  buffer.resize( buffer.size() * 2 );
117 
118  }
119 
120  m_num_written ++;
121  buffer.write( val_ );
122  request_update();
123 
124  return true;
125 }
126 
127 template < typename T >
128 inline
129 bool
131 
132  return !is_full();
133 
134 }
135 
136 } // namespace tlm
137 
138 #endif
void wait(int, sc_simcontext *)
T get(tlm_tag< T > *=0)
void put(const T &)
bool nb_can_put(tlm_tag< T > *=0) const
bool nb_get(T &)
bool nb_put(const T &)
bool nb_can_get(tlm_tag< T > *=0) const