2 FreeRTOS.org V4.8.0 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
53 + Removed the volatile modifier from the function parameters. This was
\r
54 only ever included to prevent compiler warnings. Now warnings are
\r
55 removed by casting parameters where the calls are made.
\r
57 + prvListGetOwnerOfNextEntry() and prvListGetOwnerOfHeadEntry() have been
\r
58 removed from the c file and added as macros to the h file.
\r
60 + uxNumberOfItems has been added to the list structure. This removes the
\r
61 need for a pointer comparison when checking if a list is empty, and so
\r
64 + Removed the NULL check in vListRemove(). This makes the call faster but
\r
65 necessitates any application code utilising the list implementation to
\r
66 ensure NULL pointers are not passed.
\r
70 + Double linked the lists to allow faster removal item removal.
\r
74 + Make use of the new portBASE_TYPE definition where ever appropriate.
\r
78 + API changes as described on the FreeRTOS.org WEB site.
\r
82 + Removed the pxHead member of the xList structure. This always pointed
\r
83 to the same place so has been removed to free a few bytes of RAM.
\r
85 + Introduced the xMiniListItem structure that does not include the
\r
86 xListItem members that are not required by the xListEnd member of a list.
\r
87 Again this was done to reduce RAM usage.
\r
89 + Changed the volatile definitions of some structure members to clean up
\r
90 the code where the list structures are used.
\r
94 + Optimised vListInsert() in the case when the wake time is the maximum
\r
99 #include "FreeRTOS.h"
\r
102 /*-----------------------------------------------------------
\r
103 * PUBLIC LIST API documented in list.h
\r
104 *----------------------------------------------------------*/
\r
106 void vListInitialise( xList *pxList )
\r
108 /* The list structure contains a list item which is used to mark the
\r
109 end of the list. To initialise the list the list end is inserted
\r
110 as the only list entry. */
\r
111 pxList->pxIndex = ( xListItem * ) &( pxList->xListEnd );
\r
113 /* The list end value is the highest possible value in the list to
\r
114 ensure it remains at the end of the list. */
\r
115 pxList->xListEnd.xItemValue = portMAX_DELAY;
\r
117 /* The list end next and previous pointers point to itself so we know
\r
118 when the list is empty. */
\r
119 pxList->xListEnd.pxNext = ( xListItem * ) &( pxList->xListEnd );
\r
120 pxList->xListEnd.pxPrevious = ( xListItem * ) &( pxList->xListEnd );
\r
122 pxList->uxNumberOfItems = 0;
\r
124 /*-----------------------------------------------------------*/
\r
126 void vListInitialiseItem( xListItem *pxItem )
\r
128 /* Make sure the list item is not recorded as being on a list. */
\r
129 pxItem->pvContainer = NULL;
\r
131 /*-----------------------------------------------------------*/
\r
133 void vListInsertEnd( xList *pxList, xListItem *pxNewListItem )
\r
135 volatile xListItem * pxIndex;
\r
137 /* Insert a new list item into pxList, but rather than sort the list,
\r
138 makes the new list item the last item to be removed by a call to
\r
139 pvListGetOwnerOfNextEntry. This means it has to be the item pointed to by
\r
140 the pxIndex member. */
\r
141 pxIndex = pxList->pxIndex;
\r
143 pxNewListItem->pxNext = pxIndex->pxNext;
\r
144 pxNewListItem->pxPrevious = pxList->pxIndex;
\r
145 pxIndex->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;
\r
146 pxIndex->pxNext = ( volatile xListItem * ) pxNewListItem;
\r
147 pxList->pxIndex = ( volatile xListItem * ) pxNewListItem;
\r
149 /* Remember which list the item is in. */
\r
150 pxNewListItem->pvContainer = ( void * ) pxList;
\r
152 ( pxList->uxNumberOfItems )++;
\r
154 /*-----------------------------------------------------------*/
\r
156 void vListInsert( xList *pxList, xListItem *pxNewListItem )
\r
158 volatile xListItem *pxIterator;
\r
159 portTickType xValueOfInsertion;
\r
161 /* Insert the new list item into the list, sorted in ulListItem order. */
\r
162 xValueOfInsertion = pxNewListItem->xItemValue;
\r
164 /* If the list already contains a list item with the same item value then
\r
165 the new list item should be placed after it. This ensures that TCB's which
\r
166 are stored in ready lists (all of which have the same ulListItem value)
\r
167 get an equal share of the CPU. However, if the xItemValue is the same as
\r
168 the back marker the iteration loop below will not end. This means we need
\r
169 to guard against this by checking the value first and modifying the
\r
170 algorithm slightly if necessary. */
\r
171 if( xValueOfInsertion == portMAX_DELAY )
\r
173 pxIterator = pxList->xListEnd.pxPrevious;
\r
177 for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext )
\r
179 /* There is nothing to do here, we are just iterating to the
\r
180 wanted insertion position. */
\r
184 pxNewListItem->pxNext = pxIterator->pxNext;
\r
185 pxNewListItem->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;
\r
186 pxNewListItem->pxPrevious = pxIterator;
\r
187 pxIterator->pxNext = ( volatile xListItem * ) pxNewListItem;
\r
189 /* Remember which list the item is in. This allows fast removal of the
\r
191 pxNewListItem->pvContainer = ( void * ) pxList;
\r
193 ( pxList->uxNumberOfItems )++;
\r
195 /*-----------------------------------------------------------*/
\r
197 void vListRemove( xListItem *pxItemToRemove )
\r
201 pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
\r
202 pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
\r
204 /* The list item knows which list it is in. Obtain the list from the list
\r
206 pxList = ( xList * ) pxItemToRemove->pvContainer;
\r
208 /* Make sure the index is left pointing to a valid item. */
\r
209 if( pxList->pxIndex == pxItemToRemove )
\r
211 pxList->pxIndex = pxItemToRemove->pxPrevious;
\r
214 pxItemToRemove->pvContainer = NULL;
\r
215 ( pxList->uxNumberOfItems )--;
\r
217 /*-----------------------------------------------------------*/
\r