OpenCores
URL https://opencores.org/ocsvn/openfire2/openfire2/trunk

Subversion Repositories openfire2

[/] [openfire2/] [trunk/] [sw/] [freertos/] [list.h] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 toni32
/*
2
        FreeRTOS.org V4.2.0 - Copyright (C) 2003-2007 Richard Barry.
3
 
4
        This file is part of the FreeRTOS.org distribution.
5
 
6
        FreeRTOS.org is free software; you can redistribute it and/or modify
7
        it under the terms of the GNU General Public License as published by
8
        the Free Software Foundation; either version 2 of the License, or
9
        (at your option) any later version.
10
 
11
        FreeRTOS.org is distributed in the hope that it will be useful,
12
        but WITHOUT ANY WARRANTY; without even the implied warranty of
13
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
        GNU General Public License for more details.
15
 
16
        You should have received a copy of the GNU General Public License
17
        along with FreeRTOS.org; if not, write to the Free Software
18
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
20
        A special exception to the GPL can be applied should you wish to distribute
21
        a combined work that includes FreeRTOS.org, without being obliged to provide
22
        the source code for any proprietary components.  See the licensing section
23
        of http://www.FreeRTOS.org for full details of how and when the exception
24
        can be applied.
25
 
26
        ***************************************************************************
27
        See http://www.FreeRTOS.org for documentation, latest information, license
28
        and contact details.  Please ensure to read the configuration and relevant
29
        port sections of the online documentation.
30
        ***************************************************************************
31
*/
32
 
33
/*
34
 * This is the list implementation used by the scheduler.  While it is tailored
35
 * heavily for the schedulers needs, it is also available for use by
36
 * application code.
37
 *
38
 * xLists can only store pointers to xListItems.  Each xListItem contains a
39
 * numeric value (xItemValue).  Most of the time the lists are sorted in
40
 * descending item value order.
41
 *
42
 * Lists are created already containing one list item.  The value of this
43
 * item is the maximum possible that can be stored, it is therefore always at
44
 * the end of the list and acts as a marker.  The list member pxHead always
45
 * points to this marker - even though it is at the tail of the list.  This
46
 * is because the tail contains a wrap back pointer to the true head of
47
 * the list.
48
 *
49
 * In addition to it's value, each list item contains a pointer to the next
50
 * item in the list (pxNext), a pointer to the list it is in (pxContainer)
51
 * and a pointer to back to the object that contains it.  These later two
52
 * pointers are included for efficiency of list manipulation.  There is
53
 * effectively a two way link between the object containing the list item and
54
 * the list item itself.
55
 *
56
 *
57
 * \page ListIntroduction List Implementation
58
 * \ingroup FreeRTOSIntro
59
 */
60
 
61
 
62
#ifndef LIST_H
63
#define LIST_H
64
 
65
/*
66
 * Definition of the only type of object that a list can contain.
67
 */
68
struct xLIST_ITEM
69
{
70
        portTickType xItemValue;                                /*< The value being listed.  In most cases this is used to sort the list in descending order. */
71
        volatile struct xLIST_ITEM * pxNext;    /*< Pointer to the next xListItem in the list. */
72
        volatile struct xLIST_ITEM * pxPrevious;/*< Pointer to the previous xListItem in the list. */
73
        void * pvOwner;                                                 /*< Pointer to the object (normally a TCB) that contains the list item.  There is therefore a two way link between the object containing the list item and the list item itself. */
74
        void * pvContainer;                                             /*< Pointer to the list in which this list item is placed (if any). */
75
};
76
typedef struct xLIST_ITEM xListItem;            /* For some reason lint wants this as two separate definitions. */
77
 
78
struct xMINI_LIST_ITEM
79
{
80
        portTickType xItemValue;
81
        volatile struct xLIST_ITEM *pxNext;
82
        volatile struct xLIST_ITEM *pxPrevious;
83
};
84
typedef struct xMINI_LIST_ITEM xMiniListItem;
85
 
86
/*
87
 * Definition of the type of queue used by the scheduler.
88
 */
89
typedef struct xLIST
90
{
91
        volatile unsigned portBASE_TYPE uxNumberOfItems;
92
        volatile xListItem * pxIndex;                   /*< Used to walk through the list.  Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */
93
        volatile xMiniListItem xListEnd;                /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */
94
} xList;
95
 
96
/*
97
 * Access macro to set the owner of a list item.  The owner of a list item
98
 * is the object (usually a TCB) that contains the list item.
99
 *
100
 * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
101
 * \ingroup LinkedList
102
 */
103
#define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner )          ( pxListItem )->pvOwner = ( void * ) pxOwner
104
 
105
/*
106
 * Access macro to set the value of the list item.  In most cases the value is
107
 * used to sort the list in descending order.
108
 *
109
 * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE
110
 * \ingroup LinkedList
111
 */
112
#define listSET_LIST_ITEM_VALUE( pxListItem, xValue )           ( pxListItem )->xItemValue = xValue
113
 
114
/*
115
 * Access macro the retrieve the value of the list item.  The value can
116
 * represent anything - for example a the priority of a task, or the time at
117
 * which a task should be unblocked.
118
 *
119
 * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
120
 * \ingroup LinkedList
121
 */
122
#define listGET_LIST_ITEM_VALUE( pxListItem )                           ( ( pxListItem )->xItemValue )
123
 
124
/*
125
 * Access macro to determine if a list contains any items.  The macro will
126
 * only have the value true if the list is empty.
127
 *
128
 * \page listLIST_IS_EMPTY listLIST_IS_EMPTY
129
 * \ingroup LinkedList
130
 */
131
#define listLIST_IS_EMPTY( pxList )                             ( ( pxList )->uxNumberOfItems == ( unsigned portBASE_TYPE ) 0 )
132
 
