fifo_put_get.hh revision 13521:74fa3ac44057
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 23namespace tlm 24{ 25 26// Get interface. 27template <typename T> 28inline T 29tlm_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. 42template <typename T> 43inline bool 44tlm_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 58template <typename T> 59inline bool 60tlm_fifo<T>::nb_can_get(tlm_tag<T> *) const 61{ 62 return !is_empty(); 63} 64 65 66// Put interface. 67template <typename T> 68inline void 69tlm_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 85template <typename T> 86inline bool 87tlm_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 104template <typename T> 105inline bool 106tlm_fifo<T>::nb_can_put(tlm_tag<T> *) const 107{ 108 return !is_full(); 109} 110 111} // namespace tlm 112 113#endif /* __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_FIFO_PUT_GET_HH__ */ 114