Project

General

Profile

Download (7.35 KB) Statistics
| Branch: | Tag: | Revision:
1 633c646a henryk
/*
2
	FreeRTOS.org V4.2.1 - 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
	Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along
32
	with commercial development and support options.
33
	***************************************************************************
34
*/
35
36
/*
37
Changes from V1.2.0
38
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.
42
43
	+ prvListGetOwnerOfNextEntry() and prvListGetOwnerOfHeadEntry() have been
44
	  removed from the c file and added as macros to the h file.
45
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
48
	  is slightly faster.
49
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.
53
54
Changes from V2.0.0
55
56
	+ Double linked the lists to allow faster removal item removal.
57
58
Changes from V2.6.1
59
60
	+ Make use of the new portBASE_TYPE definition where ever appropriate.
61
62
Changes from V3.0.0
63
64
	+ API changes as described on the FreeRTOS.org WEB site.
65
66
Changes from V3.2.4
67
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.
70
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.
74
75
	+ Changed the volatile definitions of some structure members to clean up
76
	  the code where the list structures are used.
77
78
Changes from V4.0.4
79
80
	+ Optimised vListInsert() in the case when the wake time is the maximum 
81
	  tick count value.
82
*/
83
84
#include <stdlib.h>
85
#include "FreeRTOS.h"
86
#include "list.h"
87
88
/*-----------------------------------------------------------
89
 * PUBLIC LIST API documented in list.h
90
 *----------------------------------------------------------*/
91
92
void
93
vListInitialise (xList * pxList)
94
{
95
  /* The list structure contains a list item which is used to mark the
96
     end of the list.  To initialise the list the list end is inserted
97
     as the only list entry. */
98
  pxList->pxIndex = (xListItem *) & (pxList->xListEnd);
99
100
  /* The list end value is the highest possible value in the list to
101
     ensure it remains at the end of the list. */
102
  pxList->xListEnd.xItemValue = portMAX_DELAY;
103
104
  /* The list end next and previous pointers point to itself so we know
105
     when the list is empty. */
106
  pxList->xListEnd.pxNext = (xListItem *) & (pxList->xListEnd);
107
  pxList->xListEnd.pxPrevious = (xListItem *) & (pxList->xListEnd);
108
109
  pxList->uxNumberOfItems = 0;
110
}
111
112
/*-----------------------------------------------------------*/
113
114
void
115
vListInitialiseItem (xListItem * pxItem)
116
{
117
  /* Make sure the list item is not recorded as being on a list. */
118
  pxItem->pvContainer = NULL;
119
}
120
121
/*-----------------------------------------------------------*/
122
123
void
124
vListInsertEnd (xList * pxList, xListItem * pxNewListItem)
125
{
126
  volatile xListItem *pxIndex;
127
128
  /* Insert a new list item into pxList, but rather than sort the list,
129
     makes the new list item the last item to be removed by a call to
130
     pvListGetOwnerOfNextEntry.  This means it has to be the item pointed to by
131
     the pxIndex member. */
132
  pxIndex = pxList->pxIndex;
133
134
  pxNewListItem->pxNext = pxIndex->pxNext;
135
  pxNewListItem->pxPrevious = pxList->pxIndex;
136
  pxIndex->pxNext->pxPrevious = (volatile xListItem *) pxNewListItem;
137
  pxIndex->pxNext = (volatile xListItem *) pxNewListItem;
138
  pxList->pxIndex = (volatile xListItem *) pxNewListItem;
139
140
  /* Remember which list the item is in. */
141
  pxNewListItem->pvContainer = (void *) pxList;
142
143
  (pxList->uxNumberOfItems)++;
144
}
145
146
/*-----------------------------------------------------------*/
147
148
void
149
vListInsert (xList * pxList, xListItem * pxNewListItem)
150
{
151
  volatile xListItem *pxIterator;
152
  portTickType xValueOfInsertion;
153
154
  /* Insert the new list item into the list, sorted in ulListItem order. */
155
  xValueOfInsertion = pxNewListItem->xItemValue;
156
157
  /* If the list already contains a list item with the same item value then
158
     the new list item should be placed after it.  This ensures that TCB's which
159
     are stored in ready lists (all of which have the same ulListItem value)
160
     get an equal share of the CPU.  However, if the xItemValue is the same as 
161
     the back marker the iteration loop below will not end.  This means we need
162
     to guard against this by checking the value first and modifying the 
163
     algorithm slightly if necessary. */
164
  if (xValueOfInsertion == portMAX_DELAY)
165
    {
166
      pxIterator = pxList->xListEnd.pxPrevious;
167
    }
168
  else
169
    {
170
      for (pxIterator = (xListItem *) & (pxList->xListEnd);
171
	   pxIterator->pxNext->xItemValue <= xValueOfInsertion;
172
	   pxIterator = pxIterator->pxNext)
173
	{
174
	  /* There is nothing to do here, we are just iterating to the
175
	     wanted insertion position. */
176
	}
177
    }
178
179
  pxNewListItem->pxNext = pxIterator->pxNext;
180
  pxNewListItem->pxNext->pxPrevious = (volatile xListItem *) pxNewListItem;
181
  pxNewListItem->pxPrevious = pxIterator;
182
  pxIterator->pxNext = (volatile xListItem *) pxNewListItem;
183
184
  /* Remember which list the item is in.  This allows fast removal of the
185
     item later. */
186
  pxNewListItem->pvContainer = (void *) pxList;
187
188
  (pxList->uxNumberOfItems)++;
189
}
190
191
/*-----------------------------------------------------------*/
192
193
void
194
vListRemove (xListItem * pxItemToRemove)
195
{
196
  xList *pxList;
197
198
  pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
199
  pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
200
201
  /* The list item knows which list it is in.  Obtain the list from the list
202
     item. */
203
  pxList = (xList *) pxItemToRemove->pvContainer;
204
205
  /* Make sure the index is left pointing to a valid item. */
206
  if (pxList->pxIndex == pxItemToRemove)
207
    {
208
      pxList->pxIndex = pxItemToRemove->pxPrevious;
209
    }
210
211
  pxItemToRemove->pvContainer = NULL;
212
  (pxList->uxNumberOfItems)--;
213
}
214
215
/*-----------------------------------------------------------*/
Add picture from clipboard (Maximum size: 48.8 MB)