|
0
|
1 //========================================================================== |
|
|
2 // |
|
2
|
3 // memvar.cxx |
|
0
|
4 // |
|
2
|
5 // Memory pool with variable block class declarations |
|
0
|
6 // |
|
|
7 //========================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
2
|
32 // Author(s): dsm |
|
|
33 // Contributors: dsm |
|
|
34 // Date: 1998-05-22 |
|
|
35 // Description: |
|
|
36 // Usage: #include <cyg/kernel/memvar.hxx> |
|
|
37 // |
|
0
|
38 // |
|
|
39 //####DESCRIPTIONEND#### |
|
|
40 // |
|
|
41 //========================================================================== |
|
|
42 |
|
|
43 #include <pkgconf/kernel.h> |
|
|
44 |
|
|
45 #include <cyg/kernel/ktypes.h> // base kernel types |
|
|
46 #include <cyg/infra/cyg_trac.h> // tracing macros |
|
|
47 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
48 #include <cyg/kernel/instrmnt.h> // instrumentation |
|
|
49 |
|
|
50 #include <cyg/kernel/memvar.hxx> |
|
|
51 |
|
|
52 // implementation that we want to make concrete |
|
|
53 #ifdef CYGIMP_MEM_USE_MEMPOOLT_PLAIN |
|
|
54 #include <cyg/kernel/mempoolt.inl> // kernel safe mempool template |
|
|
55 #else |
|
|
56 #include <cyg/kernel/mempolt2.inl> // kernel safe mempool template |
|
|
57 #endif |
|
|
58 |
|
|
59 #include <cyg/kernel/mvarimpl.inl> // mem pool implementation |
|
|
60 |
|
|
61 // ------------------------------------------------------------------------- |
|
|
62 // debugging/assert function |
|
|
63 |
|
|
64 #ifdef CYGDBG_USE_ASSERTS |
|
|
65 cyg_bool |
|
2
|
66 Cyg_Mempool_Variable::check_this(cyg_assert_class_zeal zeal) const |
|
0
|
67 { |
|
|
68 CYG_REPORT_FUNCTION(); |
|
|
69 // check that we have a non-NULL pointer first |
|
|
70 if( this == NULL ) return false; |
|
|
71 return mypool.check_this( zeal ); |
|
|
72 } |
|
|
73 #endif |
|
|
74 |
|
|
75 // ------------------------------------------------------------------------- |
|
|
76 // Constructor: gives the base and size of the arena in which memory is |
|
|
77 // to be carved out |
|
|
78 Cyg_Mempool_Variable::Cyg_Mempool_Variable( |
|
|
79 cyg_uint8 *base, |
|
|
80 cyg_int32 size) |
|
|
81 : mypool( base, size, (CYG_ADDRWORD)4 ) |
|
|
82 { |
|
|
83 } |
|
|
84 |
|
|
85 // Destructor |
|
|
86 Cyg_Mempool_Variable::~Cyg_Mempool_Variable() |
|
|
87 { |
|
|
88 } |
|
|
89 |
|
|
90 // ------------------------------------------------------------------------- |
|
|
91 // get some memory; wait if none available |
|
|
92 cyg_uint8 * |
|
|
93 Cyg_Mempool_Variable::alloc(cyg_int32 size) |
|
|
94 { |
|
|
95 return mypool.alloc( size ); |
|
|
96 } |
|
|
97 |
|
|
98 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
|
99 // get some memory with a timeout |
|
|
100 cyg_uint8 * |
|
|
101 Cyg_Mempool_Variable::alloc(cyg_int32 size, cyg_tick_count delay_timeout ) |
|
|
102 { |
|
|
103 return mypool.alloc( size , delay_timeout ); |
|
|
104 } |
|
|
105 #endif |
|
|
106 |
|
|
107 // get some memory, return NULL if none available |
|
|
108 cyg_uint8 * |
|
|
109 Cyg_Mempool_Variable::try_alloc(cyg_int32 size) |
|
|
110 { |
|
|
111 return mypool.try_alloc( size ); |
|
|
112 } |
|
|
113 |
|
|
114 // free the memory back to the pool |
|
|
115 cyg_bool |
|
|
116 Cyg_Mempool_Variable::free( cyg_uint8 *p, cyg_int32 size ) |
|
|
117 { |
|
|
118 return mypool.free( p, size ); |
|
|
119 } |
|
|
120 |
|
|
121 // is anyone waiting for memory? |
|
|
122 cyg_bool |
|
|
123 Cyg_Mempool_Variable::waiting() |
|
|
124 { |
|
|
125 return mypool.waiting(); |
|
|
126 } |
|
|
127 |
|
|
128 // read the fixed allocation size (will be -1 as variable) |
|
|
129 cyg_int32 |
|
|
130 Cyg_Mempool_Variable::get_blocksize() |
|
|
131 { |
|
|
132 return mypool.get_blocksize(); |
|
|
133 } |
|
|
134 |
|
|
135 // these two are obvious and generic |
|
|
136 cyg_int32 |
|
|
137 Cyg_Mempool_Variable::get_totalmem() { |
|
|
138 return mypool.get_totalmem(); |
|
|
139 } |
|
|
140 cyg_int32 |
|
|
141 Cyg_Mempool_Variable::get_freemem() { |
|
|
142 return mypool.get_freemem(); |
|
|
143 } |
|
|
144 |
|
|
145 // get information about the construction parameters for external |
|
|
146 // freeing after the destruction of the holding object |
|
|
147 void |
|
|
148 Cyg_Mempool_Variable::get_arena( |
|
|
149 cyg_uint8 * &base, cyg_int32 &size, CYG_ADDRWORD &maxfree ) |
|
|
150 { |
|
|
151 mypool.get_arena( base, size, maxfree ); |
|
|
152 } |
|
|
153 |
|
|
154 // Return the size of the memory allocation (previously returned |
|
|
155 // by alloc() or try_alloc() ) at ptr. Returns -1 if not found |
|
|
156 cyg_int32 |
|
|
157 Cyg_Mempool_Variable::get_allocation_size( cyg_uint8 *ptr ) |
|
|
158 { |
|
|
159 return mypool.get_allocation_size( ptr ); |
|
|
160 } |
|
|
161 |
|
|
162 // ------------------------------------------------------------------------- |
|
|
163 |
|
|
164 // End of memvar.cxx |