Mercurial > ecos-v2_0-branch
comparison packages/services/memalloc/common/current/include/mempoolt.hxx @ 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 #ifndef CYGONCE_KERNEL_MEMPOOLT_HXX | |
| 2 #define CYGONCE_KERNEL_MEMPOOLT_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 6 // mempoolt.hxx | |
| 7 // | |
| 8 // Mempoolt (Memory pool template) class declarations | |
| 9 // | |
| 10 //========================================================================== | |
| 11 //####COPYRIGHTBEGIN#### | |
| 12 // | |
| 13 // ------------------------------------------- | |
| 14 // The contents of this file are subject to the Red Hat eCos Public License | |
| 15 // Version 1.1 (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://www.redhat.com/ | |
| 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 Configurable Operating System, | |
| 25 // released September 30, 1998. | |
| 26 // | |
| 27 // The Initial Developer of the Original Code is Red Hat. | |
| 28 // Portions created by Red Hat are | |
| 29 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 30 // All Rights Reserved. | |
| 31 // ------------------------------------------- | |
| 32 // | |
| 33 //####COPYRIGHTEND#### | |
| 34 //========================================================================== | |
| 35 //#####DESCRIPTIONBEGIN#### | |
| 36 // | |
| 37 // Author(s): hmt | |
| 38 // Contributors: hmt | |
| 39 // Date: 1998-02-10 | |
| 40 // Purpose: Define Mempoolt class interface | |
| 41 | |
| 42 // Description: The class defined here provides the APIs for thread-safe, | |
| 43 // kernel-savvy memory managers; make a class with the | |
| 44 // underlying allocator as the template parameter. | |
| 45 // Usage: #include <cyg/kernel/mempoolt.hxx> | |
| 46 // | |
| 47 // | |
| 48 //####DESCRIPTIONEND#### | |
| 49 // | |
| 50 //========================================================================== | |
| 51 | |
| 52 #include <cyg/kernel/ktypes.h> | |
| 53 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 54 #include <cyg/kernel/thread.hxx> | |
| 55 | |
| 56 template <class T> | |
| 57 class Cyg_Mempoolt | |
| 58 { | |
| 59 private: | |
| 60 T pool; // underlying memory manager | |
| 61 Cyg_ThreadQueue queue; // queue of waiting threads | |
| 62 | |
| 63 public: | |
| 64 | |
| 65 CYGDBG_DEFINE_CHECK_THIS | |
| 66 | |
| 67 Cyg_Mempoolt( | |
| 68 cyg_uint8 *base, | |
| 69 cyg_int32 size, | |
| 70 CYG_ADDRWORD arg_thru ); // Constructor | |
| 71 ~Cyg_Mempoolt(); // Destructor | |
| 72 | |
| 73 // get some memory; wait if none available; return NULL if failed | |
| 74 // due to interrupt | |
| 75 cyg_uint8 *alloc( cyg_int32 size ); | |
| 76 | |
| 77 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 78 // get some memory with a timeout; return NULL if failed | |
| 79 // due to interrupt or timeout | |
| 80 cyg_uint8 *alloc( cyg_int32 size, cyg_tick_count abs_timeout ); | |
| 81 #endif | |
| 82 | |
| 83 // get some memory, return NULL if none available | |
| 84 cyg_uint8 *try_alloc( cyg_int32 size ); | |
| 85 | |
| 86 // free the memory back to the pool | |
| 87 cyg_bool free( cyg_uint8 *p, cyg_int32 size ); | |
| 88 | |
| 89 // if applicable: return -1 if not fixed size | |
| 90 cyg_int32 get_blocksize(); | |
| 91 | |
| 92 // is anyone waiting for memory? | |
| 93 cyg_bool waiting() { return ! queue.empty(); } | |
| 94 | |
| 95 // these two are obvious and generic | |
| 96 cyg_int32 get_totalmem(); | |
| 97 cyg_int32 get_freemem(); | |
| 98 | |
| 99 // get information about the construction parameters for external | |
| 100 // freeing after the destruction of the holding object. | |
| 101 void get_arena( | |
| 102 cyg_uint8 * &base, | |
| 103 cyg_int32 &size, | |
| 104 CYG_ADDRWORD &arg_thru ); | |
| 105 | |
| 106 // Return the size of the memory allocation (previously returned | |
| 107 // by alloc() or try_alloc() ) at ptr. Returns -1 if not found | |
| 108 cyg_int32 | |
| 109 get_allocation_size( cyg_uint8 * /* ptr */ ); | |
| 110 }; | |
| 111 | |
| 112 // ------------------------------------------------------------------------- | |
| 113 #endif // ifndef CYGONCE_KERNEL_MEMPOOLT_HXX | |
| 114 // EOF mempoolt.hxx |
