1 |
786 |
skrzyp |
#ifndef CYGONCE_MEMALLOC_MVARIMPL_HXX
|
2 |
|
|
#define CYGONCE_MEMALLOC_MVARIMPL_HXX
|
3 |
|
|
|
4 |
|
|
//==========================================================================
|
5 |
|
|
//
|
6 |
|
|
// mvarimpl.hxx
|
7 |
|
|
//
|
8 |
|
|
// Memory pool with variable block class declarations
|
9 |
|
|
//
|
10 |
|
|
//==========================================================================
|
11 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
12 |
|
|
// -------------------------------------------
|
13 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
14 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
15 |
|
|
//
|
16 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
17 |
|
|
// the terms of the GNU General Public License as published by the Free
|
18 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
19 |
|
|
// version.
|
20 |
|
|
//
|
21 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
22 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
23 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
24 |
|
|
// for more details.
|
25 |
|
|
//
|
26 |
|
|
// You should have received a copy of the GNU General Public License
|
27 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
28 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
29 |
|
|
//
|
30 |
|
|
// As a special exception, if other files instantiate templates or use
|
31 |
|
|
// macros or inline functions from this file, or you compile this file
|
32 |
|
|
// and link it with other works to produce a work based on this file,
|
33 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
34 |
|
|
// the GNU General Public License. However the source code for this file
|
35 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
36 |
|
|
// General Public License v2.
|
37 |
|
|
//
|
38 |
|
|
// This exception does not invalidate any other reasons why a work based
|
39 |
|
|
// on this file might be covered by the GNU General Public License.
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
//==========================================================================
|
43 |
|
|
//#####DESCRIPTIONBEGIN####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): dsm, jlarmour
|
46 |
|
|
// Contributors:
|
47 |
|
|
// Date: 2000-06-12
|
48 |
|
|
// Purpose: Define Mvarimpl class interface
|
49 |
|
|
// Description: Inline class for constructing a variable block allocator
|
50 |
|
|
// Usage: #include
|
51 |
|
|
//
|
52 |
|
|
//
|
53 |
|
|
//####DESCRIPTIONEND####
|
54 |
|
|
//
|
55 |
|
|
//==========================================================================
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
#include
|
59 |
|
|
#include
|
60 |
|
|
#include // Common memory allocator infra
|
61 |
|
|
|
62 |
|
|
class Cyg_Mempool_Variable_Implementation {
|
63 |
|
|
protected:
|
64 |
|
|
// these constructors are explicitly disallowed
|
65 |
|
|
Cyg_Mempool_Variable_Implementation() {};
|
66 |
|
|
// Cyg_Mempool_Variable_Implementation( Cyg_Mempool_Variable_Implementation &ref )
|
67 |
|
|
// {};
|
68 |
|
|
Cyg_Mempool_Variable_Implementation &
|
69 |
|
|
operator=( Cyg_Mempool_Variable_Implementation &ref )
|
70 |
|
|
{ return ref; };
|
71 |
|
|
|
72 |
|
|
struct memdq {
|
73 |
|
|
struct memdq *prev, *next;
|
74 |
|
|
cyg_int32 size;
|
75 |
|
|
};
|
76 |
|
|
|
77 |
|
|
struct memdq head;
|
78 |
|
|
cyg_uint8 *obase;
|
79 |
|
|
cyg_int32 osize;
|
80 |
|
|
cyg_uint8 *bottom;
|
81 |
|
|
cyg_uint8 *top;
|
82 |
|
|
cyg_int32 alignment;
|
83 |
|
|
cyg_int32 freemem;
|
84 |
|
|
|
85 |
|
|
// round up size passed to alloc/free to a size that will be used
|
86 |
|
|
// for allocation
|
87 |
|
|
cyg_int32
|
88 |
|
|
roundup(cyg_int32 size);
|
89 |
|
|
|
90 |
|
|
struct memdq *
|
91 |
|
|
addr2memdq( cyg_uint8 *addr );
|
92 |
|
|
|
93 |
|
|
struct memdq *
|
94 |
|
|
alloc2memdq( cyg_uint8 *addr );
|
95 |
|
|
|
96 |
|
|
cyg_uint8 *
|
97 |
|
|
memdq2alloc( struct memdq *dq );
|
98 |
|
|
|
99 |
|
|
void
|
100 |
|
|
insert_free_block( struct memdq *freedq );
|
101 |
|
|
|
102 |
|
|
public:
|
103 |
|
|
// THIS is the public API of memory pools generally that can have the
|
104 |
|
|
// kernel oriented thread-safe package layer atop.
|
105 |
|
|
|
106 |
|
|
// Constructor: gives the base and size of the arena in which memory is
|
107 |
|
|
// to be carved out.
|
108 |
|
|
Cyg_Mempool_Variable_Implementation(
|
109 |
|
|
cyg_uint8 * /* base */,
|
110 |
|
|
cyg_int32 /* size */,
|
111 |
|
|
CYG_ADDRWORD /* alignment */ = 8 );
|
112 |
|
|
|
113 |
|
|
// Destructor
|
114 |
|
|
~Cyg_Mempool_Variable_Implementation();
|
115 |
|
|
|
116 |
|
|
// get size bytes of memory
|
117 |
|
|
cyg_uint8 *
|
118 |
|
|
try_alloc( cyg_int32 /* size */ );
|
119 |
|
|
|
120 |
|
|
// resize existing allocation, if oldsize is non-NULL, previous
|
121 |
|
|
// allocation size is placed into it. If previous size not available,
|
122 |
|
|
// it is set to 0. NB previous allocation size may have been rounded up.
|
123 |
|
|
// Occasionally the allocation can be adjusted *backwards* as well as,
|
124 |
|
|
// or instead of forwards, therefore the address of the resized
|
125 |
|
|
// allocation is returned, or NULL if no resizing was possible.
|
126 |
|
|
// Note that this differs from ::realloc() in that no attempt is
|
127 |
|
|
// made to call malloc() if resizing is not possible - that is left
|
128 |
|
|
// to higher layers. The data is copied from old to new though.
|
129 |
|
|
// The effects of alloc_ptr==NULL or newsize==0 are undefined
|
130 |
|
|
cyg_uint8 *
|
131 |
|
|
resize_alloc( cyg_uint8 *alloc_ptr, cyg_int32 newsize,
|
132 |
|
|
cyg_int32 *oldsize );
|
133 |
|
|
|
134 |
|
|
// free size bytes of memory back to the pool
|
135 |
|
|
// returns true on success
|
136 |
|
|
cyg_bool
|
137 |
|
|
free( cyg_uint8 * /* ptr */,
|
138 |
|
|
cyg_int32 /* size */ );
|
139 |
|
|
|
140 |
|
|
// Get memory pool status
|
141 |
|
|
// flags is a bitmask of requested fields to fill in. The flags are
|
142 |
|
|
// defined in common.hxx
|
143 |
|
|
void
|
144 |
|
|
get_status( cyg_mempool_status_flag_t /* flags */,
|
145 |
|
|
Cyg_Mempool_Status & /* status */ );
|
146 |
|
|
|
147 |
|
|
};
|
148 |
|
|
|
149 |
|
|
#include
|
150 |
|
|
|
151 |
|
|
// -------------------------------------------------------------------------
|
152 |
|
|
#endif // ifndef CYGONCE_MEMALLOC_MVARIMPL_HXX
|
153 |
|
|
// EOF mvarimpl.hxx
|