comparison packages/kernel/current/include/mempolt2.hxx @ 0:3111d98ba7b3 ecos-v1_1-release

Initial commit of eCos version 1.1
author jlarmour
date Tue, 11 May 1999 11:16:07 +0000
parents
children 443894e2e912
comparison
equal deleted inserted replaced
-1:000000000000 0:3111d98ba7b3
1 #ifndef CYGONCE_KERNEL_MEMPOLT2_HXX
2 #define CYGONCE_KERNEL_MEMPOLT2_HXX
3
4 //==========================================================================
5 //
6 // mempolt2.hxx
7 //
8 // Mempolt2 (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 Mempolt2 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/mempolt2.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_Mempolt2
56 {
57 private:
58 T pool; // underlying memory manager
59 Cyg_ThreadQueue queue; // queue of waiting threads
60
61 class Mempolt2WaitInfo {
62 private:
63 Mempolt2WaitInfo() {}
64 public:
65 cyg_int32 size;
66 cyg_uint8 *addr;
67 Mempolt2WaitInfo( cyg_int32 allocsize )
68 { size = allocsize; addr = 0; }
69 };
70
71 public:
72
73 CYGDBG_DEFINE_CHECK_THIS
74
75 Cyg_Mempolt2(
76 cyg_uint8 *base,
77 cyg_int32 size,
78 CYG_ADDRWORD arg_thru ); // Constructor
79 ~Cyg_Mempolt2(); // Destructor
80
81 // get some memory; wait if none available; return NULL if failed
82 // due to interrupt
83 cyg_uint8 *alloc( cyg_int32 size );
84
85 #ifdef CYGFUN_KERNEL_THREADS_TIMER
86 // get some memory with a timeout; return NULL if failed
87 // due to interrupt or timeout
88 cyg_uint8 *alloc( cyg_int32 size, cyg_tick_count abs_timeout );
89 #endif
90
91 // get some memory, return NULL if none available
92 cyg_uint8 *try_alloc( cyg_int32 size );
93
94 // free the memory back to the pool
95 cyg_bool free( cyg_uint8 *p, cyg_int32 size );
96
97 // if applicable: return -1 if not fixed size
98 cyg_int32 get_blocksize();
99
100 // is anyone waiting for memory?
101 cyg_bool waiting() { return ! queue.empty(); }
102
103 // these two are obvious and generic
104 cyg_int32 get_totalmem();
105 cyg_int32 get_freemem();
106
107 // get information about the construction parameters for external
108 // freeing after the destruction of the holding object.
109 void get_arena(
110 cyg_uint8 * &base,
111 cyg_int32 &size,
112 CYG_ADDRWORD &arg_thru );
113
114 // Return the size of the memory allocation (previously returned
115 // by alloc() or try_alloc() ) at ptr. Returns -1 if not found
116 cyg_int32
117 get_allocation_size( cyg_uint8 * /* ptr */ );
118 };
119
120 // -------------------------------------------------------------------------
121 #endif // ifndef CYGONCE_KERNEL_MEMPOLT2_HXX
122 // EOF mempolt2.hxx