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