Mercurial > ecos
comparison packages/kernel/current/src/mem/memfixed.cxx @ 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 //========================================================================== | |
| 2 // | |
| 3 // memfixed.cxx | |
| 4 // | |
| 5 // Memory pool with fixed block class declarations | |
| 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 | |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | |
| 26 // ------------------------------------------- | |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //========================================================================== | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 32 // Author(s): hmt | |
| 33 // Contributors: hmt | |
| 34 // Date: 1998-03-23 | |
| 35 // Purpose: Define Memfixed class interface | |
| 36 // Description: Inline class for constructing a fixed block allocator | |
| 37 // Usage: #include <cyg/kernel/memfixed.hxx> | |
| 38 // | |
| 39 // | |
| 40 //####DESCRIPTIONEND#### | |
| 41 // | |
| 42 //========================================================================== | |
| 43 | |
| 44 #include <pkgconf/kernel.h> | |
| 45 | |
| 46 #include <cyg/kernel/ktypes.h> // base kernel types | |
| 47 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 48 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 49 #include <cyg/kernel/instrmnt.h> // instrumentation | |
| 50 | |
| 51 #include <cyg/kernel/memfixed.hxx> | |
| 52 | |
| 53 // implementation that we want to make concrete | |
| 54 #ifdef CYGIMP_MEM_USE_MEMPOOLT_PLAIN | |
| 55 #include <cyg/kernel/mempoolt.inl> // kernel safe mempool template | |
| 56 #else | |
| 57 // tell it to optimize for the fixed block one-to-one case | |
| 58 #define CYGIMP_MEM_T_ONEFREE_TO_ONEALLOC | |
| 59 #include <cyg/kernel/mempolt2.inl> // kernel safe mempool template | |
| 60 #endif | |
| 61 | |
| 62 #include <cyg/kernel/mfiximpl.inl> // implementation of a fixed mem pool | |
| 63 | |
| 64 // ------------------------------------------------------------------------- | |
| 65 // debugging/assert function | |
| 66 | |
| 67 #ifdef CYGDBG_USE_ASSERTS | |
| 68 cyg_bool | |
| 69 Cyg_Mempool_Fixed::check_this(cyg_assert_class_zeal zeal) | |
| 70 { | |
| 71 CYG_REPORT_FUNCTION(); | |
| 72 // check that we have a non-NULL pointer first | |
| 73 if( this == NULL ) return false; | |
| 74 return mypool.check_this( zeal ); | |
| 75 } | |
| 76 #endif | |
| 77 | |
| 78 // ------------------------------------------------------------------------- | |
| 79 // Constructor: gives the base and size of the arena in which memory is | |
| 80 // to be carved out, note that management structures are taken from the | |
| 81 // same arena. Alloc_unit is the blocksize allocated. | |
| 82 Cyg_Mempool_Fixed::Cyg_Mempool_Fixed( | |
| 83 cyg_uint8 *base, | |
| 84 cyg_int32 size, | |
| 85 CYG_ADDRWORD alloc_unit ) | |
| 86 : mypool( base, size, alloc_unit ) | |
| 87 { | |
| 88 } | |
| 89 | |
| 90 // Destructor | |
| 91 Cyg_Mempool_Fixed::~Cyg_Mempool_Fixed() | |
| 92 { | |
| 93 } | |
| 94 | |
| 95 // ------------------------------------------------------------------------- | |
| 96 // get some memory; wait if none available | |
| 97 cyg_uint8 * | |
| 98 Cyg_Mempool_Fixed::alloc() | |
| 99 { | |
| 100 return mypool.alloc( 0 ); | |
| 101 } | |
| 102 | |
| 103 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 104 // get some memory with a timeout | |
| 105 cyg_uint8 * | |
| 106 Cyg_Mempool_Fixed::alloc(cyg_tick_count delay_timeout ) | |
| 107 { | |
| 108 return mypool.alloc( 0, delay_timeout ); | |
| 109 } | |
| 110 #endif | |
| 111 | |
| 112 // get some memory, return NULL if none available | |
| 113 cyg_uint8 * | |
| 114 Cyg_Mempool_Fixed::try_alloc() | |
| 115 { | |
| 116 return mypool.try_alloc( 0 ); | |
| 117 } | |
| 118 | |
| 119 // free the memory back to the pool | |
| 120 cyg_bool | |
| 121 Cyg_Mempool_Fixed::free( cyg_uint8 *p ) | |
| 122 { | |
| 123 return mypool.free( p, 0 ); | |
| 124 } | |
| 125 | |
| 126 // is anyone waiting for memory? | |
| 127 cyg_bool | |
| 128 Cyg_Mempool_Fixed::waiting() | |
| 129 { | |
| 130 return mypool.waiting(); | |
| 131 } | |
| 132 | |
| 133 // read the fixed allocation size | |
| 134 cyg_int32 | |
| 135 Cyg_Mempool_Fixed::get_blocksize() | |
| 136 { | |
| 137 return mypool.get_blocksize(); | |
| 138 } | |
| 139 | |
| 140 // these two are obvious and generic | |
| 141 cyg_int32 | |
| 142 Cyg_Mempool_Fixed::get_totalmem() { | |
| 143 return mypool.get_totalmem(); | |
| 144 } | |
| 145 cyg_int32 | |
| 146 Cyg_Mempool_Fixed::get_freemem() { | |
| 147 return mypool.get_freemem(); | |
| 148 } | |
| 149 | |
| 150 // get information about the construction parameters for external | |
| 151 // freeing after the destruction of the holding object | |
| 152 void | |
| 153 Cyg_Mempool_Fixed::get_arena( | |
| 154 cyg_uint8 * &base, cyg_int32 &size, CYG_ADDRWORD &alloc ) | |
| 155 { | |
| 156 mypool.get_arena( base, size, alloc ); | |
| 157 } | |
| 158 | |
| 159 // Return the size of the memory allocation (previously returned | |
| 160 // by alloc() or try_alloc() ) at ptr. Returns -1 if not found | |
| 161 cyg_int32 | |
| 162 Cyg_Mempool_Fixed::get_allocation_size( cyg_uint8 *ptr ) | |
| 163 { | |
| 164 // can only be one size for the fixed block allocator | |
| 165 return mypool.get_blocksize(); | |
| 166 } | |
| 167 // ------------------------------------------------------------------------- | |
| 168 | |
| 169 // End of memfixed.cxx |
