Mercurial > ecos-v2_0-branch
comparison packages/services/memalloc/common/current/src/memfixed.cxx @ 115:6ed91473a1cd ecos-sw-2000-08-21
Merge from eCos master repository on 2000-08-21-22:40:54-BST
| author | jlarmour |
|---|---|
| date | Fri, 25 Aug 2000 17:32:38 +0000 |
| parents | |
| children | e0c0827131d1 |
comparison
equal
deleted
inserted
replaced
| 114:5ad2b71d525e | 115:6ed91473a1cd |
|---|---|
| 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 Red Hat eCos Public License | |
| 12 // Version 1.1 (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://www.redhat.com/ | |
| 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 Configurable Operating System, | |
| 22 // released September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Red Hat. | |
| 25 // Portions created by Red Hat are | |
| 26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 27 // All Rights Reserved. | |
| 28 // ------------------------------------------- | |
| 29 // | |
| 30 //####COPYRIGHTEND#### | |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): hmt | |
| 35 // Contributors: jlarmour | |
| 36 // Date: 2000-06-16 | |
| 37 // Purpose: Define Memfixed class interface | |
| 38 // Description: Inline class for constructing a fixed block allocator | |
| 39 // Usage: #include <cyg/memalloc/memfixed.hxx> | |
| 40 // | |
| 41 // | |
| 42 //####DESCRIPTIONEND#### | |
| 43 // | |
| 44 //========================================================================== | |
| 45 | |
| 46 // CONFIGURATION | |
| 47 | |
| 48 #include <pkgconf/memalloc.h> | |
| 49 #include <pkgconf/system.h> | |
| 50 #ifdef CYGPKG_KERNEL | |
| 51 # include <pkgconf/kernel.h> | |
| 52 #endif | |
| 53 | |
| 54 | |
| 55 // INCLUDES | |
| 56 | |
| 57 #include <cyg/infra/cyg_type.h> // types | |
| 58 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 59 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 60 | |
| 61 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 62 # include <cyg/kernel/ktypes.h> // cyg_tick_count | |
| 63 #endif | |
| 64 | |
| 65 #ifdef CYGSEM_MEMALLOC_ALLOCATOR_FIXED_THREADAWARE | |
| 66 // tell it to optimize for the fixed block one-to-one case | |
| 67 # define CYGIMP_MEM_T_ONEFREE_TO_ONEALLOC | |
| 68 # include <cyg/memalloc/mempolt2.hxx> // kernel safe mempool template | |
| 69 #endif | |
| 70 | |
| 71 #include <cyg/memalloc/memfixed.hxx> | |
| 72 #include <cyg/memalloc/mfiximpl.hxx> // implementation of a fixed mem pool | |
| 73 #include <cyg/memalloc/common.hxx> // Common memory allocator infra | |
| 74 | |
| 75 // ------------------------------------------------------------------------- | |
| 76 // debugging/assert function | |
| 77 | |
| 78 #ifdef CYGDBG_USE_ASSERTS | |
| 79 cyg_bool | |
| 80 Cyg_Mempool_Fixed::check_this(cyg_assert_class_zeal zeal) const | |
| 81 { | |
| 82 CYG_REPORT_FUNCTION(); | |
| 83 // check that we have a non-NULL pointer first | |
| 84 if( this == NULL ) return false; | |
| 85 #ifdef CYGSEM_MEMALLOC_ALLOCATOR_FIXED_THREADAWARE | |
| 86 return mypool.check_this( zeal ); | |
| 87 #else | |
| 88 return true; | |
| 89 #endif | |
| 90 } | |
| 91 #endif | |
| 92 | |
| 93 // ------------------------------------------------------------------------- | |
| 94 // Constructor: gives the base and size of the arena in which memory is | |
| 95 // to be carved out, note that management structures are taken from the | |
| 96 // same arena. Alloc_unit is the blocksize allocated. | |
| 97 Cyg_Mempool_Fixed::Cyg_Mempool_Fixed( | |
| 98 cyg_uint8 *base, | |
| 99 cyg_int32 size, | |
| 100 CYG_ADDRWORD alloc_unit ) | |
| 101 : mypool( base, size, alloc_unit ) | |
| 102 { | |
| 103 } | |
| 104 | |
| 105 // Destructor | |
| 106 Cyg_Mempool_Fixed::~Cyg_Mempool_Fixed() | |
| 107 { | |
| 108 } | |
| 109 | |
| 110 // ------------------------------------------------------------------------- | |
| 111 // get some memory; wait if none available | |
| 112 #ifdef CYGSEM_MEMALLOC_ALLOCATOR_FIXED_THREADAWARE | |
| 113 cyg_uint8 * | |
| 114 Cyg_Mempool_Fixed::alloc() | |
| 115 { | |
| 116 return mypool.alloc( 0 ); | |
| 117 } | |
| 118 | |
| 119 # ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 120 // get some memory with a timeout | |
| 121 cyg_uint8 * | |
| 122 Cyg_Mempool_Fixed::alloc(cyg_tick_count delay_timeout ) | |
| 123 { | |
| 124 return mypool.alloc( 0, delay_timeout ); | |
| 125 } | |
| 126 # endif | |
| 127 #endif | |
| 128 | |
| 129 // get some memory, return NULL if none available | |
| 130 cyg_uint8 * | |
| 131 Cyg_Mempool_Fixed::try_alloc() | |
| 132 { | |
| 133 return mypool.try_alloc( 0 ); | |
| 134 } | |
| 135 | |
| 136 // free the memory back to the pool | |
| 137 cyg_bool | |
| 138 Cyg_Mempool_Fixed::free( cyg_uint8 *p ) | |
| 139 { | |
| 140 return mypool.free( p, 0 ); | |
| 141 } | |
| 142 | |
| 143 // supposedly resize existing allocation. This is defined in the | |
| 144 // fixed block allocator purely for API consistency. It will return | |
| 145 // an error (false) for all values, except for the blocksize | |
| 146 // returns true on success | |
| 147 cyg_uint8 * | |
| 148 Cyg_Mempool_Fixed::resize_alloc( cyg_uint8 *alloc_ptr, cyg_int32 newsize, | |
| 149 cyg_int32 *oldsize=NULL ) | |
| 150 { | |
| 151 return mypool.resize_alloc( alloc_ptr, newsize, oldsize ); | |
| 152 } | |
| 153 | |
| 154 // Get memory pool status | |
| 155 void | |
| 156 Cyg_Mempool_Fixed::get_status( cyg_mempool_status_flag_t flags, | |
| 157 Cyg_Mempool_Status &status ) | |
| 158 { | |
| 159 // set to 0 - if there's anything really waiting, it will be set to | |
| 160 // 1 later | |
| 161 status.waiting = 0; | |
| 162 | |
| 163 return mypool.get_status( flags, status ); | |
| 164 } | |
| 165 | |
| 166 // ------------------------------------------------------------------------- | |
| 167 | |
| 168 // End of memfixed.cxx |
