Mercurial > ecos
annotate packages/kernel/current/include/llistt.hxx @ 3292:7f8e529b4d82 default tip
Fix FREESCALE_EDMA_NBYTES_MLOFFYES_MLOFF() so it works with negative offsets.
| author | vae |
|---|---|
| date | Wed, 29 Apr 2015 23:31:48 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 0 | 1 #ifndef CYGONCE_KERNEL_LLISTT_HXX |
| 2 #define CYGONCE_KERNEL_LLISTT_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // llistt.hxx |
| 0 | 7 // |
| 2 | 8 // Llistt linked list template class declarations |
| 0 | 9 // |
| 10 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
11 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
12 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
13 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
15 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
16 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
17 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
18 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
19 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
20 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
21 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
22 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
23 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
24 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
25 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
26 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
27 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
28 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
29 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
30 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
31 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
32 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
33 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
34 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
35 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
36 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
37 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
38 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
39 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
40 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
41 // ####ECOSGPLCOPYRIGHTEND#### |
| 0 | 42 //========================================================================== |
| 43 //#####DESCRIPTIONBEGIN#### | |
| 44 // | |
| 2 | 45 // Author(s): hmt |
| 46 // Contributors: hmt | |
| 47 // Date: 1998-02-10 | |
| 48 // Purpose: Define Llistt template class | |
| 49 // Description: The classes defined here provide the APIs for llistts. | |
| 50 // Usage: #include <cyg/kernel/llistt.hxx> | |
| 51 // | |
| 0 | 52 // |
| 53 //####DESCRIPTIONEND#### | |
| 54 // | |
| 55 //========================================================================== | |
| 56 | |
| 57 #include <cyg/kernel/ktypes.h> | |
| 58 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 59 #include <cyg/kernel/thread.hxx> | |
| 60 | |
| 61 // ------------------------------------------------------------------------- | |
| 62 // A simple linked list template; each item also contains a pointer of type | |
| 63 // T, and you can search for a particular T* in a list. | |
| 64 // | |
| 65 // It is intended that this list be amenable to the trick of using the | |
| 66 // address of the pointer that is the list head, cast to an item pointer, | |
| 67 // as the "zeroth" element of the list; prev of the first item is the | |
| 68 // address of the head pointer, and inserting before the first item works | |
| 69 // correctly. For this reason, a "getprev" is not provided; iteration may | |
| 70 // only be forwards, until a NULL is found. | |
| 71 // | |
| 72 // It is expected that derived classes will be used to hold other | |
| 73 // information than just the T* but that is beyond our discussion here; | |
| 74 // only the T* can be searched for using code provided here. | |
| 75 // | |
| 76 // This module is NOT thread-safe; it is expected that all clients will be | |
| 77 // seeing that that themselves. | |
| 78 | |
| 79 template <class T> | |
| 80 class Cyg_Llistt | |
| 81 { | |
| 82 private: | |
| 83 Cyg_Llistt<T> *next, *prev; | |
| 84 T *tptr; | |
| 85 | |
| 86 private: | |
| 87 // make initialisation _without_ a T* impossible. | |
| 88 Cyg_Llistt<T> &operator=(Cyg_Llistt<T> &); | |
| 89 Cyg_Llistt(Cyg_Llistt<T> &); | |
| 90 Cyg_Llistt(); | |
| 91 | |
| 92 public: | |
| 93 | |
| 94 CYGDBG_DEFINE_CHECK_THIS | |
| 95 | |
| 96 Cyg_Llistt( T *tvalue ) // Constructor | |
| 97 { | |
| 98 tptr = tvalue; | |
| 99 next = prev = NULL; | |
| 100 } | |
| 101 | |
| 102 ~Cyg_Llistt() // Destructor | |
| 103 { | |
| 104 CYG_ASSERT( NULL == next, "bad item next - still in list" ); | |
| 105 CYG_ASSERT( NULL == prev, "bad item prev - still in list" ); | |
| 106 } | |
| 107 | |
| 108 // iterator, basically. | |
| 109 Cyg_Llistt<T> * getnext() { return next; } | |
| 110 | |
| 111 // get the value | |
| 112 T * getitem() { return tptr; } | |
| 113 | |
| 114 // look up a particular T value in the llist | |
| 115 static Cyg_Llistt<T> * | |
| 116 find( Cyg_Llistt<T> *list, T *tvalue ) | |
| 117 { | |
| 118 for ( ; list ; list = list->next ) { | |
| 119 if ( list->tptr == tvalue ) | |
| 120 break; | |
| 121 } | |
| 122 return list; | |
| 123 } | |
| 124 | |
| 125 // unlink an item from the list | |
| 126 void | |
| 127 unlink() | |
| 128 { | |
| 129 CYG_ASSERT( prev, "not in a list" ); | |
| 130 prev->next = next; | |
| 131 if ( next ) { | |
| 132 next->prev = prev; | |
| 133 } | |
| 134 next = prev = NULL; | |
| 135 } | |
| 136 | |
| 137 // insert a new item in the list after "this" | |
| 138 void | |
| 139 insertafter( Cyg_Llistt<T> *item ) | |
| 140 { | |
| 141 CYG_ASSERT( item, "null item" ); | |
| 142 CYG_ASSERT( NULL == item->next, "bad item next - already linked" ); | |
| 143 CYG_ASSERT( NULL == item->prev, "bad item prev - already linked" ); | |
| 144 item->next = next; | |
| 145 item->prev = this; | |
| 146 if ( next ) | |
| 147 next->prev = item; | |
| 148 next = item; | |
| 149 } | |
| 150 | |
| 151 // insert a new item in the list before "this" | |
| 152 void | |
| 153 insertbefore( Cyg_Llistt<T> *item ) | |
| 154 { | |
| 155 CYG_ASSERT( prev, "this not in a list" ); | |
| 156 CYG_ASSERT( item, "null item" ); | |
| 157 CYG_ASSERT( NULL == item->next, "bad item next - already linked" ); | |
| 158 CYG_ASSERT( NULL == item->prev, "bad item prev - already linked" ); | |
| 159 item->prev = prev; | |
| 160 item->next = this; | |
| 161 prev->next = item; | |
| 162 prev = item; | |
| 163 } | |
| 164 }; | |
| 165 | |
| 166 | |
| 167 | |
| 168 // ------------------------------------------------------------------------- | |
| 169 #endif // ifndef CYGONCE_KERNEL_LLISTT_HXX | |
| 170 // EOF llistt.hxx |
