SystemC
3.0.0
Accellera SystemC proof-of-concept library
sysc
utils
sc_temporary.h
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_temporary.h -- Temporary value pool classes.
23
24
Original Author: Andy Goodrich, Forte Design Systems, Inc.
25
26
CHANGE LOG AT END OF FILE
27
*****************************************************************************/
28
29
#ifndef SC_TEMPORARY_H
30
#define SC_TEMPORARY_H
31
#include "
sysc/kernel/sc_cmnhdr.h
"
32
33
#include <cstddef>
// std::size_t
34
35
namespace
sc_core
{
36
37
//------------------------------------------------------------------------------
38
// sc_vpool<T> - CLASS MANAGING A TEMPORARY VECTOR OF CLASS T INSTANCES
39
//
40
// This class implements a fixed pool of objects contained in a vector. These
41
// objects are allocated via the allocate() method. An index, m_pool_i,
42
// indicates the next object to be allocated. The vector is a power of 2 in
43
// size, and this fact is used to wrap the list when m_pool_i reaches the
44
// end of the vector.
45
//
46
// sc_vpool( int log2, T* pool_p=0 )
47
// This is the object instance constructor for this class. It configures
48
// the object to manage a vector of 2**log2 entries. If a vector is
49
// not supplied one will be allocated.
50
// log2 = the log base two of the size of the vector.
51
// pool_p -> vector of 2**log2 entries to be managed or 0.
52
//
53
// ~sc_vpool()
54
// This is the object instance destructor for this class. It frees the
55
// block of storage which was being managed.
56
//
57
// T* allocate()
58
// This method returns the address of the next entry in the vector, m_pool_p,
59
// pointed to by the index, m_pool_i, and updates that index. The index
60
// update consists of adding 1 to m_pool_i and masking it by m_wrap.
61
//
62
// void reset()
63
// This method resets the allocation index, m_pool_i, to point to the start
64
// of the vector of objects under management. This call is not usually made
65
// since there are a fixed number of entries and the index wraps. However,
66
// for diagnostics tests it is convenient to be able to reset to the start
67
// of the vector.
68
//
69
// int size()
70
// This method returns the number of object instances contained in the
71
// vector being managed by this object instance.
72
//------------------------------------------------------------------------------
73
template
<
class
T>
74
class
sc_vpool
{
75
protected
:
76
std::size_t
m_pool_i
;
// Index of next entry to m_pool_m to provide.
77
T*
m_pool_p
;
// Vector of temporaries.
78
std::size_t
m_wrap
;
// Mask to wrap vector index.
79
80
public
:
81
inline
sc_vpool
(
int
log2, T* pool_p=0 );
82
inline
~sc_vpool
();
83
inline
T*
allocate
();
84
inline
void
reset
();
85
inline
std::size_t
size
();
86
};
87
88
template
<
class
T>
sc_vpool<T>::sc_vpool
(
int
log2, T* pool_p )
89
: m_pool_i( 0 )
90
, m_pool_p( pool_p ? pool_p : new T[static_cast<std::size_t>(1) << log2] )
91
, m_wrap( ~(static_cast<std::size_t>(-1) << log2) )
92
{
93
// if ( log2 > 32 ) SC_REPORT_ERROR(SC_ID_POOL_SIZE_, "");
94
}
95
96
template
<
class
T>
sc_vpool<T>::~sc_vpool
()
97
{
98
// delete [] m_pool_p;
99
}
100
101
template
<
class
T> T*
sc_vpool<T>::allocate
()
102
{
103
T* result_p;
// Entry to return.
104
105
result_p = &m_pool_p[m_pool_i];
106
m_pool_i = (m_pool_i + 1) & m_wrap;
107
return
result_p;
108
}
109
110
template
<
class
T>
void
sc_vpool<T>::reset
()
111
{
112
m_pool_i = 0;
113
}
114
115
template
<
class
T> std::size_t
sc_vpool<T>::size
()
116
{
117
return
m_wrap + 1;
118
}
119
120
}
// namespace sc_core
121
122
// $Log: sc_temporary.h,v $
123
// Revision 1.4 2011/08/26 20:46:19 acg
124
// Andy Goodrich: moved the modification log to the end of the file to
125
// eliminate source line number skew when check-ins are done.
126
//
127
// Revision 1.3 2011/08/24 22:05:56 acg
128
// Torsten Maehne: initialization changes to remove warnings.
129
//
130
// Revision 1.2 2011/02/18 20:38:44 acg
131
// Andy Goodrich: Updated Copyright notice.
132
//
133
// Revision 1.1.1.1 2006/12/15 20:20:06 acg
134
// SystemC 2.3
135
//
136
// Revision 1.3 2006/01/13 18:53:11 acg
137
// Andy Goodrich: Added $Log command so that CVS comments are reproduced in
138
// the source.
139
//
140
141
#endif
// SC_TEMPORARY_H
sc_cmnhdr.h
sc_core
Definition:
sc_buffer.h:36
sc_core::sc_vpool
Definition:
sc_temporary.h:74
sc_core::sc_vpool::m_pool_p
T * m_pool_p
Definition:
sc_temporary.h:77
sc_core::sc_vpool::m_wrap
std::size_t m_wrap
Definition:
sc_temporary.h:78
sc_core::sc_vpool::size
std::size_t size()
Definition:
sc_temporary.h:115
sc_core::sc_vpool::~sc_vpool
~sc_vpool()
Definition:
sc_temporary.h:96
sc_core::sc_vpool::reset
void reset()
Definition:
sc_temporary.h:110
sc_core::sc_vpool::sc_vpool
sc_vpool(int log2, T *pool_p=0)
Definition:
sc_temporary.h:88
sc_core::sc_vpool::allocate
T * allocate()
Definition:
sc_temporary.h:101
sc_core::sc_vpool::m_pool_i
std::size_t m_pool_i
Definition:
sc_temporary.h:76
Generated on Fri Aug 16 2024 16:36:34 for SystemC by
1.9.4