gem5
v20.1.0.0
systemc
ext
dt
fx
sc_context.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
/*****************************************************************************
21
22
sc_context.h -
23
24
Original Author: Martin Janssen, Synopsys, Inc.
25
26
*****************************************************************************/
27
28
/*****************************************************************************
29
30
MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31
changes you are making here.
32
33
Name, Affiliation, Date:
34
Description of Modification:
35
36
*****************************************************************************/
37
38
// $Log: sc_context.h,v $
39
// Revision 1.2 2011/08/24 22:05:43 acg
40
// Torsten Maehne: initialization changes to remove warnings.
41
//
42
// Revision 1.1.1.1 2006/12/15 20:20:04 acg
43
// SystemC 2.3
44
//
45
// Revision 1.5 2006/05/26 20:36:52 acg
46
// Andy Goodrich: added a using for sc_core::default_ptr_hash_fn to keep HP
47
// aCC happy.
48
//
49
// Revision 1.4 2006/03/21 00:00:31 acg
50
// Andy Goodrich: changed name of sc_get_current_process_base() to be
51
// sc_get_current_process_b() since its returning an sc_process_b instance.
52
//
53
// Revision 1.3 2006/01/13 18:53:57 acg
54
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
55
// the source.
56
//
57
58
#ifndef __SYSTEMC_EXT_DT_FX_SC_CONTEXT_HH__
59
#define __SYSTEMC_EXT_DT_FX_SC_CONTEXT_HH__
60
61
#include <map>
62
63
#include "../../core/sc_process_handle.hh"
64
#include "../../utils/sc_report_handler.hh"
65
#include "
messages.hh
"
66
67
namespace
sc_dt
68
{
69
70
// classes defined in this module
71
class
sc_without_context;
72
template
<
class
T>
73
class
sc_global;
74
template
<
class
T>
75
class
sc_context;
76
77
78
// ----------------------------------------------------------------------------
79
// CLASS : sc_without_context
80
//
81
// Empty class that is used for its type only.
82
// ----------------------------------------------------------------------------
83
84
class
sc_without_context {};
85
86
87
// ----------------------------------------------------------------------------
88
// TEMPLATE CLASS : sc_global
89
//
90
// Template global variable class; singleton; co-routine safe.
91
// ----------------------------------------------------------------------------
92
93
template
<
class
T>
94
class
sc_global
95
{
96
sc_global
();
97
void
update
();
98
99
public
:
100
static
sc_global<T>*
instance
();
101
const
T*&
value_ptr
();
102
103
private
:
104
static
sc_global<T>
*
m_instance
;
105
106
std::map<void *, const T *>
m_map
;
107
void
*
m_proc
;
// context (current process or NULL)
108
const
T *
m_value_ptr
;
109
};
110
111
112
// ----------------------------------------------------------------------------
113
// ENUM : sc_context_begin
114
//
115
// Enumeration of context begin options.
116
// ----------------------------------------------------------------------------
117
118
enum
sc_context_begin
119
{
120
SC_NOW
,
121
SC_LATER
122
};
123
124
125
// ----------------------------------------------------------------------------
126
// CLASS : sc_context
127
//
128
// Template context class; co-routine safe.
129
// ----------------------------------------------------------------------------
130
131
template
<
class
T>
132
class
sc_context
133
{
134
// disabled
135
sc_context
(
const
sc_context<T>
&);
136
void
*
operator
new
(std::size_t);
137
138
public
:
139
explicit
sc_context
(
const
T &,
sc_context_begin
=
SC_NOW
);
140
~sc_context
();
141
142
void
begin
();
143
void
end
();
144
145
static
const
T &
default_value
();
146
const
T &
value
()
const
;
147
148
private
:
149
sc_context
&
operator =
(
const
sc_context
&)
/* = delete */
;
150
151
const
T
m_value
;
152
const
T *&
m_def_value_ptr
;
153
const
T *
m_old_value_ptr
;
154
};
155
156
157
// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
158
159
// ----------------------------------------------------------------------------
160
// TEMPLATE CLASS : sc_global
161
//
162
// Template global variable class; singleton; co-routine safe.
163
// ----------------------------------------------------------------------------
164
165
template
<
class
T>
166
sc_global<T> *
sc_global<T>::m_instance
= 0;
167
168
template
<
class
T>
169
inline
sc_global<T>::sc_global
() : m_map(),
170
// use &m_instance as unique "non-process" key (NULL denotes 'sc_main'
171
// context)
172
m_proc(&m_instance), m_value_ptr(0)
173
{}
174
175
176
template
<
class
T>
177
inline
void
178
sc_global<T>::update()
179
{
180
void
*
p
= (
::sc_gem5::Process
*)
sc_core::sc_get_current_process_handle
();
181
if
(
p
!= m_proc) {
182
const
T *vp = m_map[
p
];
183
if
(vp == 0) {
184
vp =
new
T(
sc_without_context
());
185
m_map.emplace(
p
, vp);
186
}
187
m_proc =
p
;
188
m_value_ptr = vp;
189
}
190
}
191
192
193
template
<
class
T>
194
inline
sc_global<T> *
195
sc_global<T>::instance()
196
{
197
if
(m_instance == 0) {
198
m_instance =
new
sc_global<T>;
199
}
200
return
m_instance;
201
}
202
203
204
template
<
class
T>
205
inline
const
T *&
206
sc_global<T>::value_ptr
()
207
{
208
update();
209
return
m_value_ptr;
210
}
211
212
213
// ----------------------------------------------------------------------------
214
// CLASS : sc_context
215
//
216
// Template context class; co-routine safe.
217
// ----------------------------------------------------------------------------
218
219
template
<
class
T>
220
inline
sc_context<T>::sc_context
(
const
T &value_,
sc_context_begin
begin_) :
221
m_value(value_),
222
m_def_value_ptr(
sc_global
<T>::instance()->value_ptr()),
223
m_old_value_ptr(0)
224
{
225
if
(begin_ ==
SC_NOW
) {
226
m_old_value_ptr = m_def_value_ptr;
227
m_def_value_ptr = &m_value;
228
}
229
}
230
231
template
<
class
T>
232
inline
sc_context<T>::~sc_context
()
233
{
234
if
(m_old_value_ptr != 0) {
235
m_def_value_ptr = m_old_value_ptr;
236
m_old_value_ptr = 0;
237
}
238
}
239
240
241
template
<
class
T>
242
inline
void
243
sc_context<T>::begin
()
244
{
245
if
(m_old_value_ptr == 0) {
246
m_old_value_ptr = m_def_value_ptr;
247
m_def_value_ptr = &m_value;
248
}
else
{
249
SC_REPORT_ERROR
(
sc_core::SC_ID_CONTEXT_BEGIN_FAILED_
, 0);
250
}
251
}
252
253
template
<
class
T>
254
inline
void
255
sc_context<T>::end
()
256
{
257
if
(m_old_value_ptr != 0) {
258
m_def_value_ptr = m_old_value_ptr;
259
m_old_value_ptr = 0;
260
}
else
{
261
SC_REPORT_ERROR
(
sc_core::SC_ID_CONTEXT_END_FAILED_
, 0);
262
}
263
}
264
265
266
template
<
class
T>
267
inline
const
T &
268
sc_context<T>::default_value
()
269
{
270
return
*
sc_global<T>::instance
()->value_ptr();
271
}
272
273
template
<
class
T>
274
inline
const
T &
275
sc_context<T>::value
()
const
276
{
277
return
m_value;
278
}
279
280
}
// namespace sc_dt
281
282
#endif // __SYSTEMC_EXT_DT_FX_SC_CONTEXT_HH__
sc_dt::sc_global::update
void update()
Definition:
sc_context.hh:209
sc_dt::sc_context::m_value
const T m_value
Definition:
sc_context.hh:182
sc_dt
Definition:
sc_bit.cc:67
sc_dt::sc_context::~sc_context
~sc_context()
Definition:
sc_context.hh:263
sc_dt::sc_context::end
void end()
Definition:
sc_context.hh:286
sc_dt::sc_context::m_old_value_ptr
const T * m_old_value_ptr
Definition:
sc_context.hh:184
sc_dt::sc_global
Definition:
sc_context.hh:104
sc_dt::sc_global::m_proc
void * m_proc
Definition:
sc_context.hh:138
sc_dt::sc_global::m_instance
static sc_global< T > * m_instance
Definition:
sc_context.hh:135
sc_dt::sc_without_context
Definition:
sc_context.hh:115
sc_dt::sc_context::operator=
sc_context & operator=(const sc_context &)
sc_dt::sc_global::sc_global
sc_global()
Definition:
sc_context.hh:200
SC_REPORT_ERROR
#define SC_REPORT_ERROR(msg_type, msg)
Definition:
sc_report_handler.hh:127
sc_dt::sc_context_begin
sc_context_begin
Definition:
sc_context.hh:149
sc_dt::sc_global::value_ptr
const T *& value_ptr()
Definition:
sc_context.hh:237
sc_dt::SC_LATER
@ SC_LATER
Definition:
sc_context.hh:152
sc_gem5::Process
Definition:
process.hh:62
messages.hh
sc_dt::sc_global::m_map
std::map< void *, const T * > m_map
Definition:
sc_context.hh:137
sc_dt::sc_context::sc_context
sc_context(const sc_context< T > &)
sc_dt::sc_context::begin
void begin()
Definition:
sc_context.hh:274
sc_dt::sc_context::m_def_value_ptr
const T *& m_def_value_ptr
Definition:
sc_context.hh:183
sc_dt::SC_NOW
@ SC_NOW
Definition:
sc_context.hh:151
sc_dt::sc_context::default_value
static const T & default_value()
Definition:
sc_context.hh:299
sc_dt::sc_context::value
const T & value() const
Definition:
sc_context.hh:306
sc_core::SC_ID_CONTEXT_END_FAILED_
const char SC_ID_CONTEXT_END_FAILED_[]
Definition:
messages.cc:44
MipsISA::p
Bitfield< 0 > p
Definition:
pra_constants.hh:323
sc_dt::sc_global::m_value_ptr
const T * m_value_ptr
Definition:
sc_context.hh:139
sc_core::sc_get_current_process_handle
sc_process_handle sc_get_current_process_handle()
Definition:
sc_process_handle.cc:312
sc_dt::sc_global::instance
static sc_global< T > * instance()
Definition:
sc_context.hh:226
sc_dt::sc_context
Definition:
sc_context.hh:106
sc_core::SC_ID_CONTEXT_BEGIN_FAILED_
const char SC_ID_CONTEXT_BEGIN_FAILED_[]
Definition:
messages.cc:43
Generated on Wed Sep 30 2020 14:02:15 for gem5 by
doxygen
1.8.17