1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// memvar.cxx
|
4 |
|
|
//
|
5 |
|
|
// Memory pool with variable block 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): dsm, jlarmour
|
44 |
|
|
// Contributors:
|
45 |
|
|
// Date: 2000-06-12
|
46 |
|
|
// Description:
|
47 |
|
|
// Usage: #include <cyg/memalloc/memvar.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_VARIABLE_THREADAWARE
|
74 |
|
|
# include <cyg/memalloc/mempolt2.hxx> // kernel safe mempool template
|
75 |
|
|
#endif
|
76 |
|
|
|
77 |
|
|
#include <cyg/memalloc/memvar.hxx>
|
78 |
|
|
#include <cyg/memalloc/mvarimpl.hxx> // implementation of a variable 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_Variable::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_VARIABLE_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_Variable::Cyg_Mempool_Variable(
|
105 |
|
|
cyg_uint8 *base,
|
106 |
|
|
cyg_int32 size,
|
107 |
|
|
cyg_int32 alignment)
|
108 |
|
|
: mypool( base, size, (CYG_ADDRWORD)alignment )
|
109 |
|
|
{
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
// Destructor
|
113 |
|
|
Cyg_Mempool_Variable::~Cyg_Mempool_Variable()
|
114 |
|
|
{
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
// -------------------------------------------------------------------------
|
118 |
|
|
// get some memory; wait if none available
|
119 |
|
|
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_VARIABLE_THREADAWARE
|
120 |
|
|
cyg_uint8 *
|
121 |
|
|
Cyg_Mempool_Variable::alloc(cyg_int32 size)
|
122 |
|
|
{
|
123 |
|
|
return mypool.alloc( size );
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
# ifdef CYGFUN_KERNEL_THREADS_TIMER
|
127 |
|
|
// get some memory with a timeout
|
128 |
|
|
cyg_uint8 *
|
129 |
|
|
Cyg_Mempool_Variable::alloc(cyg_int32 size, cyg_tick_count delay_timeout)
|
130 |
|
|
{
|
131 |
|
|
return mypool.alloc( size , delay_timeout );
|
132 |
|
|
}
|
133 |
|
|
# endif
|
134 |
|
|
#endif
|
135 |
|
|
|
136 |
|
|
// get some memory, return NULL if none available
|
137 |
|
|
cyg_uint8 *
|
138 |
|
|
Cyg_Mempool_Variable::try_alloc(cyg_int32 size)
|
139 |
|
|
{
|
140 |
|
|
return mypool.try_alloc( size );
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
// resize existing allocation, if oldsize is non-NULL, previous
|
144 |
|
|
// allocation size is placed into it. If previous size not available,
|
145 |
|
|
// it is set to 0. NB previous allocation size may have been rounded up.
|
146 |
|
|
// Occasionally the allocation can be adjusted *backwards* as well as,
|
147 |
|
|
// or instead of forwards, therefore the address of the resized
|
148 |
|
|
// allocation is returned, or NULL if no resizing was possible.
|
149 |
|
|
// Note that this differs from ::realloc() in that no attempt is
|
150 |
|
|
// made to call malloc() if resizing is not possible - that is left
|
151 |
|
|
// to higher layers. The data is copied from old to new though.
|
152 |
|
|
// The effects of alloc_ptr==NULL or newsize==0 are undefined
|
153 |
|
|
cyg_uint8 *
|
154 |
|
|
Cyg_Mempool_Variable::resize_alloc( cyg_uint8 *alloc_ptr, cyg_int32 newsize,
|
155 |
|
|
cyg_int32 *oldsize )
|
156 |
|
|
{
|
157 |
|
|
return mypool.resize_alloc( alloc_ptr, newsize, oldsize );
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
// free the memory back to the pool
|
161 |
|
|
cyg_bool
|
162 |
|
|
Cyg_Mempool_Variable::free( cyg_uint8 *p, cyg_int32 size )
|
163 |
|
|
{
|
164 |
|
|
return mypool.free( p, size );
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
// Get memory pool status
|
168 |
|
|
void
|
169 |
|
|
Cyg_Mempool_Variable::get_status( cyg_mempool_status_flag_t flags,
|
170 |
|
|
Cyg_Mempool_Status &status )
|
171 |
|
|
{
|
172 |
|
|
// set to 0 - if there's anything really waiting, it will be set to
|
173 |
|
|
// 1 later
|
174 |
|
|
status.waiting = 0;
|
175 |
|
|
|
176 |
|
|
return mypool.get_status( flags, status );
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
// -------------------------------------------------------------------------
|
180 |
|
|
|
181 |
|
|
// End of memvar.cxx
|