2 FreeRTOS.org V4.4.0 - Copyright (C) 2003-2007 Richard Barry.
4 This file is part of the FreeRTOS.org distribution.
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.
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.
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
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
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.
31 Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along
32 with commercial development and support options.
33 ***************************************************************************
39 + Removed the volatile modifier from the function parameters. This was
40 only ever included to prevent compiler warnings. Now warnings are
41 removed by casting parameters where the calls are made.
43 + prvListGetOwnerOfNextEntry() and prvListGetOwnerOfHeadEntry() have been
44 removed from the c file and added as macros to the h file.
46 + uxNumberOfItems has been added to the list structure. This removes the
47 need for a pointer comparison when checking if a list is empty, and so
50 + Removed the NULL check in vListRemove(). This makes the call faster but
51 necessitates any application code utilising the list implementation to
52 ensure NULL pointers are not passed.
56 + Double linked the lists to allow faster removal item removal.
60 + Make use of the new portBASE_TYPE definition where ever appropriate.
64 + API changes as described on the FreeRTOS.org WEB site.
68 + Removed the pxHead member of the xList structure. This always pointed
69 to the same place so has been removed to free a few bytes of RAM.
71 + Introduced the xMiniListItem structure that does not include the
72 xListItem members that are not required by the xListEnd member of a list.
73 Again this was done to reduce RAM usage.
75 + Changed the volatile definitions of some structure members to clean up
76 the code where the list structures are used.
80 + Optimised vListInsert() in the case when the wake time is the maximum
88 /*-----------------------------------------------------------
89 * PUBLIC LIST API documented in list.h
90 *----------------------------------------------------------*/
92 void vListInitialise( xList *pxList )
94 /* The list structure contains a list item which is used to mark the
95 end of the list. To initialise the list the list end is inserted
96 as the only list entry. */
97 pxList->pxIndex = ( xListItem * ) &( pxList->xListEnd );
99 /* The list end value is the highest possible value in the list to
100 ensure it remains at the end of the list. */
101 pxList->xListEnd.xItemValue = portMAX_DELAY;
103 /* The list end next and previous pointers point to itself so we know
104 when the list is empty. */
105 pxList->xListEnd.pxNext = ( xListItem * ) &( pxList->xListEnd );
106 pxList->xListEnd.pxPrevious = ( xListItem * ) &( pxList->xListEnd );
108 pxList->uxNumberOfItems = 0;
110 /*-----------------------------------------------------------*/
112 void vListInitialiseItem( xListItem *pxItem )
114 /* Make sure the list item is not recorded as being on a list. */
115 pxItem->pvContainer = NULL;
117 /*-----------------------------------------------------------*/
119 void vListInsertEnd( xList *pxList, xListItem *pxNewListItem )
121 volatile xListItem * pxIndex;
123 /* Insert a new list item into pxList, but rather than sort the list,
124 makes the new list item the last item to be removed by a call to
125 pvListGetOwnerOfNextEntry. This means it has to be the item pointed to by
126 the pxIndex member. */
127 pxIndex = pxList->pxIndex;
129 pxNewListItem->pxNext = pxIndex->pxNext;
130 pxNewListItem->pxPrevious = pxList->pxIndex;
131 pxIndex->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;
132 pxIndex->pxNext = ( volatile xListItem * ) pxNewListItem;
133 pxList->pxIndex = ( volatile xListItem * ) pxNewListItem;
135 /* Remember which list the item is in. */
136 pxNewListItem->pvContainer = ( void * ) pxList;
138 ( pxList->uxNumberOfItems )++;
140 /*-----------------------------------------------------------*/
142 void vListInsert( xList *pxList, xListItem *pxNewListItem )
144 volatile xListItem *pxIterator;
145 portTickType xValueOfInsertion;
147 /* Insert the new list item into the list, sorted in ulListItem order. */
148 xValueOfInsertion = pxNewListItem->xItemValue;
150 /* If the list already contains a list item with the same item value then
151 the new list item should be placed after it. This ensures that TCB's which
152 are stored in ready lists (all of which have the same ulListItem value)
153 get an equal share of the CPU. However, if the xItemValue is the same as
154 the back marker the iteration loop below will not end. This means we need
155 to guard against this by checking the value first and modifying the
156 algorithm slightly if necessary. */
157 if( xValueOfInsertion == portMAX_DELAY )
159 pxIterator = pxList->xListEnd.pxPrevious;
163 for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext )
165 /* There is nothing to do here, we are just iterating to the
166 wanted insertion position. */
170 pxNewListItem->pxNext = pxIterator->pxNext;
171 pxNewListItem->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;
172 pxNewListItem->pxPrevious = pxIterator;
173 pxIterator->pxNext = ( volatile xListItem * ) pxNewListItem;
175 /* Remember which list the item is in. This allows fast removal of the
177 pxNewListItem->pvContainer = ( void * ) pxList;
179 ( pxList->uxNumberOfItems )++;
181 /*-----------------------------------------------------------*/
183 void vListRemove( xListItem *pxItemToRemove )
187 pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
188 pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
190 /* The list item knows which list it is in. Obtain the list from the list
192 pxList = ( xList * ) pxItemToRemove->pvContainer;
194 /* Make sure the index is left pointing to a valid item. */
195 if( pxList->pxIndex == pxItemToRemove )
197 pxList->pxIndex = pxItemToRemove->pxPrevious;
200 pxItemToRemove->pvContainer = NULL;
201 ( pxList->uxNumberOfItems )--;
203 /*-----------------------------------------------------------*/