|
0
|
1 #ifndef CYGONCE_KERNEL_MFIXIMPL_HXX |
|
|
2 #define CYGONCE_KERNEL_MFIXIMPL_HXX |
|
|
3 |
|
|
4 //========================================================================== |
|
|
5 // |
|
|
6 // mfiximpl.hxx |
|
|
7 // |
|
|
8 // Memory pool with fixed block class declarations |
|
|
9 // |
|
|
10 //========================================================================== |
|
|
11 //####COPYRIGHTBEGIN#### |
|
|
12 // |
|
|
13 // ------------------------------------------- |
|
|
14 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
15 // Version 1.0 (the "License"); you may not use this file except in |
|
|
16 // compliance with the License. You may obtain a copy of the License at |
|
|
17 // http://sourceware.cygnus.com/ecos |
|
|
18 // |
|
|
19 // Software distributed under the License is distributed on an "AS IS" |
|
|
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
21 // License for the specific language governing rights and limitations under |
|
|
22 // the License. |
|
|
23 // |
|
|
24 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
25 // September 30, 1998. |
|
|
26 // |
|
|
27 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
|
28 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
29 // ------------------------------------------- |
|
|
30 // |
|
|
31 //####COPYRIGHTEND#### |
|
|
32 //========================================================================== |
|
|
33 //#####DESCRIPTIONBEGIN#### |
|
|
34 // |
|
|
35 // Author(s): hmt |
|
|
36 // Contributors: hmt |
|
|
37 // Date: 1998-03-23 |
|
|
38 // Purpose: Define Mfiximpl class interface |
|
|
39 // Description: Inline class for constructing a fixed block allocator |
|
|
40 // Usage: #include <cyg/kernel/mfiximpl.hxx> |
|
|
41 // |
|
|
42 // |
|
|
43 //####DESCRIPTIONEND#### |
|
|
44 // |
|
|
45 //========================================================================== |
|
|
46 |
|
|
47 #include <cyg/kernel/ktypes.h> |
|
|
48 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
49 #include <cyg/kernel/thread.hxx> |
|
|
50 |
|
|
51 class Cyg_Mempool_Fixed_Implementation { |
|
|
52 private: |
|
|
53 // these constructors are explicitly disallowed |
|
|
54 Cyg_Mempool_Fixed_Implementation() {}; |
|
|
55 // Cyg_Mempool_Fixed_Implementation( Cyg_Mempool_Fixed_Implementation &ref ) |
|
|
56 // {}; |
|
|
57 Cyg_Mempool_Fixed_Implementation & |
|
|
58 operator=( Cyg_Mempool_Fixed_Implementation &ref ) |
|
|
59 { return ref; }; |
|
|
60 |
|
|
61 private: |
|
|
62 cyg_uint32 *bitmap; |
|
|
63 cyg_int32 maptop; |
|
|
64 cyg_uint8 *mempool; |
|
|
65 cyg_int32 numblocks; |
|
|
66 cyg_int32 freeblocks; |
|
|
67 cyg_int32 blocksize; |
|
|
68 cyg_int32 firstfree; |
|
|
69 cyg_uint8 *top; |
|
|
70 |
|
|
71 public: |
|
|
72 // THIS is the public API of memory pools generally that can have the |
|
|
73 // kernel oriented thread-safe package layer atop. |
|
|
74 // |
|
|
75 // The kernel package is a template whose type parameter is one of |
|
|
76 // these. That is the reason there are superfluous parameters here and |
|
|
77 // more genereralization than might be expected in a fixed block |
|
|
78 // allocator. |
|
|
79 |
|
|
80 // Constructor: gives the base and size of the arena in which memory is |
|
|
81 // to be carved out, note that management structures are taken from the |
|
|
82 // same arena. The alloc_unit may be any other param in general; it |
|
|
83 // comes through from the outer constructor unchanged. |
|
|
84 Cyg_Mempool_Fixed_Implementation( |
|
|
85 cyg_uint8 *base, |
|
|
86 cyg_int32 size, |
|
|
87 CYG_ADDRWORD alloc_unit ); |
|
|
88 |
|
|
89 // Destructor |
|
|
90 ~Cyg_Mempool_Fixed_Implementation(); |
|
|
91 |
|
|
92 // get some memory; size is ignored in a fixed block allocator |
|
|
93 inline cyg_uint8 *alloc( cyg_int32 size ); |
|
|
94 |
|
|
95 // free the memory back to the pool; size ignored here |
|
|
96 inline cyg_bool free( cyg_uint8 *p, cyg_int32 size ); |
|
|
97 |
|
|
98 // if applicable: return -1 if not fixed size |
|
|
99 inline cyg_int32 get_blocksize() { return blocksize; } |
|
|
100 |
|
|
101 // these two are obvious and generic |
|
|
102 inline cyg_int32 get_totalmem() { return blocksize * numblocks; } |
|
|
103 inline cyg_int32 get_freemem() { return blocksize * freeblocks; } |
|
|
104 |
|
|
105 // get information about the construction parameters for external |
|
|
106 // freeing after the destruction of the holding object |
|
|
107 inline void get_arena( cyg_uint8 * &base, cyg_int32 &size, CYG_ADDRWORD &alloc ) |
|
|
108 { |
|
|
109 base = (cyg_uint8 *)bitmap; |
|
|
110 size = top - base; |
|
|
111 alloc = blocksize; |
|
|
112 } |
|
|
113 |
|
|
114 }; |
|
|
115 |
|
|
116 // ------------------------------------------------------------------------- |
|
|
117 #endif // ifndef CYGONCE_KERNEL_MFIXIMPL_HXX |
|
|
118 // EOF mfiximpl.hxx |