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