comparison packages/kernel/current/include/memvar.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_MEMVAR_HXX
2 #define CYGONCE_KERNEL_MEMVAR_HXX
3
4 //==========================================================================
5 //
6 // memvar.hxx
7 //
8 // Memory pool with variable 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): dsm
36 // Contributors: dsm
37 // Date: 1998-05-21
38 // Purpose: Define Memvar class interface
39 // Description: Inline class for constructing a variable block allocator
40 // Usage: #include <cyg/kernel/memvar.hxx>
41 //
42 //
43 //####DESCRIPTIONEND####
44 //
45 //==========================================================================
46
47 #include <cyg/kernel/ktypes.h> // kernel types
48 #include <cyg/infra/cyg_ass.h> // assertion macros
49
50 #ifdef CYGIMP_MEM_USE_MEMPOOLT_PLAIN
51 #include <cyg/kernel/mempoolt.hxx> // kernel safe mempool template
52 #else
53 #include <cyg/kernel/mempolt2.hxx> // kernel safe mempool template
54 #endif
55
56 #include <cyg/kernel/mvarimpl.hxx> // implementation of a variable mem pool
57
58 class Cyg_Mempool_Variable {
59 private:
60 #ifdef CYGIMP_MEM_USE_MEMPOOLT_PLAIN
61 Cyg_Mempoolt<Cyg_Mempool_Variable_Implementation> mypool;
62 #else
63 Cyg_Mempolt2<Cyg_Mempool_Variable_Implementation> mypool;
64 #endif
65
66 public:
67 // this API makes concrete a class which implements a thread-safe
68 // kernel-savvy memory pool which manages variable size blocks.
69
70 CYGDBG_DEFINE_CHECK_THIS
71
72 // Constructor: gives the base and size of the arena in which memory is
73 // to be carved out, note that management structures are taken from the
74 // same arena. Alignment is the alignment of allocated blocks.
75 Cyg_Mempool_Variable(
76 cyg_uint8 * /* base */,
77 cyg_int32 /* size */);
78
79 // Destructor
80 ~Cyg_Mempool_Variable();
81
82 // get some memory; wait if none available
83 cyg_uint8 *
84 alloc(cyg_int32 /* size */);
85
86 #ifdef CYGFUN_KERNEL_THREADS_TIMER
87 // get some memory with a timeout
88 cyg_uint8 *
89 alloc(cyg_int32 /* size */, cyg_tick_count /* delay_timeout */ );
90 #endif
91
92 // get some memory, return NULL if none available
93 cyg_uint8 *
94 try_alloc(cyg_int32 /* size */ );
95
96 // free the memory back to the pool
97 cyg_bool
98 free( cyg_uint8 * /* ptr */, cyg_int32 /* size */ );
99
100 // is anyone waiting for memory?
101 cyg_bool
102 waiting( void );
103
104 // read the fixed allocation size (-1 indicates variable)
105 cyg_int32
106 get_blocksize( void );
107
108 // these two are obvious and generic
109 cyg_int32
110 get_totalmem( void );
111
112 cyg_int32
113 get_freemem( void );
114
115 // get information about the construction parameters for external
116 // freeing after the destruction of the holding object
117 // also finds largest free block
118 void
119 get_arena( cyg_uint8 * & /* base */, cyg_int32 & /* size */,
120 CYG_ADDRWORD & /* maxfree */ );
121
122 // Return the size of the memory allocation (previously returned
123 // by alloc() or try_alloc() ) at ptr. Returns -1 if not found
124 cyg_int32
125 get_allocation_size( cyg_uint8 * /* ptr */ );
126 };
127
128 #endif // ifndef CYGONCE_KERNEL_MEMVAR_HXX
129 // EOF memvar.hxx