TLM-2.0  2.0.4
Accellera TLM-2.0 proof-of-concept library
tlm_fifo_put_get.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 #ifndef __TLM_FIFO_PUT_GET_IF_H__
21 #define __TLM_FIFO_PUT_GET_IF_H__
22 
23 namespace tlm {
24 
25 /******************************************************************
26 //
27 // get interface
28 //
29 ******************************************************************/
30 
31 template <typename T>
32 inline
33 T
35 {
36 
37  while( is_empty() ) {
38  wait( m_data_written_event );
39  }
40 
41  m_num_read ++;
42  request_update();
43 
44  return buffer.read();
45 
46 }
47 
48 // non-blocking read
49 
50 template <typename T>
51 inline
52 bool
54 {
55 
56  if( is_empty() ) {
57  return false;
58  }
59 
60  m_num_read ++;
61  request_update();
62 
63  val_ = buffer.read();
64 
65  return true;
66 
67 }
68 
69 template <typename T>
70 inline
71 bool
73 
74  return !is_empty();
75 
76 }
77 
78 
79 /******************************************************************
80 //
81 // put interface
82 //
83 ******************************************************************/
84 
85 template <typename T>
86 inline
87 void
88 tlm_fifo<T>::put( const T& val_ )
89 {
90  while( is_full() ) {
91  wait( m_data_read_event );
92  }
93 
94  if( buffer.is_full() ) {
95 
96  buffer.resize( buffer.size() * 2 );
97 
98  }
99 
100  m_num_written ++;
101  buffer.write( val_ );
102 
103  request_update();
104 }
105 
106 template <typename T>
107 inline
108 bool
109 tlm_fifo<T>::nb_put( const T& val_ )
110 {
111 
112  if( is_full() ) {
113  return false;
114  }
115 
116  if( buffer.is_full() ) {
117 
118  buffer.resize( buffer.size() * 2 );
119 
120  }
121 
122  m_num_written ++;
123  buffer.write( val_ );
124  request_update();
125 
126  return true;
127 }
128 
129 template < typename T >
130 inline
131 bool
133 
134  return !is_full();
135 
136 }
137 
138 } // namespace tlm
139 
140 #endif
bool nb_can_get(tlm_tag< T > *=0) const
T get(tlm_tag< T > *=0)
bool nb_can_put(tlm_tag< T > *=0) const
void put(const T &)
bool nb_put(const T &)
bool nb_get(T &)
void SC_API wait(int, sc_simcontext *)