133
/*
134
 * Access macro to return the number of items in the list.
135
 */
136
#define listCURRENT_LIST_LENGTH( pxList )               ( ( pxList )->uxNumberOfItems )
137
 
138
/*
139
 * Access function to obtain the owner of the next entry in a list.
140
 *
141
 * The list member pxIndex is used to walk through a list.  Calling
142
 * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list
143
 * and returns that entries pxOwner parameter.  Using multiple calls to this
144
 * function it is therefore possible to move through every item contained in
145
 * a list.
146
 *
147
 * The pxOwner parameter of a list item is a pointer to the object that owns
148
 * the list item.  In the scheduler this is normally a task control block.
149
 * The pxOwner parameter effectively creates a two way link between the list
150
 * item and its owner.
151
 *
152
 * @param pxList The list from which the next item owner is to be returned.
153
 *
154
 * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY
155
 * \ingroup LinkedList
156
 */
157
#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList )                                                                    \
158
        /* Increment the index to the next item and return the item, ensuring */                        \
159
        /* we don't return the marker used at the end of the list.  */                                          \
160
        ( pxList )->pxIndex = ( pxList )->pxIndex->pxNext;                                                                      \
161
        if( ( pxList )->pxIndex == ( xListItem * ) &( ( pxList )->xListEnd ) )                          \
162
        {                                                                                                                                                                       \
163
                ( pxList )->pxIndex = ( pxList )->pxIndex->pxNext;                                                              \
164
        }                                                                                                                                                                       \
165
        pxTCB = ( pxList )->pxIndex->pvOwner
166
 
167
 
168
/*
169
 * Access function to obtain the owner of the first entry in a list.  Lists
170
 * are normally sorted in ascending item value order.
171
 *
172
 * This function returns the pxOwner member of the first item in the list.
173
 * The pxOwner parameter of a list item is a pointer to the object that owns
174
 * the list item.  In the scheduler this is normally a task control block.
175
 * The pxOwner parameter effectively creates a two way link between the list
176
 * item and its owner.
177
 *
178
 * @param pxList The list from which the owner of the head item is to be
179
 * returned.
180
 *
181
 * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY
182
 * \ingroup LinkedList
183
 */
184
#define listGET_OWNER_OF_HEAD_ENTRY( pxList )  ( ( pxList->uxNumberOfItems != ( unsigned portBASE_TYPE ) 0 ) ? ( (&( pxList->xListEnd ))->pxNext->pvOwner ) : ( NULL ) )
185
 
186
/*
187
 * Check to see if a list item is within a list.  The list item maintains a
188
 * "container" pointer that points to the list it is in.  All this macro does
189
 * is check to see if the container and the list match.
190
 *
191
 * @param pxList The list we want to know if the list item is within.
192
 * @param pxListItem The list item we want to know if is in the list.
193
 * @return pdTRUE is the list item is in the list, otherwise pdFALSE.
194
 * pointer against
195
 */
196
#define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) pxList )
197
 
198
/*
199
 * Must be called before a list is used!  This initialises all the members
200
 * of the list structure and inserts the xListEnd item into the list as a
201
 * marker to the back of the list.
202
 *
203
 * @param pxList Pointer to the list being initialised.
204
 *
205
 * \page vListInitialise vListInitialise
206
 * \ingroup LinkedList
207
 */
208
void vListInitialise( xList *pxList );
209
 
210
/*
211
 * Must be called before a list item is used.  This sets the list container to
212
 * null so the item does not think that it is already contained in a list.
213
 *
214
 * @param pxItem Pointer to the list item being initialised.
215
 *
216
 * \page vListInitialiseItem vListInitialiseItem
217
 * \ingroup LinkedList
218
 */
219
void vListInitialiseItem( xListItem *pxItem );
220
 
221
/*
222
 * Insert a list item into a list.  The item will be inserted into the list in
223
 * a position determined by its item value (descending item value order).
224
 *
225
 * @param pxList The list into which the item is to be inserted.
226
 *
227
 * @param pxNewListItem The item to that is to be placed in the list.
228
 *
229
 * \page vListInsert vListInsert
230
 * \ingroup LinkedList
231
 */
232
void vListInsert( xList *pxList, xListItem *pxNewListItem );
233
 
234
/*
235
 * Insert a list item into a list.  The item will be inserted in a position
236
 * such that it will be the last item within the list returned by multiple
237
 * calls to listGET_OWNER_OF_NEXT_ENTRY.
238
 *
239
 * The list member pvIndex is used to walk through a list.  Calling
240
 * listGET_OWNER_OF_NEXT_ENTRY increments pvIndex to the next item in the list.
241
 * Placing an item in a list using vListInsertEnd effectively places the item
242
 * in the list position pointed to by pvIndex.  This means that every other
243
 * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before
244
 * the pvIndex parameter again points to the item being inserted.
245
 *
246
 * @param pxList The list into which the item is to be inserted.
247
 *
248
 * @param pxNewListItem The list item to be inserted into the list.
249
 *
250
 * \page vListInsertEnd vListInsertEnd
251
 * \ingroup LinkedList
252
 */
253
void vListInsertEnd( xList *pxList, xListItem *pxNewListItem );
254
 
255
/*
256
 * Remove an item from a list.  The list item has a pointer to the list that
257
 * it is in, so only the list item need be passed into the function.
258
 *
259
 * @param vListRemove The item to be removed.  The item will remove itself from
260
 * the list pointed to by it's pxContainer parameter.
261
 *
262
 * \page vListRemove vListRemove
263
 * \ingroup LinkedList
264
 */
265
void vListRemove( xListItem *pxItemToRemove );
266
 
267
 
268
 
269
#endif
270
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.