]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - os/7.4.2/include/os/list.h
Remove the name of the platform from the OS folder name
[pes-rpp/rpp-lib.git] / os / 7.4.2 / include / os / list.h
1 /*
2     FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
3
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     ***************************************************************************
8      *                                                                       *
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *
10      *    Complete, revised, and edited pdf reference manuals are also       *
11      *    available.                                                         *
12      *                                                                       *
13      *    Purchasing FreeRTOS documentation will not only help you, by       *
14      *    ensuring you get running as quickly as possible and with an        *
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *
16      *    the FreeRTOS project to continue with its mission of providing     *
17      *    professional grade, cross platform, de facto standard solutions    *
18      *    for microcontrollers - completely free of charge!                  *
19      *                                                                       *
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *
21      *                                                                       *
22      *    Thank you for using FreeRTOS, and thank you for your support!      *
23      *                                                                       *
24     ***************************************************************************
25
26
27     This file is part of the FreeRTOS distribution.
28
29     FreeRTOS is free software; you can redistribute it and/or modify it under
30     the terms of the GNU General Public License (version 2) as published by the
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
32
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
34     distribute a combined work that includes FreeRTOS without being obliged to
35     provide the source code for proprietary components outside of the FreeRTOS
36     kernel.
37
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
41     details. You should have received a copy of the GNU General Public License
42     and the FreeRTOS license exception along with FreeRTOS; if not it can be
43     viewed here: http://www.freertos.org/a00114.html and also obtained by
44     writing to Real Time Engineers Ltd., contact details for whom are available
45     on the FreeRTOS WEB site.
46
47     1 tab == 4 spaces!
48
49     ***************************************************************************
50      *                                                                       *
51      *    Having a problem?  Start by reading the FAQ "My application does   *
52      *    not run, what could be wrong?"                                     *
53      *                                                                       *
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *
55      *                                                                       *
56     ***************************************************************************
57
58
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions,
60     license and Real Time Engineers Ltd. contact details.
61
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new
64     fully thread aware and reentrant UDP/IP stack.
65
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
67     Integrity Systems, who sell the code with commercial support,
68     indemnification and middleware, under the OpenRTOS brand.
69
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
71     engineered and independently SIL3 certified version for use in safety and
72     mission critical applications that require provable dependability.
73 */
74
75 /*
76  * This is the list implementation used by the scheduler.  While it is tailored
77  * heavily for the schedulers needs, it is also available for use by
78  * application code.
79  *
80  * xLists can only store pointers to xListItems.  Each xListItem contains a
81  * numeric value (xItemValue).  Most of the time the lists are sorted in
82  * descending item value order.
83  *
84  * Lists are created already containing one list item.  The value of this
85  * item is the maximum possible that can be stored, it is therefore always at
86  * the end of the list and acts as a marker.  The list member pxHead always
87  * points to this marker - even though it is at the tail of the list.  This
88  * is because the tail contains a wrap back pointer to the true head of
89  * the list.
90  *
91  * In addition to it's value, each list item contains a pointer to the next
92  * item in the list (pxNext), a pointer to the list it is in (pxContainer)
93  * and a pointer to back to the object that contains it.  These later two
94  * pointers are included for efficiency of list manipulation.  There is
95  * effectively a two way link between the object containing the list item and
96  * the list item itself.
97  *
98  *
99  * \page ListIntroduction List Implementation
100  * \ingroup FreeRTOSIntro
101  */
102
103
104 #ifndef LIST_H
105 #define LIST_H
106
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110 /*
111  * Definition of the only type of object that a list can contain.
112  */
113 struct xLIST_ITEM
114 {
115     portTickType xItemValue;                /*< The value being listed.  In most cases this is used to sort the list in descending order. */
116     volatile struct xLIST_ITEM * pxNext;    /*< Pointer to the next xListItem in the list. */
117     volatile struct xLIST_ITEM * pxPrevious;/*< Pointer to the previous xListItem in the list. */
118     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. */
119     void * pvContainer;                     /*< Pointer to the list in which this list item is placed (if any). */
120 };
121 typedef struct xLIST_ITEM xListItem;        /* For some reason lint wants this as two separate definitions. */
122
123 struct xMINI_LIST_ITEM
124 {
125     portTickType xItemValue;
126     volatile struct xLIST_ITEM *pxNext;
127     volatile struct xLIST_ITEM *pxPrevious;
128 };
129 typedef struct xMINI_LIST_ITEM xMiniListItem;
130
131 /*
132  * Definition of the type of queue used by the scheduler.
133  */
134 typedef struct xLIST
135 {
136     volatile unsigned portBASE_TYPE uxNumberOfItems;
137     volatile xListItem * pxIndex;           /*< Used to walk through the list.  Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */
138     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. */
139 } xList;
140
141 /*
142  * Access macro to set the owner of a list item.  The owner of a list item
143  * is the object (usually a TCB) that contains the list item.
144  *
145  * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
146  * \ingroup LinkedList
147  */
148 #define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner )      ( pxListItem )->pvOwner = ( void * ) ( pxOwner )
149
150 /*
151  * Access macro to get the owner of a list item.  The owner of a list item
152  * is the object (usually a TCB) that contains the list item.
153  *
154  * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
155  * \ingroup LinkedList
156  */
157 #define listGET_LIST_ITEM_OWNER( pxListItem )       ( pxListItem )->pvOwner
158
159 /*
160  * Access macro to set the value of the list item.  In most cases the value is
161  * used to sort the list in descending order.
162  *
163  * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE
164  * \ingroup LinkedList
165  */
166 #define listSET_LIST_ITEM_VALUE( pxListItem, xValue )       ( pxListItem )->xItemValue = ( xValue )
167
168 /*
169  * Access macro to retrieve the value of the list item.  The value can
170  * represent anything - for example a the priority of a task, or the time at
171  * which a task should be unblocked.
172  *
173  * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
174  * \ingroup LinkedList
175  */
176 #define listGET_LIST_ITEM_VALUE( pxListItem )               ( ( pxListItem )->xItemValue )
177
178 /*
179  * Access macro the retrieve the value of the list item at the head of a given
180  * list.
181  *
182  * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
183  * \ingroup LinkedList
184  */
185 #define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList )          ( (&( ( pxList )->xListEnd ))->pxNext->xItemValue )
186
187 /*
188  * Access macro to determine if a list contains any items.  The macro will
189  * only have the value true if the list is empty.
190  *
191  * \page listLIST_IS_EMPTY listLIST_IS_EMPTY
192  * \ingroup LinkedList
193  */
194 #define listLIST_IS_EMPTY( pxList )             ( ( pxList )->uxNumberOfItems == ( unsigned portBASE_TYPE ) 0 )
195
196 /*
197  * Access macro to return the number of items in the list.
198  */
199 #define listCURRENT_LIST_LENGTH( pxList )       ( ( pxList )->uxNumberOfItems )
200
201 /*
202  * Access function to obtain the owner of the next entry in a list.
203  *
204  * The list member pxIndex is used to walk through a list.  Calling
205  * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list
206  * and returns that entries pxOwner parameter.  Using multiple calls to this
207  * function it is therefore possible to move through every item contained in
208  * a list.
209  *
210  * The pxOwner parameter of a list item is a pointer to the object that owns
211  * the list item.  In the scheduler this is normally a task control block.
212  * The pxOwner parameter effectively creates a two way link between the list
213  * item and its owner.
214  *
215  * @param pxList The list from which the next item owner is to be returned.
216  *
217  * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY
218  * \ingroup LinkedList
219  */
220 #define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList )                                    \
221 {                                                                                       \
222 xList * const pxConstList = ( pxList );                                                 \
223     /* Increment the index to the next item and return the item, ensuring */            \
224     /* we don't return the marker used at the end of the list.  */                      \
225     ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext;                        \
226     if( ( pxConstList )->pxIndex == ( xListItem * ) &( ( pxConstList )->xListEnd ) )    \
227     {                                                                                   \
228         ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext;                    \
229     }                                                                                   \
230     ( pxTCB ) = ( pxConstList )->pxIndex->pvOwner;                                      \
231 }
232
233
234 /*
235  * Access function to obtain the owner of the first entry in a list.  Lists
236  * are normally sorted in ascending item value order.
237  *
238  * This function returns the pxOwner member of the first item in the list.
239  * The pxOwner parameter of a list item is a pointer to the object that owns
240  * the list item.  In the scheduler this is normally a task control block.
241  * The pxOwner parameter effectively creates a two way link between the list
242  * item and its owner.
243  *
244  * @param pxList The list from which the owner of the head item is to be
245  * returned.
246  *
247  * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY
248  * \ingroup LinkedList
249  */
250 #define listGET_OWNER_OF_HEAD_ENTRY( pxList )  ( (&( ( pxList )->xListEnd ))->pxNext->pvOwner )
251
252 /*
253  * Check to see if a list item is within a list.  The list item maintains a
254  * "container" pointer that points to the list it is in.  All this macro does
255  * is check to see if the container and the list match.
256  *
257  * @param pxList The list we want to know if the list item is within.
258  * @param pxListItem The list item we want to know if is in the list.
259  * @return pdTRUE is the list item is in the list, otherwise pdFALSE.
260  * pointer against
261  */
262 #define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) )
263
264 /*
265  * Return the list a list item is contained within (referenced from).
266  *
267  * @param pxListItem The list item being queried.
268  * @return A pointer to the xList object that references the pxListItem
269  */
270 #define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pvContainer )
271
272 /*
273  * This provides a crude means of knowing if a list has been initialised, as
274  * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise()
275  * function.
276  */
277 #define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY )
278
279 /*
280  * Must be called before a list is used!  This initialises all the members
281  * of the list structure and inserts the xListEnd item into the list as a
282  * marker to the back of the list.
283  *
284  * @param pxList Pointer to the list being initialised.
285  *
286  * \page vListInitialise vListInitialise
287  * \ingroup LinkedList
288  */
289 void vListInitialise( xList *pxList );
290
291 /*
292  * Must be called before a list item is used.  This sets the list container to
293  * null so the item does not think that it is already contained in a list.
294  *
295  * @param pxItem Pointer to the list item being initialised.
296  *
297  * \page vListInitialiseItem vListInitialiseItem
298  * \ingroup LinkedList
299  */
300 void vListInitialiseItem( xListItem *pxItem );
301
302 /*
303  * Insert a list item into a list.  The item will be inserted into the list in
304  * a position determined by its item value (descending item value order).
305  *
306  * @param pxList The list into which the item is to be inserted.
307  *
308  * @param pxNewListItem The item to that is to be placed in the list.
309  *
310  * \page vListInsert vListInsert
311  * \ingroup LinkedList
312  */
313 void vListInsert( xList *pxList, xListItem *pxNewListItem );
314
315 /*
316  * Insert a list item into a list.  The item will be inserted in a position
317  * such that it will be the last item within the list returned by multiple
318  * calls to listGET_OWNER_OF_NEXT_ENTRY.
319  *
320  * The list member pvIndex is used to walk through a list.  Calling
321  * listGET_OWNER_OF_NEXT_ENTRY increments pvIndex to the next item in the list.
322  * Placing an item in a list using vListInsertEnd effectively places the item
323  * in the list position pointed to by pvIndex.  This means that every other
324  * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before
325  * the pvIndex parameter again points to the item being inserted.
326  *
327  * @param pxList The list into which the item is to be inserted.
328  *
329  * @param pxNewListItem The list item to be inserted into the list.
330  *
331  * \page vListInsertEnd vListInsertEnd
332  * \ingroup LinkedList
333  */
334 void vListInsertEnd( xList *pxList, xListItem *pxNewListItem );
335
336 /*
337  * Remove an item from a list.  The list item has a pointer to the list that
338  * it is in, so only the list item need be passed into the function.
339  *
340  * @param uxListRemove The item to be removed.  The item will remove itself from
341  * the list pointed to by it's pxContainer parameter.
342  *
343  * @return The number of items that remain in the list after the list item has
344  * been removed.
345  *
346  * \page uxListRemove uxListRemove
347  * \ingroup LinkedList
348  */
349 unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove );
350
351 #ifdef __cplusplus
352 }
353 #endif
354
355 #endif
356