blob: 59fcb0840d9cf5027e4dcbe482d79ceaf45ce5da [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Jeff Johnson32d95a32012-09-10 13:15:23 -07002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -07003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22#if !defined( __VOS_LIST_H )
23#define __VOS_LIST_H
24
25/**=========================================================================
26
27 \file vos_list.h
28
29 \brief virtual Operating System Services (vOSS) List APIs
30
31 Definitions for vOSS Linked Lists API
32
33 Lists are implemented as a doubly linked list. An item in a list can
34 be of any type as long as the datatype contains a field of type
35 vos_link_t.
36
37 In general, a list is a doubly linked list of items with a pointer
38 to the front of the list and a pointer to the end of the list. The
39 list items contain a forward and back link.
40
41 List Nodes
42 ============= ===========================
43 +-------+
44 | Front |------------->+---------+ +---------+
45 +-------+ | Next |---->| Next |---->NULL
46 | Back |-+ +---------+ +---------+
47 +-------+ | NULL<----| Prev |<----| Prev |
48 | +---------+ +---------+
49 | |User Data| |User Data|
50 | +---------+ +---------+
51 | ^
52 | |
53 +---------------------------------+
54
55 This linked list API is implemented with appropriate locking
56 mechanisms to assure operations on the list are thread safe.
57
58 Copyright 2008 (c) Qualcomm, Incorporated. All Rights Reserved.
59
60 Qualcomm Confidential and Proprietary.
61
62 ========================================================================*/
63
64/* $Header$ */
65
66/*--------------------------------------------------------------------------
67 Include Files
68 ------------------------------------------------------------------------*/
69#include <vos_types.h>
70#include <vos_status.h>
71#include <i_vos_list.h>
72
73/*--------------------------------------------------------------------------
74 Preprocessor definitions and constants
75 ------------------------------------------------------------------------*/
76
77/*--------------------------------------------------------------------------
78 Type declarations
79 ------------------------------------------------------------------------*/
80
81/*-------------------------------------------------------------------------
82 Function declarations and documenation
83 ------------------------------------------------------------------------*/
84
85/**---------------------------------------------------------------------------
86
87 \brief vos_list_init() - initialize a vOS Linked List
88
89 The \a vos_list_init() function initializes the specified linked list
90 'object'. Upon successful initialization, the state of the list
91 becomes initialized and available for use through the other vos_list_xxx
92 APIs.
93
94 A list must be initialized by calling vos_list_init() before it
95 may be used in any other lock functions.
96
97 Attempting to initialize an already initialized list results in
98 a failure.
99
100 \param pList - pointer to the opaque list object to initialize
101
102 \return VOS_STATUS_SUCCESS - list was successfully initialized and
103 is ready to be used.
104
105 VOS_STATUS_E_RESOURCES - System resources (other than memory)
106 are unavailable to initilize the list
107
108 VOS_STATUS_E_NOMEM - insufficient memory exists to initialize
109 the list
110
111 VOS_STATUS_E_BUSY - The implementation has detected an attempt
112 to reinitialize the object referenced by list, a previously
113 initialized, but not yet destroyed, list.
114
115 VOS_STATUS_E_FAULT - pList is an invalid pointer.
116
117 \sa vos_list_destroy()
118
119 --------------------------------------------------------------------------*/
120VOS_STATUS vos_list_init( vos_list_t *pList );
121
122
123/**-------------------------------------------------------------------------
124
125 \brief vos_list_destroy() - Destroy a vOSS List
126
127 The \a vos_list_destroy() function shall destroy the list object
128 referenced by pList. After a successful return from \a vos_list_destroy()
129 the list object becomes, in effect, uninitialized.
130
131 A destroyed lock object can be reinitialized using vos_list_init();
132 the results of otherwise referencing the object after it has been destroyed
133 are undefined. Calls to vOSS list functions to manipulate the list such
134 will fail if the list or has not been initialized or is destroyed.
135 Therefore, don't use the list after it has been destroyed until it has
136 been re-initialized.
137
138 \param pLlist - pointer to the list object to be destroyed.
139
140 \return VOS_STATUS_SUCCESS - list was successfully destroyed.
141
142 VOS_STATUS_E_BUSY - The implementation has detected an attempt
143 to destroy the object referenced by pList that is still has
144 nodes. The list must be empty before it can be destroyed.
145
146 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
147 initialized list object.
148
149 VOS_STATUS_E_FAULT - pList is an invalid pointer.
150 \sa
151
152 ----------------------------------------------------------------------------*/
153VOS_STATUS vos_list_destroy( vos_list_t *pList );
154
155/*--------------------------------------------------------------------------
156
157 \brief vos_list_lock() - Lock a vOSS List
158
159 The \a vos_list_lock() function shall lock the list object to prevent
160 other tasks from operating on this list. The list remains locked until
161 a call to vos_list_unlock() is made.
162
163 Each list function already operate within a critical section.
164 However it is sometimes necessary to lock a list over a series of list
165 function calls.
166
167 For example, when one needs to search a node on a list and insert another
168 node after it, one would want to lock this list for the entire process
169 in case another task attempts to manipulate this list.
170
171 \param pLlist - pointer to the list object to be locked.
172
173 \return VOS_STATUS_SUCCESS - list was successfully locked.
174
175 VOS_STATUS_E_FAULT - pList is an invalid pointer.
176
177 \sa vos_list_unlock()
178
179 ----------------------------------------------------------------------------*/
180VOS_STATUS vos_list_lock( vos_list_t *pList );
181
182/*--------------------------------------------------------------------------
183
184 \brief vos_list_unlock() - Unlock a vOSS List
185
186 The \a vos_list_unlock() function shall unlock the list object to allow
187 other tasks to use this list. This function is only called when
188 the vos_list_lock() is previously called in the current task.
189
190 \param pLlist - pointer to the list object to be unlocked.
191
192 \return VOS_STATUS_SUCCESS - list was successfully unlocked.
193
194 VOS_STATUS_E_FAULT - pList is an invalid pointer.
195
196 \sa vos_list_lock()
197
198 ----------------------------------------------------------------------------*/
199VOS_STATUS vos_list_unlock( vos_list_t *pList );
200
201
202/**---------------------------------------------------------------------------
203
204 \brief vos_list_insert_front() - insert node at front of a linked list
205
206 The vos_list_insert_front() API will insert a node at the front of
207 a properly initialized vOS List object.
208
209 \param pList - Pointer to list object where the node will be inserted
210
211 \param pNode - Pointer to the list node to be inserted into the list.
212
213 \return VOS_STATUS_SUCCESS - list node was successfully inserted onto
214 the front of the list.
215
216 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
217 initialized list object.
218
219 VOS_STATUS_E_FAULT - pList is an invalid pointer or pNode is an
220 invalid pointer.
221
222 \sa
223
224 --------------------------------------------------------------------------*/
225VOS_STATUS vos_list_insert_front( vos_list_t *pList, vos_list_node_t *pNode );
226
227
228/**---------------------------------------------------------------------------
229
230 \brief vos_list_insert_back() - insert node at back of a linked list
231
232 The vos_list_insert_back() API will insert a node at the back of
233 a properly initialized vOS List object.
234
235 \param pList - Pointer to list object where the node will be inserted
236
237 \param pNode - Pointer to the list node to be inserted into the list.
238
239 \return VOS_STATUS_SUCCESS - list node was successfully inserted onto
240 the back of the list.
241
242 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
243 initialized list object.
244
245 VOS_STATUS_E_FAULT - pList is an invalid pointer or pNode is an
246 invalid pointer.
247
248 \sa
249
250 --------------------------------------------------------------------------*/
251VOS_STATUS vos_list_insert_back( vos_list_t *pList, vos_list_node_t *pNode );
252
253/**---------------------------------------------------------------------------
254
255 \brief vos_list_insert_back_size() - insert node at back of a linked list and
256 return the size AFTER the enqueue. This size is determined in a race free
257 manner i.e. while the list is locked for the enqueue operation
258
259 The vos_list_insert_back_size() API will insert a node at the back of
260 a properly initialized vOS List object.
261
262 \param pList - Pointer to list object where the node will be inserted
263
264 \param pNode - Pointer to the list node to be inserted into the list.
265
266 \param pSize - Pointer to a size variable, where the size of the
267 list will be returned.
268
269 \return VOS_STATUS_SUCCESS - list node was successfully inserted onto
270 the back of the list.
271
272 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
273 initialized list object.
274
275 VOS_STATUS_E_FAULT - pList is an invalid pointer or pNode is an
276 invalid pointer.
277
278 \sa
279
280 --------------------------------------------------------------------------*/
281VOS_STATUS vos_list_insert_back_size( vos_list_t *pList, vos_list_node_t *pNode, v_SIZE_t *pSize );
282
283
284/**---------------------------------------------------------------------------
285
286 \brief vos_list_remove_front() - remove node at front of a linked list
287
288 The vos_list_remove_front() API will remove a node at the front of
289 a properly initialized vOS List object.
290
291 \param pList - Pointer to list object where the node will be removed
292
293 \param ppNode - Pointer to a pointer to the list node to be removed
294 from the list.
295
296 \return VOS_STATUS_SUCCESS - list node was successfully removed from
297 the front of the list.
298
299 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
300 initialized list object.
301
302 VOS_STATUS_E_EMPTY - The specified is empty so nodes cannot be
303 removed.
304
305 VOS_STATUS_E_FAULT - pList is an invalid pointer or ppNode is an
306 invalid pointer.
307
308 \sa vos_list_remove_back()
309
310 --------------------------------------------------------------------------*/
311VOS_STATUS vos_list_remove_front( vos_list_t *pList, vos_list_node_t **ppNode );
312
313
314/**---------------------------------------------------------------------------
315
316 \brief vos_list_remove_back() - remove node at back of a linked list
317
318 The vos_list_remove_back() API will remove a node at the back of
319 a properly initialized vOS List object.
320
321 \param pList - Pointer to list object where the node will be removed
322
323 \param ppNode - Pointer to a pointer to the list node to be removed
324 from the list.
325
326 \return VOS_STATUS_SUCCESS - list node was successfully removed from
327 the back of the list.
328
329 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
330 initialized list object.
331
332 VOS_STATUS_E_EMPTY - The specified is empty so nodes cannot be
333 removed.
334
335 VOS_STATUS_E_FAULT - pList is an invalid pointer or ppNode is an
336 invalid pointer.
337
338 \sa vos_list_remove_back()
339
340 --------------------------------------------------------------------------*/
341VOS_STATUS vos_list_remove_back( vos_list_t *pList, vos_list_node_t **ppNode );
342
343
344/*----------------------------------------------------------------------------
345
346 \brief vos_list_size() - return the size of of a linked list
347
348 The vos_list_size() API will return the number of nodes on the
349 given vOS List object.
350
351 \param pList - Pointer to list object where the node will be counted
352
353 \param pSize - Pointer to a size variable, where the size of the
354 list will be returned.
355
356 \return VOS_STATUS_SUCCESS - list size of the properly initialized
357 vos list object has been returned.
358
359 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
360 initialized list object.
361
362 VOS_STATUS_E_FAULT - pList or pSize are not valid pointers
363
364 \sa
365
366 --------------------------------------------------------------------------*/
367VOS_STATUS vos_list_size( vos_list_t *pList, v_SIZE_t *pSize );
368
369/**---------------------------------------------------------------------------
370
371 \brief vos_list_peek_front() - peek at the node at front of a linked list
372
373 The vos_list_peek_front() API will return a pointer to the node at the
374 front of a properly initialized vOS List object. The node will *not* be
375 removed from the list.
376
377 \param pList - Pointer to list object of the list to be 'peeked'
378
379 \param ppNode - Pointer to a pointer to the list node that exists at
380 the front of the list.
381
382 \return VOS_STATUS_SUCCESS - list node at the front of the list was
383 successfully returned.
384
385 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
386 initialized list object.
387
388 VOS_STATUS_E_EMPTY - The specified is empty so nodes cannot be
389 removed.
390
391 VOS_STATUS_E_FAULT - pList or or ppNode is an invalid pointer.
392
393 \sa vos_list_remove_back()
394
395 --------------------------------------------------------------------------*/
396VOS_STATUS vos_list_peek_front( vos_list_t *pList, vos_list_node_t **ppNode );
397
398/**---------------------------------------------------------------------------
399
400 \brief vos_list_peek_back() - peek at the node at back of a linked list
401
402 The vos_list_peek_back() API will return a pointer to the node at the
403 back of a properly initialized vOS List object. The node will *not* be
404 removed from the list.
405
406 \param pList - Pointer to list object of the list to be 'peeked'
407
408 \param ppNode - Pointer to a pointer to the list node that exists at
409 the back of the list.
410
411 \return VOS_STATUS_SUCCESS - list node at the back of the list was
412 successfully returned.
413
414 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
415 initialized list object.
416
417 VOS_STATUS_E_EMPTY - The specified is empty so nodes cannot be
418 removed.
419
420 VOS_STATUS_E_FAULT - pList or or ppNode is an invalid pointer.
421
422 \sa vos_list_peek_back(), vos_list_remove_back(), vos_list_peek_front(),
423 vos_list_remove_front()
424
425 --------------------------------------------------------------------------*/
426VOS_STATUS vos_list_peek_back( vos_list_t *pList, vos_list_node_t **ppNode );
427
428/**---------------------------------------------------------------------------
429
430 \brief vos_list_peek_next() - peek at the node after the specified node
431
432 The vos_list_peek_next() API will return a pointer to the node following the
433 specified node on a properly initialized vOS List object. The node will
434 *not* be removed from the list.
435
436 \param pList - Pointer to list object of the list to be 'peeked'
437
438 \param pNode - Pointer to the node that is being 'peeked'
439
440 \param ppNode - Pointer to a pointer to the list node that follows the
441 pNode node on the list.
442
443 \return VOS_STATUS_SUCCESS - list node following pNode on the properly
444 initialized list is successfully returned.
445
446 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
447 initialized list object.
448
449 VOS_STATUS_E_EMPTY - The specified is empty so nodes cannot be
450 removed.
451
452 VOS_STATUS_E_FAULT - pList, pNode or ppNode is an invalid pointer.
453
454 \sa vos_list_remove_back()
455
456 --------------------------------------------------------------------------*/
457VOS_STATUS vos_list_peek_next( vos_list_t *pList, vos_list_node_t *pNode,
458 vos_list_node_t **ppNode );
459
460/**---------------------------------------------------------------------------
461
462 \brief vos_list_peek_prev() - peek at the node before the specified node
463
464 The vos_list_peek_prev() API will return a pointer to the node before the
465 specified node on a properly initialized vOS List object. The node will
466 *not* be removed from the list.
467
468 \param pList - Pointer to list object of the list to be 'peeked'
469
470 \param pNode - Pointer to the node that is being 'peeked'
471
472 \param ppNode - Pointer to a pointer to the list node before the
473 pNode node on the list.
474
475 \return VOS_STATUS_SUCCESS - list node before pNode on the properly
476 initialized list is successfully returned.
477
478 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
479 initialized list object.
480
481 VOS_STATUS_E_EMPTY - The specified is empty so nodes cannot be
482 removed.
483
484 VOS_STATUS_E_FAULT - pList, pNode or ppNode is an invalid pointer.
485
486 \sa vos_list_remove_back()
487
488 --------------------------------------------------------------------------*/
489VOS_STATUS vos_list_peek_prev( vos_list_t *pList, vos_list_node_t *pNode,
490 vos_list_node_t **ppNode );
491
492/**---------------------------------------------------------------------------
493
494 \brief vos_list_insert_before() - insert node at front of a specified
495 list node
496
497 The vos_list_insert_before() API will insert a node onto a properly
498 initialized vOS List object in front of the specified list node.
499
500 \param pList - Pointer to list object where the node will be inserted
501
502 \param pNodeToInsert - Pointer to the list node to be inserted into the list.
503
504 \param pNode - Pointer to the list node where pNodeToInsert will be inserted
505 in front of.
506
507 \return VOS_STATUS_SUCCESS - list node was successfully inserted onto
508 the front of the list.
509
510 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
511 initialized list object.
512
513 VOS_STATUS_E_FAULT - pList, pNodeToInsert, or pNode are
514 invalid pointer(s)
515
516 \sa
517
518 --------------------------------------------------------------------------*/
519VOS_STATUS vos_list_insert_before( vos_list_t *pList, vos_list_node_t *pNodeToInsert,
520 vos_list_node_t *pNode );
521
522/**---------------------------------------------------------------------------
523
524 \brief vos_list_insert_after() - insert node behind a specified list node
525
526 The vos_list_insert_after() API will insert a node onto a properly
527 initialized vOS List object after the specified list node.
528
529 \param pList - Pointer to list object where the node will be inserted
530
531 \param pNodeToInsert - Pointer to the list node to be inserted into the list.
532
533 \param pNode - Pointer to the list node where pNodeToInsert will be inserted
534 after.
535
536 \return VOS_STATUS_SUCCESS - list node was successfully inserted onto
537 the front of the list.
538
539 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
540 initialized list object.
541
542 VOS_STATUS_E_FAULT - pList, pNodeToInsert, or pNode are
543 invalid pointer(s)
544
545 \sa
546
547 --------------------------------------------------------------------------*/
548VOS_STATUS vos_list_insert_after( vos_list_t *pList, vos_list_node_t *pNodeToInsert,
549 vos_list_node_t *pNode );
550
551
552/**---------------------------------------------------------------------------
553
554 \brief vos_list_remove_node() - remove specified node from vOS list list
555
556 The vos_list_remove_node() API will remove a specified node from the
557 properly initialized vOS List object.
558
559 \param pList - Pointer to list object where the node will be removed
560
561 \param ppNode - Pointer to the node to be removed from the list.
562
563 \return VOS_STATUS_SUCCESS - list node was successfully removed from
564 the list.
565
566 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
567 initialized list object.
568
569 VOS_STATUS_E_EMPTY - The specified is empty so nodes cannot be
570 removed.
571
572
573 VOS_STATUS_E_FAULT - pList or pNodeToRemove is not a valid pointer
574
575 \sa
576
577 --------------------------------------------------------------------------*/
578VOS_STATUS vos_list_remove_node( vos_list_t *pList, vos_list_node_t *pNodeToRemove );
579
580
581
582#endif // __VOS_LIST_H