|
0
|
1 #ifndef CYGONCE_KERNEL_MEMPOOLT_HXX |
|
|
2 #define CYGONCE_KERNEL_MEMPOOLT_HXX |
|
|
3 |
|
|
4 //========================================================================== |
|
|
5 // |
|
|
6 // mempoolt.hxx |
|
|
7 // |
|
|
8 // Mempoolt (Memory pool template) 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-02-10 |
|
|
38 // Purpose: Define Mempoolt class interface |
|
|
39 |
|
|
40 // Description: The class defined here provides the APIs for thread-safe, |
|
|
41 // kernel-savvy memory managers; make a class with the |
|
|
42 // underlying allocator as the template parameter. |
|
|
43 // Usage: #include <cyg/kernel/mempoolt.hxx> |
|
|
44 // |
|
|
45 // |
|
|
46 //####DESCRIPTIONEND#### |
|
|
47 // |
|
|
48 //========================================================================== |
|
|
49 |
|
|
50 #include <cyg/kernel/ktypes.h> |
|
|
51 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
52 #include <cyg/kernel/thread.hxx> |
|
|
53 |
|
|
54 template <class T> |
|
|
55 class Cyg_Mempoolt |
|
|
56 { |
|
|
57 private: |
|
|
58 T pool; // underlying memory manager |
|
|
59 Cyg_ThreadQueue queue; // queue of waiting threads |
|
|
60 |
|
|
61 public: |
|
|
62 |
|
|
63 CYGDBG_DEFINE_CHECK_THIS |
|
|
64 |
|
|
65 Cyg_Mempoolt( |
|
|
66 cyg_uint8 *base, |
|
|
67 cyg_int32 size, |
|
|
68 CYG_ADDRWORD arg_thru ); // Constructor |
|
|
69 ~Cyg_Mempoolt(); // Destructor |
|
|
70 |
|
|
71 // get some memory; wait if none available; return NULL if failed |
|
|
72 // due to interrupt |
|
|
73 cyg_uint8 *alloc( cyg_int32 size ); |
|
|
74 |
|
|
75 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
|
76 // get some memory with a timeout; return NULL if failed |
|
|
77 // due to interrupt or timeout |
|
|
78 cyg_uint8 *alloc( cyg_int32 size, cyg_tick_count abs_timeout ); |
|
|
79 #endif |
|
|
80 |
|
|
81 // get some memory, return NULL if none available |
|
|
82 cyg_uint8 *try_alloc( cyg_int32 size ); |
|
|
83 |
|
|
84 // free the memory back to the pool |
|
|
85 cyg_bool free( cyg_uint8 *p, cyg_int32 size ); |
|
|
86 |
|
|
87 // if applicable: return -1 if not fixed size |
|
|
88 cyg_int32 get_blocksize(); |
|
|
89 |
|
|
90 // is anyone waiting for memory? |
|
|
91 cyg_bool waiting() { return ! queue.empty(); } |
|
|
92 |
|
|
93 // these two are obvious and generic |
|
|
94 cyg_int32 get_totalmem(); |
|
|
95 cyg_int32 get_freemem(); |
|
|
96 |
|
|
97 // get information about the construction parameters for external |
|
|
98 // freeing after the destruction of the holding object. |
|
|
99 void get_arena( |
|
|
100 cyg_uint8 * &base, |
|
|
101 cyg_int32 &size, |
|
|
102 CYG_ADDRWORD &arg_thru ); |
|
|
103 |
|
|
104 // Return the size of the memory allocation (previously returned |
|
|
105 // by alloc() or try_alloc() ) at ptr. Returns -1 if not found |
|
|
106 cyg_int32 |
|
|
107 get_allocation_size( cyg_uint8 * /* ptr */ ); |
|
|
108 }; |
|
|
109 |
|
|
110 // ------------------------------------------------------------------------- |
|
|
111 #endif // ifndef CYGONCE_KERNEL_MEMPOOLT_HXX |
|
|
112 // EOF mempoolt.hxx |