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
23namespace tlm {
24
25/******************************************************************
26//
27// get interface
28//
29******************************************************************/
30
31template <typename T>
32inline
33T
34tlm_fifo<T>::get( tlm_tag<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
50template <typename T>
51inline
52bool
53tlm_fifo<T>::nb_get( T& val_ )
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
69template <typename T>
70inline
71bool
72tlm_fifo<T>::nb_can_get( tlm_tag<T> * ) const {
73
74  return !is_empty();
75
76}
77
78
79/******************************************************************
80//
81// put interface
82//
83******************************************************************/
84
85template <typename T>
86inline
87void
88tlm_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
106template <typename T>
107inline
108bool
109tlm_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
129template < typename T >
130inline
131bool
132tlm_fifo<T>::nb_can_put( tlm_tag<T> * ) const {
133
134  return !is_full();
135
136}
137
138} // namespace tlm
139
140#endif
141