1 |
1254 |
phoenix |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// sepmeta.cxx
|
4 |
|
|
//
|
5 |
|
|
// Variable block memory pool with separated metadata class declarations
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//==========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): jlarmour
|
44 |
|
|
// Contributors:
|
45 |
|
|
// Date: 2001-06-28
|
46 |
|
|
// Description:
|
47 |
|
|
// Usage: #include <cyg/memalloc/sepmeta.hxx>
|
48 |
|
|
//
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//==========================================================================
|
53 |
|
|
|
54 |
|
|
// CONFIGURATION
|
55 |
|
|
|
56 |
|
|
#include <pkgconf/memalloc.h>
|
57 |
|
|
#include <pkgconf/system.h>
|
58 |
|
|
#ifdef CYGPKG_KERNEL
|
59 |
|
|
# include <pkgconf/kernel.h>
|
60 |
|
|
#endif
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
// INCLUDES
|
64 |
|
|
|
65 |
|
|
#include <cyg/infra/cyg_type.h> // types
|
66 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
67 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
68 |
|
|
|
69 |
|
|
#ifdef CYGFUN_KERNEL_THREADS_TIMER
|
70 |
|
|
# include <cyg/kernel/ktypes.h> // cyg_tick_count
|
71 |
|
|
#endif
|
72 |
|
|
|
73 |
|
|
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_SEPMETA_THREADAWARE
|
74 |
|
|
# include <cyg/memalloc/mempolt2.hxx> // kernel safe mempool template
|
75 |
|
|
#endif
|
76 |
|
|
|
77 |
|
|
#include <cyg/memalloc/sepmeta.hxx>
|
78 |
|
|
#include <cyg/memalloc/sepmetaimpl.hxx>// implementation of this mem pool
|
79 |
|
|
#include <cyg/memalloc/common.hxx> // Common memory allocator infra
|
80 |
|
|
|
81 |
|
|
// FUNCTIONS
|
82 |
|
|
|
83 |
|
|
// -------------------------------------------------------------------------
|
84 |
|
|
// debugging/assert function
|
85 |
|
|
|
86 |
|
|
#ifdef CYGDBG_USE_ASSERTS
|
87 |
|
|
cyg_bool
|
88 |
|
|
Cyg_Mempool_Sepmeta::check_this(cyg_assert_class_zeal zeal) const
|
89 |
|
|
{
|
90 |
|
|
CYG_REPORT_FUNCTION();
|
91 |
|
|
// check that we have a non-NULL pointer first
|
92 |
|
|
if( this == NULL ) return false;
|
93 |
|
|
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_SEPMETA_THREADAWARE
|
94 |
|
|
return mypool.check_this( zeal );
|
95 |
|
|
#else
|
96 |
|
|
return true;
|
97 |
|
|
#endif
|
98 |
|
|
}
|
99 |
|
|
#endif
|
100 |
|
|
|
101 |
|
|
// -------------------------------------------------------------------------
|
102 |
|
|
// Constructor: gives the base and size of the arena in which memory is
|
103 |
|
|
// to be carved out
|
104 |
|
|
Cyg_Mempool_Sepmeta::Cyg_Mempool_Sepmeta(
|
105 |
|
|
cyg_uint8 *base,
|
106 |
|
|
cyg_int32 size,
|
107 |
|
|
cyg_int32 alignment,
|
108 |
|
|
cyg_uint8 *metabase,
|
109 |
|
|
cyg_uint32 metasize)
|
110 |
|
|
: args(alignment, metabase, metasize),
|
111 |
|
|
mypool( base, size, (CYG_ADDRWORD)&args )
|
112 |
|
|
{
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
// Destructor
|
116 |
|
|
Cyg_Mempool_Sepmeta::~Cyg_Mempool_Sepmeta()
|
117 |
|
|
{
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
// -------------------------------------------------------------------------
|
121 |
|
|
// get some memory; wait if none available
|
122 |
|
|
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_SEPMETA_THREADAWARE
|
123 |
|
|
cyg_uint8 *
|
124 |
|
|
Cyg_Mempool_Sepmeta::alloc(cyg_int32 size)
|
125 |
|
|
{
|
126 |
|
|
return mypool.alloc( size );
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
# ifdef CYGFUN_KERNEL_THREADS_TIMER
|
130 |
|
|
// get some memory with a timeout
|
131 |
|
|
cyg_uint8 *
|
132 |
|
|
Cyg_Mempool_Sepmeta::alloc(cyg_int32 size, cyg_tick_count delay_timeout)
|
133 |
|
|
{
|
134 |
|
|
return mypool.alloc( size , delay_timeout );
|
135 |
|
|
}
|
136 |
|
|
# endif
|
137 |
|
|
#endif
|
138 |
|
|
|
139 |
|
|
// get some memory, return NULL if none available
|
140 |
|
|
cyg_uint8 *
|
141 |
|
|
Cyg_Mempool_Sepmeta::try_alloc(cyg_int32 size)
|
142 |
|
|
{
|
143 |
|
|
return mypool.try_alloc( size );
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
// resize existing allocation, if oldsize is non-NULL, previous
|
147 |
|
|
// allocation size is placed into it. If previous size not available,
|
148 |
|
|
// it is set to 0. NB previous allocation size may have been rounded up.
|
149 |
|
|
// Occasionally the allocation can be adjusted *backwards* as well as,
|
150 |
|
|
// or instead of forwards, therefore the address of the resized
|
151 |
|
|
// allocation is returned, or NULL if no resizing was possible.
|
152 |
|
|
// Note that this differs from ::realloc() in that no attempt is
|
153 |
|
|
// made to call malloc() if resizing is not possible - that is left
|
154 |
|
|
// to higher layers. The data is copied from old to new though.
|
155 |
|
|
// The effects of alloc_ptr==NULL or newsize==0 are undefined
|
156 |
|
|
cyg_uint8 *
|
157 |
|
|
Cyg_Mempool_Sepmeta::resize_alloc( cyg_uint8 *alloc_ptr, cyg_int32 newsize,
|
158 |
|
|
cyg_int32 *oldsize )
|
159 |
|
|
{
|
160 |
|
|
return mypool.resize_alloc( alloc_ptr, newsize, oldsize );
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
// free the memory back to the pool
|
164 |
|
|
cyg_bool
|
165 |
|
|
Cyg_Mempool_Sepmeta::free( cyg_uint8 *p, cyg_int32 size )
|
166 |
|
|
{
|
167 |
|
|
return mypool.free( p, size );
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
// Get memory pool status
|
171 |
|
|
void
|
172 |
|
|
Cyg_Mempool_Sepmeta::get_status( cyg_mempool_status_flag_t flags,
|
173 |
|
|
Cyg_Mempool_Status &status )
|
174 |
|
|
{
|
175 |
|
|
// set to 0 - if there's anything really waiting, it will be set to
|
176 |
|
|
// 1 later
|
177 |
|
|
status.waiting = 0;
|
178 |
|
|
|
179 |
|
|
return mypool.get_status( flags, status );
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
// -------------------------------------------------------------------------
|
183 |
|
|
|
184 |
|
|
// End of sepmeta.cxx
|