1 #ifndef CYGONCE_KERNEL_LLISTT_HXX
2 #define CYGONCE_KERNEL_LLISTT_HXX
4 //==========================================================================
8 // Llistt linked list template class declarations
10 //==========================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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 version.
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //==========================================================================
44 //#####DESCRIPTIONBEGIN####
49 // Purpose: Define Llistt template class
50 // Description: The classes defined here provide the APIs for llistts.
51 // Usage: #include <cyg/kernel/llistt.hxx>
54 //####DESCRIPTIONEND####
56 //==========================================================================
58 #include <cyg/kernel/ktypes.h>
59 #include <cyg/infra/cyg_ass.h> // assertion macros
60 #include <cyg/kernel/thread.hxx>
62 // -------------------------------------------------------------------------
63 // A simple linked list template; each item also contains a pointer of type
64 // T, and you can search for a particular T* in a list.
66 // It is intended that this list be amenable to the trick of using the
67 // address of the pointer that is the list head, cast to an item pointer,
68 // as the "zeroth" element of the list; prev of the first item is the
69 // address of the head pointer, and inserting before the first item works
70 // correctly. For this reason, a "getprev" is not provided; iteration may
71 // only be forwards, until a NULL is found.
73 // It is expected that derived classes will be used to hold other
74 // information than just the T* but that is beyond our discussion here;
75 // only the T* can be searched for using code provided here.
77 // This module is NOT thread-safe; it is expected that all clients will be
78 // seeing that that themselves.
84 Cyg_Llistt<T> *next, *prev;
88 // make initialisation _without_ a T* impossible.
89 Cyg_Llistt<T> &operator=(Cyg_Llistt<T> &);
90 Cyg_Llistt(Cyg_Llistt<T> &);
95 CYGDBG_DEFINE_CHECK_THIS
97 Cyg_Llistt( T *tvalue ) // Constructor
103 ~Cyg_Llistt() // Destructor
105 CYG_ASSERT( NULL == next, "bad item next - still in list" );
106 CYG_ASSERT( NULL == prev, "bad item prev - still in list" );
109 // iterator, basically.
110 Cyg_Llistt<T> * getnext() { return next; }
113 T * getitem() { return tptr; }
115 // look up a particular T value in the llist
116 static Cyg_Llistt<T> *
117 find( Cyg_Llistt<T> *list, T *tvalue )
119 for ( ; list ; list = list->next ) {
120 if ( list->tptr == tvalue )
126 // unlink an item from the list
130 CYG_ASSERT( prev, "not in a list" );
138 // insert a new item in the list after "this"
140 insertafter( Cyg_Llistt<T> *item )
142 CYG_ASSERT( item, "null item" );
143 CYG_ASSERT( NULL == item->next, "bad item next - already linked" );
144 CYG_ASSERT( NULL == item->prev, "bad item prev - already linked" );
152 // insert a new item in the list before "this"
154 insertbefore( Cyg_Llistt<T> *item )
156 CYG_ASSERT( prev, "this not in a list" );
157 CYG_ASSERT( item, "null item" );
158 CYG_ASSERT( NULL == item->next, "bad item next - already linked" );
159 CYG_ASSERT( NULL == item->prev, "bad item prev - already linked" );
169 // -------------------------------------------------------------------------
170 #endif // ifndef CYGONCE_KERNEL_LLISTT_HXX