| 1 |
786 |
skrzyp |
#ifndef CYGONCE_MEMALLOC_COMMON_HXX
|
| 2 |
|
|
#define CYGONCE_MEMALLOC_COMMON_HXX
|
| 3 |
|
|
|
| 4 |
|
|
/*==========================================================================
|
| 5 |
|
|
//
|
| 6 |
|
|
// common.hxx
|
| 7 |
|
|
//
|
| 8 |
|
|
// Shared definitions used by memory allocators
|
| 9 |
|
|
//
|
| 10 |
|
|
//==========================================================================
|
| 11 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
| 12 |
|
|
// -------------------------------------------
|
| 13 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
| 14 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
| 15 |
|
|
//
|
| 16 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
| 17 |
|
|
// the terms of the GNU General Public License as published by the Free
|
| 18 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
| 19 |
|
|
// version.
|
| 20 |
|
|
//
|
| 21 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
| 22 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 23 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 24 |
|
|
// for more details.
|
| 25 |
|
|
//
|
| 26 |
|
|
// You should have received a copy of the GNU General Public License
|
| 27 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
| 28 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 29 |
|
|
//
|
| 30 |
|
|
// As a special exception, if other files instantiate templates or use
|
| 31 |
|
|
// macros or inline functions from this file, or you compile this file
|
| 32 |
|
|
// and link it with other works to produce a work based on this file,
|
| 33 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
| 34 |
|
|
// the GNU General Public License. However the source code for this file
|
| 35 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
| 36 |
|
|
// General Public License v2.
|
| 37 |
|
|
//
|
| 38 |
|
|
// This exception does not invalidate any other reasons why a work based
|
| 39 |
|
|
// on this file might be covered by the GNU General Public License.
|
| 40 |
|
|
// -------------------------------------------
|
| 41 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
| 42 |
|
|
//==========================================================================
|
| 43 |
|
|
//#####DESCRIPTIONBEGIN####
|
| 44 |
|
|
//
|
| 45 |
|
|
// Author(s): jlarmour
|
| 46 |
|
|
// Contributors:
|
| 47 |
|
|
// Date: 2000-06-12
|
| 48 |
|
|
// Purpose: Shared definitions used by memory allocators
|
| 49 |
|
|
// Description:
|
| 50 |
|
|
// Usage: #include
|
| 51 |
|
|
//
|
| 52 |
|
|
//
|
| 53 |
|
|
//####DESCRIPTIONEND####
|
| 54 |
|
|
//
|
| 55 |
|
|
//========================================================================*/
|
| 56 |
|
|
|
| 57 |
|
|
/* CONFIGURATION */
|
| 58 |
|
|
|
| 59 |
|
|
#include
|
| 60 |
|
|
|
| 61 |
|
|
/* TYPE DEFINITIONS */
|
| 62 |
|
|
|
| 63 |
|
|
// struct Cyg_Mempool_Status is returned by the get_status() method of
|
| 64 |
|
|
// standard eCos memory allocators. After return from get_status(), any
|
| 65 |
|
|
// field of type T may be set to ((T)-1) to indicate that the information
|
| 66 |
|
|
// is not available or not applicable to this allocator.
|
| 67 |
|
|
|
| 68 |
|
|
|
| 69 |
|
|
class Cyg_Mempool_Status {
|
| 70 |
|
|
public:
|
| 71 |
|
|
const cyg_uint8 *arenabase; // base address of entire pool
|
| 72 |
|
|
cyg_int32 arenasize; // total size of entire pool
|
| 73 |
|
|
cyg_int32 freeblocks; // number of chunks free for use
|
| 74 |
|
|
cyg_int32 totalallocated; // total allocated space in bytes
|
| 75 |
|
|
cyg_int32 totalfree; // total space in bytes not in use
|
| 76 |
|
|
cyg_int32 blocksize; // block size if fixed block
|
| 77 |
|
|
cyg_int32 maxfree; // size of largest unused block
|
| 78 |
|
|
cyg_int8 waiting; // are there any threads waiting for memory?
|
| 79 |
|
|
const cyg_uint8 *origbase; // address of original region used when pool
|
| 80 |
|
|
// created
|
| 81 |
|
|
cyg_int32 origsize; // size of original region used when pool
|
| 82 |
|
|
// created
|
| 83 |
|
|
|
| 84 |
|
|
// maxoverhead is the *maximum* per-allocation overhead imposed by
|
| 85 |
|
|
// the allocator implementation. Note: this is rarely the typical
|
| 86 |
|
|
// overhead which often depends on the size of the allocation requested.
|
| 87 |
|
|
// It includes overhead due to alignment constraints. For example, if
|
| 88 |
|
|
// maxfree and maxoverhead are available for this allocator, then an
|
| 89 |
|
|
// allocation request of (maxfree-maxoverhead) bytes must always succeed
|
| 90 |
|
|
// Unless maxoverhead is set to -1 of course, in which case the allocator
|
| 91 |
|
|
// does not support reporting this information.
|
| 92 |
|
|
|
| 93 |
|
|
cyg_int8 maxoverhead;
|
| 94 |
|
|
|
| 95 |
|
|
void
|
| 96 |
|
|
init() {
|
| 97 |
|
|
arenabase = (const cyg_uint8 *)-1;
|
| 98 |
|
|
arenasize = -1;
|
| 99 |
|
|
freeblocks = -1;
|
| 100 |
|
|
totalallocated = -1;
|
| 101 |
|
|
totalfree = -1;
|
| 102 |
|
|
blocksize = -1;
|
| 103 |
|
|
maxfree = -1;
|
| 104 |
|
|
waiting = -1;
|
| 105 |
|
|
origbase = (const cyg_uint8 *)-1;
|
| 106 |
|
|
origsize = -1;
|
| 107 |
|
|
maxoverhead = -1;
|
| 108 |
|
|
}
|
| 109 |
|
|
|
| 110 |
|
|
// constructor
|
| 111 |
|
|
Cyg_Mempool_Status() { init(); }
|
| 112 |
|
|
};
|
| 113 |
|
|
|
| 114 |
|
|
// Flags to pass to get_status() methods to tell it which stat(s) is/are
|
| 115 |
|
|
// being requested
|
| 116 |
|
|
|
| 117 |
|
|
#define CYG_MEMPOOL_STAT_ARENABASE (1<<0)
|
| 118 |
|
|
#define CYG_MEMPOOL_STAT_ARENASIZE (1<<1)
|
| 119 |
|
|
#define CYG_MEMPOOL_STAT_FREEBLOCKS (1<<2)
|
| 120 |
|
|
#define CYG_MEMPOOL_STAT_TOTALALLOCATED (1<<3)
|
| 121 |
|
|
#define CYG_MEMPOOL_STAT_TOTALFREE (1<<4)
|
| 122 |
|
|
#define CYG_MEMPOOL_STAT_BLOCKSIZE (1<<5)
|
| 123 |
|
|
#define CYG_MEMPOOL_STAT_MAXFREE (1<<6)
|
| 124 |
|
|
#define CYG_MEMPOOL_STAT_WAITING (1<<7)
|
| 125 |
|
|
#define CYG_MEMPOOL_STAT_ORIGBASE (1<<9)
|
| 126 |
|
|
#define CYG_MEMPOOL_STAT_ORIGSIZE (1<<10)
|
| 127 |
|
|
#define CYG_MEMPOOL_STAT_MAXOVERHEAD (1<<11)
|
| 128 |
|
|
|
| 129 |
|
|
// And an opaque type for any arguments with these flags
|
| 130 |
|
|
typedef cyg_uint16 cyg_mempool_status_flag_t;
|
| 131 |
|
|
|
| 132 |
|
|
// breakpoint site for out of memory conditions
|
| 133 |
|
|
#ifdef CYGSEM_MEMALLOC_INVOKE_OUT_OF_MEMORY
|
| 134 |
|
|
#include // protoype for cyg_memalloc_alloc_fail
|
| 135 |
|
|
#define CYG_MEMALLOC_FAIL_TEST( test, size ) \
|
| 136 |
|
|
CYG_MACRO_START \
|
| 137 |
|
|
if ( test) { \
|
| 138 |
|
|
cyg_memalloc_alloc_fail(__FILE__, __LINE__, size ); \
|
| 139 |
|
|
} \
|
| 140 |
|
|
CYG_MACRO_END
|
| 141 |
|
|
#define CYG_MEMALLOC_FAIL( size) \
|
| 142 |
|
|
CYG_MACRO_START \
|
| 143 |
|
|
cyg_memalloc_alloc_fail(__FILE__, __LINE__, size ); \
|
| 144 |
|
|
CYG_MACRO_END
|
| 145 |
|
|
#else
|
| 146 |
|
|
#define CYG_MEMALLOC_FAIL_TEST( test, size ) CYG_EMPTY_STATEMENT
|
| 147 |
|
|
#define CYG_MEMALLOC_FAIL( size ) CYG_EMPTY_STATEMENT
|
| 148 |
|
|
#endif
|
| 149 |
|
|
|
| 150 |
|
|
#endif /* ifndef CYGONCE_MEMALLOC_COMMON_HXX */
|
| 151 |
|
|
/* EOF common.hxx */
|