Mercurial > ecos-v3_0-branch
annotate packages/kernel/current/include/mempolt2.hxx @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children |
| rev | line source |
|---|---|
| 0 | 1 #ifndef CYGONCE_KERNEL_MEMPOLT2_HXX |
| 2 #define CYGONCE_KERNEL_MEMPOLT2_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // mempolt2.hxx |
| 0 | 7 // |
| 2 | 8 // Mempolt2 (Memory pool template) class declarations |
| 0 | 9 // |
| 10 //========================================================================== | |
| 11 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
12 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
14 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
15 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
16 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
17 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
19 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
30 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
31 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
32 // |
| 0 | 33 //####COPYRIGHTEND#### |
| 34 //========================================================================== | |
| 35 //#####DESCRIPTIONBEGIN#### | |
| 36 // | |
| 2 | 37 // Author(s): hmt |
| 38 // Contributors: hmt | |
| 39 // Date: 1998-02-10 | |
| 40 // Purpose: Define Mempolt2 class interface | |
| 0 | 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. | |
| 2 | 45 // Usage: #include <cyg/kernel/mempolt2.hxx> |
| 46 // | |
| 0 | 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_Mempolt2 | |
| 58 { | |
| 59 private: | |
| 60 T pool; // underlying memory manager | |
| 61 Cyg_ThreadQueue queue; // queue of waiting threads | |
| 62 | |
| 63 class Mempolt2WaitInfo { | |
| 64 private: | |
| 65 Mempolt2WaitInfo() {} | |
| 66 public: | |
| 67 cyg_int32 size; | |
| 68 cyg_uint8 *addr; | |
| 69 Mempolt2WaitInfo( cyg_int32 allocsize ) | |
| 70 { size = allocsize; addr = 0; } | |
| 71 }; | |
| 72 | |
| 73 public: | |
| 74 | |
| 75 CYGDBG_DEFINE_CHECK_THIS | |
| 76 | |
| 77 Cyg_Mempolt2( | |
| 78 cyg_uint8 *base, | |
| 79 cyg_int32 size, | |
| 80 CYG_ADDRWORD arg_thru ); // Constructor | |
| 81 ~Cyg_Mempolt2(); // Destructor | |
| 82 | |
| 83 // get some memory; wait if none available; return NULL if failed | |
| 84 // due to interrupt | |
| 85 cyg_uint8 *alloc( cyg_int32 size ); | |
| 86 | |
| 87 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 88 // get some memory with a timeout; return NULL if failed | |
| 89 // due to interrupt or timeout | |
| 90 cyg_uint8 *alloc( cyg_int32 size, cyg_tick_count abs_timeout ); | |
| 91 #endif | |
| 92 | |
| 93 // get some memory, return NULL if none available | |
| 94 cyg_uint8 *try_alloc( cyg_int32 size ); | |
| 95 | |
| 96 // free the memory back to the pool | |
| 97 cyg_bool free( cyg_uint8 *p, cyg_int32 size ); | |
| 98 | |
| 99 // if applicable: return -1 if not fixed size | |
| 100 cyg_int32 get_blocksize(); | |
| 101 | |
| 102 // is anyone waiting for memory? | |
| 103 cyg_bool waiting() { return ! queue.empty(); } | |
| 104 | |
| 105 // these two are obvious and generic | |
| 106 cyg_int32 get_totalmem(); | |
| 107 cyg_int32 get_freemem(); | |
| 108 | |
| 109 // get information about the construction parameters for external | |
| 110 // freeing after the destruction of the holding object. | |
| 111 void get_arena( | |
| 112 cyg_uint8 * &base, | |
| 113 cyg_int32 &size, | |
| 114 CYG_ADDRWORD &arg_thru ); | |
| 115 | |
| 116 // Return the size of the memory allocation (previously returned | |
| 117 // by alloc() or try_alloc() ) at ptr. Returns -1 if not found | |
| 118 cyg_int32 | |
| 119 get_allocation_size( cyg_uint8 * /* ptr */ ); | |
| 120 }; | |
| 121 | |
| 122 // ------------------------------------------------------------------------- | |
| 123 #endif // ifndef CYGONCE_KERNEL_MEMPOLT2_HXX | |
| 124 // EOF mempolt2.hxx |
