root/webserver/example/freeRTOS/Source/include/list.h

Revision 14, 11.7 kB (checked in by phil, 15 years ago)

added unmodified FreeRTOS package V5.4.1 with only web srv demo source for LPC2368 for CrossWorks?

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