gem5  v20.1.0.0
fifo_put_get.hh
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_CORE_1_REQ_RSP_CHANNELS_FIFO_FIFO_PUT_GET_HH__
21 #define __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_FIFO_PUT_GET_HH__
22 
23 namespace tlm
24 {
25 
26 // Get interface.
27 template <typename T>
28 inline T
29 tlm_fifo<T>::get(tlm_tag<T> *)
30 {
31  while (is_empty()) {
32  wait(m_data_written_event);
33  }
34 
35  m_num_read++;
36  request_update();
37 
38  return buffer.read();
39 }
40 
41 // Non-blocking read.
42 template <typename T>
43 inline bool
44 tlm_fifo<T>::nb_get(T &val_)
45 {
46  if (is_empty()) {
47  return false;
48  }
49 
50  m_num_read++;
51  request_update();
52 
53  val_ = buffer.read();
54 
55  return true;
56 }
57 
58 template <typename T>
59 inline bool
60 tlm_fifo<T>::nb_can_get(tlm_tag<T> *) const
61 {
62  return !is_empty();
63 }
64 
65 
66 // Put interface.
67 template <typename T>
68 inline void
69 tlm_fifo<T>::put(const T &val_)
70 {
71  while (is_full()) {
72  wait(m_data_read_event);
73  }
74 
75  if (buffer.is_full()) {
76  buffer.resize(buffer.size() * 2);
77  }
78 
79  m_num_written++;
80  buffer.write(val_);
81 
82  request_update();
83 }
84 
85 template <typename T>
86 inline bool
87 tlm_fifo<T>::nb_put(const T &val_)
88 {
89  if (is_full()) {
90  return false;
91  }
92 
93  if (buffer.is_full()) {
94  buffer.resize(buffer.size() * 2);
95  }
96 
97  m_num_written++;
98  buffer.write(val_);
99  request_update();
100 
101  return true;
102 }
103 
104 template <typename T>
105 inline bool
107 {
108  return !is_full();
109 }
110 
111 } // namespace tlm
112 
113 #endif /* __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_FIFO_PUT_GET_HH__ */
tlm::tlm_fifo::nb_put
bool nb_put(const T &)
Definition: fifo_put_get.hh:104
tlm::tlm_fifo::nb_can_put
bool nb_can_put(tlm_tag< T > *=nullptr) const
Definition: fifo_put_get.hh:123
tlm::tlm_fifo::get
T get(tlm_tag< T > *=nullptr)
Definition: fifo_put_get.hh:46
tlm::tlm_fifo::nb_can_get
bool nb_can_get(tlm_tag< T > *=nullptr) const
Definition: fifo_put_get.hh:77
tlm::tlm_fifo::nb_get
bool nb_get(T &)
Definition: fifo_put_get.hh:61
tlm::tlm_tag
Definition: tag.hh:44
tlm
Definition: analysis_fifo.hh:27
sc_core::wait
void wait()
Definition: sc_module.cc:653
tlm::tlm_fifo::put
void put(const T &)
Definition: fifo_put_get.hh:86

Generated on Wed Sep 30 2020 14:02:16 for gem5 by doxygen 1.8.17