1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff *
34219820Sjeff */
35219820Sjeff
36219820Sjeff/*
37219820Sjeff * Abstract:
38219820Sjeff *	Declaration of list.
39219820Sjeff */
40219820Sjeff
41219820Sjeff#ifndef _CL_LIST_H_
42219820Sjeff#define _CL_LIST_H_
43219820Sjeff
44219820Sjeff#include <complib/cl_qlist.h>
45219820Sjeff#include <complib/cl_qpool.h>
46219820Sjeff
47219820Sjeff#ifdef __cplusplus
48219820Sjeff#  define BEGIN_C_DECLS extern "C" {
49219820Sjeff#  define END_C_DECLS   }
50219820Sjeff#else				/* !__cplusplus */
51219820Sjeff#  define BEGIN_C_DECLS
52219820Sjeff#  define END_C_DECLS
53219820Sjeff#endif				/* __cplusplus */
54219820Sjeff
55219820SjeffBEGIN_C_DECLS
56219820Sjeff/****h* Component Library/List
57219820Sjeff* NAME
58219820Sjeff*	List
59219820Sjeff*
60219820Sjeff* DESCRIPTION
61219820Sjeff*	List stores objects in a doubly linked list.
62219820Sjeff*
63219820Sjeff*	Unlike quick list, users pass pointers to the object being stored, rather
64219820Sjeff*	than to a cl_list_item_t structure.  Insertion operations on a list can
65219820Sjeff*	fail, and callers should trap for such failures.
66219820Sjeff*
67219820Sjeff*	Use quick list in situations where insertion failures cannot be tolerated.
68219820Sjeff*
69219820Sjeff*	List is not thread safe, and users must provide serialization.
70219820Sjeff*
71219820Sjeff*	The list functions operates on a cl_list_t structure which should be
72219820Sjeff*	treated as opaque and should be manipulated only through the provided
73219820Sjeff*	functions.
74219820Sjeff*
75219820Sjeff* SEE ALSO
76219820Sjeff*	Types:
77219820Sjeff*		cl_list_iterator_t
78219820Sjeff*
79219820Sjeff*	Structures:
80219820Sjeff*		cl_list_t
81219820Sjeff*
82219820Sjeff*	Callbacks:
83219820Sjeff*		cl_pfn_list_apply_t, cl_pfn_list_find_t
84219820Sjeff*
85219820Sjeff*	Initialization/Destruction:
86219820Sjeff*		cl_list_construct, cl_list_init, cl_list_destroy
87219820Sjeff*
88219820Sjeff*	Iteration:
89219820Sjeff*		cl_list_next, cl_list_prev, cl_list_head, cl_list_tail,
90219820Sjeff*		cl_list_end
91219820Sjeff*
92219820Sjeff*	Manipulation:
93219820Sjeff*		cl_list_insert_head, cl_list_insert_tail,
94219820Sjeff*		cl_list_insert_array_head, cl_list_insert_array_tail,
95219820Sjeff*		cl_list_insert_prev, cl_list_insert_next,
96219820Sjeff*		cl_list_remove_head, cl_list_remove_tail,
97219820Sjeff*		cl_list_remove_object, cl_list_remove_item, cl_list_remove_all
98219820Sjeff*
99219820Sjeff*	Search:
100219820Sjeff*		cl_is_object_in_list, cl_list_find_from_head, cl_list_find_from_tail,
101219820Sjeff*		cl_list_apply_func
102219820Sjeff*
103219820Sjeff*	Attributes:
104219820Sjeff*		cl_list_count, cl_is_list_empty, cl_is_list_inited
105219820Sjeff*********/
106219820Sjeff/****s* Component Library: List/cl_list_t
107219820Sjeff* NAME
108219820Sjeff*	cl_list_t
109219820Sjeff*
110219820Sjeff* DESCRIPTION
111219820Sjeff*	List structure.
112219820Sjeff*
113219820Sjeff*	The cl_list_t structure should be treated as opaque and should be
114219820Sjeff*	manipulated only through the provided functions.
115219820Sjeff*
116219820Sjeff* SYNOPSIS
117219820Sjeff*/
118219820Sjefftypedef struct _cl_list {
119219820Sjeff	cl_qlist_t list;
120219820Sjeff	cl_qpool_t list_item_pool;
121219820Sjeff} cl_list_t;
122219820Sjeff/*
123219820Sjeff* FIELDS
124219820Sjeff*	list
125219820Sjeff*		Quick list of items stored in the list.
126219820Sjeff*
127219820Sjeff*	list_item_pool
128219820Sjeff*		Quick pool of list objects for storing objects in the quick list.
129219820Sjeff*
130219820Sjeff* SEE ALSO
131219820Sjeff*	List
132219820Sjeff*********/
133219820Sjeff
134219820Sjeff/****d* Component Library: List/cl_list_iterator_t
135219820Sjeff* NAME
136219820Sjeff*	cl_list_iterator_t
137219820Sjeff*
138219820Sjeff* DESCRIPTION
139219820Sjeff*	Iterator type used to walk a list.
140219820Sjeff*
141219820Sjeff* SYNOPSIS
142219820Sjeff*/
143219820Sjefftypedef const cl_list_item_t *cl_list_iterator_t;
144219820Sjeff/*
145219820Sjeff* NOTES
146219820Sjeff*	The iterator should be treated as opaque to prevent corrupting the list.
147219820Sjeff*
148219820Sjeff* SEE ALSO
149219820Sjeff*	List, cl_list_head, cl_list_tail, cl_list_next, cl_list_prev,
150219820Sjeff*	cl_list_obj
151219820Sjeff*********/
152219820Sjeff
153219820Sjeff/****d* Component Library: List/cl_pfn_list_apply_t
154219820Sjeff* NAME
155219820Sjeff*	cl_pfn_list_apply_t
156219820Sjeff*
157219820Sjeff* DESCRIPTION
158219820Sjeff*	The cl_pfn_list_apply_t function type defines the prototype for functions
159219820Sjeff*	used to iterate objects in a list.
160219820Sjeff*
161219820Sjeff* SYNOPSIS
162219820Sjeff*/
163219820Sjefftypedef void
164219820Sjeff (*cl_pfn_list_apply_t) (IN void *const p_object, IN void *context);
165219820Sjeff/*
166219820Sjeff* PARAMETERS
167219820Sjeff*	p_object
168219820Sjeff*		[in] Pointer to an object stored in a list.
169219820Sjeff*
170219820Sjeff*	context
171219820Sjeff*		[in] Context provided in a call to cl_list_apply_func.
172219820Sjeff*
173219820Sjeff* RETURN VALUE
174219820Sjeff*	This function does not return a value.
175219820Sjeff*
176219820Sjeff* NOTES
177219820Sjeff*	This function type is provided as function prototype reference for the
178219820Sjeff*	function provided by users as a parameter to the cl_list_apply_func
179219820Sjeff*	function.
180219820Sjeff*
181219820Sjeff* SEE ALSO
182219820Sjeff*	List, cl_list_apply_func
183219820Sjeff*********/
184219820Sjeff
185219820Sjeff/****d* Component Library: List/cl_pfn_list_find_t
186219820Sjeff* NAME
187219820Sjeff*	cl_pfn_list_find_t
188219820Sjeff*
189219820Sjeff* DESCRIPTION
190219820Sjeff*	The cl_pfn_list_find_t function type defines the prototype for functions
191219820Sjeff*	used to find objects in a list.
192219820Sjeff*
193219820Sjeff* SYNOPSIS
194219820Sjeff*/
195219820Sjefftypedef cl_status_t
196219820Sjeff    (*cl_pfn_list_find_t) (IN const void *const p_object, IN void *context);
197219820Sjeff/*
198219820Sjeff* PARAMETERS
199219820Sjeff*	p_object
200219820Sjeff*		[in] Pointer to an object stored in a list.
201219820Sjeff*
202219820Sjeff*	context
203219820Sjeff*		[in] Context provided in a call to ListFindFromHead or ListFindFromTail.
204219820Sjeff*
205219820Sjeff* RETURN VALUES
206219820Sjeff*	Return CL_SUCCESS if the desired item was found.  This stops list iteration.
207219820Sjeff*
208219820Sjeff*	Return CL_NOT_FOUND to continue the list iteration.
209219820Sjeff*
210219820Sjeff* NOTES
211219820Sjeff*	This function type is provided as function prototype reference for the
212219820Sjeff*	function provided by users as a parameter to the cl_list_find_from_head
213219820Sjeff*	and cl_list_find_from_tail functions.
214219820Sjeff*
215219820Sjeff* SEE ALSO
216219820Sjeff*	List, cl_list_find_from_head, cl_list_find_from_tail
217219820Sjeff*********/
218219820Sjeff
219219820Sjeff/****f* Component Library: List/cl_list_construct
220219820Sjeff* NAME
221219820Sjeff*	cl_list_construct
222219820Sjeff*
223219820Sjeff* DESCRIPTION
224219820Sjeff*	The cl_list_construct function constructs a list.
225219820Sjeff*
226219820Sjeff* SYNOPSIS
227219820Sjeff*/
228219820Sjeffvoid cl_list_construct(IN cl_list_t * const p_list);
229219820Sjeff/*
230219820Sjeff* PARAMETERS
231219820Sjeff*	p_list
232219820Sjeff*		[in] Pointer to cl_list_t object whose state to initialize.
233219820Sjeff*
234219820Sjeff* RETURN VALUE
235219820Sjeff*	This function does not return a value.
236219820Sjeff*
237219820Sjeff* NOTES
238219820Sjeff*	Allows calling cl_list_init, cl_list_destroy and cl_is_list_inited.
239219820Sjeff*
240219820Sjeff*	Calling cl_list_construct is a prerequisite to calling any other
241219820Sjeff*	list function except cl_list_init.
242219820Sjeff*
243219820Sjeff* SEE ALSO
244219820Sjeff*	List, cl_list_init, cl_list_destroy, cl_is_list_inited
245219820Sjeff*********/
246219820Sjeff
247219820Sjeff/****f* Component Library: List/cl_is_list_inited
248219820Sjeff* NAME
249219820Sjeff*	cl_is_list_inited
250219820Sjeff*
251219820Sjeff* DESCRIPTION
252219820Sjeff*	The cl_is_list_inited function returns whether a list was
253219820Sjeff*	initialized successfully.
254219820Sjeff*
255219820Sjeff* SYNOPSIS
256219820Sjeff*/
257219820Sjeffstatic inline boolean_t cl_is_list_inited(IN const cl_list_t * const p_list)
258219820Sjeff{
259219820Sjeff	/* CL_ASSERT that a non-null pointer is provided. */
260219820Sjeff	CL_ASSERT(p_list);
261219820Sjeff	/*
262219820Sjeff	 * The pool is the last thing initialized.  If it is initialized, the
263219820Sjeff	 * list is initialized too.
264219820Sjeff	 */
265219820Sjeff	return (cl_is_qpool_inited(&p_list->list_item_pool));
266219820Sjeff}
267219820Sjeff
268219820Sjeff/*
269219820Sjeff* PARAMETERS
270219820Sjeff*	p_list
271219820Sjeff*		[in] Pointer to a cl_list_t structure whose initilization state
272219820Sjeff*		to check.
273219820Sjeff*
274219820Sjeff* RETURN VALUES
275219820Sjeff*	TRUE if the list was initialized successfully.
276219820Sjeff*
277219820Sjeff*	FALSE otherwise.
278219820Sjeff*
279219820Sjeff* NOTES
280219820Sjeff*	Allows checking the state of a list to determine if invoking
281219820Sjeff*	member functions is appropriate.
282219820Sjeff*
283219820Sjeff* SEE ALSO
284219820Sjeff*	List
285219820Sjeff*********/
286219820Sjeff
287219820Sjeff/****f* Component Library: List/cl_list_init
288219820Sjeff* NAME
289219820Sjeff*	cl_list_init
290219820Sjeff*
291219820Sjeff* DESCRIPTION
292219820Sjeff*	The cl_list_init function initializes a list for use.
293219820Sjeff*
294219820Sjeff* SYNOPSIS
295219820Sjeff*/
296219820Sjeffcl_status_t
297219820Sjeffcl_list_init(IN cl_list_t * const p_list, IN const size_t min_items);
298219820Sjeff/*
299219820Sjeff* PARAMETERS
300219820Sjeff*	p_list
301219820Sjeff*		[in] Pointer to cl_list_t structure to initialize.
302219820Sjeff*
303219820Sjeff*	min_items
304219820Sjeff*		[in] Minimum number of items that can be stored.  All necessary
305219820Sjeff*		allocations to allow storing the minimum number of items is performed
306219820Sjeff*		at initialization time.
307219820Sjeff*
308219820Sjeff* RETURN VALUES
309219820Sjeff*	CL_SUCCESS if the list was initialized successfully.
310219820Sjeff*
311219820Sjeff*	CL_INSUFFICIENT_MEMORY if there was not enough memory for initialization.
312219820Sjeff*
313219820Sjeff* NOTES
314219820Sjeff*	The list will always be able to store at least as many items as specified
315219820Sjeff*	by the min_items parameter.
316219820Sjeff*
317219820Sjeff* SEE ALSO
318219820Sjeff*	List, cl_list_construct, cl_list_destroy, cl_list_insert_head,
319219820Sjeff*	cl_list_insert_tail, cl_list_remove_head, cl_list_remove_tail
320219820Sjeff*********/
321219820Sjeff
322219820Sjeff/****f* Component Library: List/cl_list_destroy
323219820Sjeff* NAME
324219820Sjeff*	cl_list_destroy
325219820Sjeff*
326219820Sjeff* DESCRIPTION
327219820Sjeff*	The cl_list_destroy function destroys a list.
328219820Sjeff*
329219820Sjeff* SYNOPSIS
330219820Sjeff*/
331219820Sjeffvoid cl_list_destroy(IN cl_list_t * const p_list);
332219820Sjeff/*
333219820Sjeff* PARAMETERS
334219820Sjeff*	p_list
335219820Sjeff*		[in] Pointer to cl_list_t structure to destroy.
336219820Sjeff*
337219820Sjeff* RETURN VALUE
338219820Sjeff*	This function does not return a value.
339219820Sjeff*
340219820Sjeff* NOTES
341219820Sjeff*	cl_list_destroy does not affect any of the objects stored in the list,
342219820Sjeff*	but does release all memory allocated internally.  Further operations
343219820Sjeff*	should not be attempted on the list after cl_list_destroy is invoked.
344219820Sjeff*
345219820Sjeff*	This function should only be called after a call to cl_list_construct
346219820Sjeff*	or cl_list_init.
347219820Sjeff*
348219820Sjeff*	In debug builds, cl_list_destroy asserts if the list is not empty.
349219820Sjeff*
350219820Sjeff* SEE ALSO
351219820Sjeff*	List, cl_list_construct, cl_list_init
352219820Sjeff*********/
353219820Sjeff
354219820Sjeff/****f* Component Library: List/cl_is_list_empty
355219820Sjeff* NAME
356219820Sjeff*	cl_is_list_empty
357219820Sjeff*
358219820Sjeff* DESCRIPTION
359219820Sjeff*	The cl_is_list_empty function returns whether a list is empty.
360219820Sjeff*
361219820Sjeff* SYNOPSIS
362219820Sjeff*/
363219820Sjeffstatic inline boolean_t cl_is_list_empty(IN const cl_list_t * const p_list)
364219820Sjeff{
365219820Sjeff	CL_ASSERT(p_list);
366219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
367219820Sjeff	return (cl_is_qlist_empty(&p_list->list));
368219820Sjeff}
369219820Sjeff
370219820Sjeff/*
371219820Sjeff* PARAMETERS
372219820Sjeff*	p_list
373219820Sjeff*		[in] Pointer to a cl_list_t structure.
374219820Sjeff*
375219820Sjeff* RETURN VALUES
376219820Sjeff*	TRUE if the specified list is empty.
377219820Sjeff*
378219820Sjeff*	FALSE otherwise.
379219820Sjeff*
380219820Sjeff* SEE ALSO
381219820Sjeff*	List, cl_list_count, cl_list_remove_all
382219820Sjeff*********/
383219820Sjeff
384219820Sjeff/****f* Component Library: List/cl_list_insert_head
385219820Sjeff* NAME
386219820Sjeff*	cl_list_insert_head
387219820Sjeff*
388219820Sjeff* DESCRIPTION
389219820Sjeff*	The cl_list_insert_head function inserts an object at the head of a list.
390219820Sjeff*
391219820Sjeff* SYNOPSIS
392219820Sjeff*/
393219820Sjeffstatic inline cl_status_t
394219820Sjeffcl_list_insert_head(IN cl_list_t * const p_list, IN const void *const p_object)
395219820Sjeff{
396219820Sjeff	cl_pool_obj_t *p_pool_obj;
397219820Sjeff
398219820Sjeff	CL_ASSERT(p_list);
399219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
400219820Sjeff
401219820Sjeff	/* Get a list item to add to the list. */
402219820Sjeff	p_pool_obj = (cl_pool_obj_t *) cl_qpool_get(&p_list->list_item_pool);
403219820Sjeff	if (!p_pool_obj)
404219820Sjeff		return (CL_INSUFFICIENT_MEMORY);
405219820Sjeff
406219820Sjeff	p_pool_obj->p_object = p_object;
407219820Sjeff	cl_qlist_insert_head(&p_list->list, &p_pool_obj->pool_item.list_item);
408219820Sjeff	return (CL_SUCCESS);
409219820Sjeff}
410219820Sjeff
411219820Sjeff/*
412219820Sjeff* PARAMETERS
413219820Sjeff*	p_list
414219820Sjeff*		[in] Pointer to a cl_list_t structure into which to insert the object.
415219820Sjeff*
416219820Sjeff*	p_object
417219820Sjeff*		[in] Pointer to an object to insert into the list.
418219820Sjeff*
419219820Sjeff* RETURN VALUES
420219820Sjeff*	CL_SUCCESS if the insertion was successful.
421219820Sjeff*
422219820Sjeff*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
423219820Sjeff*
424219820Sjeff* NOTES
425219820Sjeff*	Inserts the specified object at the head of the list.  List insertion
426219820Sjeff*	operations are guaranteed to work for the minimum number of items as
427219820Sjeff*	specified in cl_list_init by the min_items parameter.
428219820Sjeff*
429219820Sjeff* SEE ALSO
430219820Sjeff*	List, cl_list_insert_tail, cl_list_insert_array_head,
431219820Sjeff*	cl_list_insert_array_tail, cl_list_insert_prev, cl_list_insert_next,
432219820Sjeff*	cl_list_remove_head
433219820Sjeff*********/
434219820Sjeff
435219820Sjeff/****f* Component Library: List/cl_list_insert_tail
436219820Sjeff* NAME
437219820Sjeff*	cl_list_insert_tail
438219820Sjeff*
439219820Sjeff* DESCRIPTION
440219820Sjeff*	The cl_list_insert_tail function inserts an object at the tail of a list.
441219820Sjeff*
442219820Sjeff* SYNOPSIS
443219820Sjeff*/
444219820Sjeffstatic inline cl_status_t
445219820Sjeffcl_list_insert_tail(IN cl_list_t * const p_list, IN const void *const p_object)
446219820Sjeff{
447219820Sjeff	cl_pool_obj_t *p_pool_obj;
448219820Sjeff
449219820Sjeff	CL_ASSERT(p_list);
450219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
451219820Sjeff
452219820Sjeff	/* Get a list item to add to the list. */
453219820Sjeff	p_pool_obj = (cl_pool_obj_t *) cl_qpool_get(&p_list->list_item_pool);
454219820Sjeff	if (!p_pool_obj)
455219820Sjeff		return (CL_INSUFFICIENT_MEMORY);
456219820Sjeff
457219820Sjeff	p_pool_obj->p_object = p_object;
458219820Sjeff	cl_qlist_insert_tail(&p_list->list, &p_pool_obj->pool_item.list_item);
459219820Sjeff	return (CL_SUCCESS);
460219820Sjeff}
461219820Sjeff
462219820Sjeff/*
463219820Sjeff* PARAMETERS
464219820Sjeff*	p_list
465219820Sjeff*		[in] Pointer to a cl_list_t structure into which to insert the object.
466219820Sjeff*
467219820Sjeff*	p_object
468219820Sjeff*		[in] Pointer to an object to insert into the list.
469219820Sjeff*
470219820Sjeff* RETURN VALUES
471219820Sjeff*	CL_SUCCESS if the insertion was successful.
472219820Sjeff*
473219820Sjeff*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
474219820Sjeff*
475219820Sjeff* NOTES
476219820Sjeff*	Inserts the specified object at the tail of the list.  List insertion
477219820Sjeff*	operations are guaranteed to work for the minimum number of items as
478219820Sjeff*	specified in cl_list_init by the min_items parameter.
479219820Sjeff*
480219820Sjeff* SEE ALSO
481219820Sjeff*	List, cl_list_insert_head, cl_list_insert_array_head,
482219820Sjeff*	cl_list_insert_array_tail, cl_list_insert_prev, cl_list_insert_next,
483219820Sjeff*	cl_list_remove_tail
484219820Sjeff*********/
485219820Sjeff
486219820Sjeff/****f* Component Library: List/cl_list_insert_array_head
487219820Sjeff* NAME
488219820Sjeff*	cl_list_insert_array_head
489219820Sjeff*
490219820Sjeff* DESCRIPTION:
491219820Sjeff*	The cl_list_insert_array_head function inserts an array of objects
492219820Sjeff*	at the head of a list.
493219820Sjeff*
494219820Sjeff* SYNOPSIS
495219820Sjeff*/
496219820Sjeffcl_status_t
497219820Sjeffcl_list_insert_array_head(IN cl_list_t * const p_list,
498219820Sjeff			  IN const void *const p_array,
499219820Sjeff			  IN uint32_t item_count, IN const uint32_t item_size);
500219820Sjeff/*
501219820Sjeff* PARAMETERS
502219820Sjeff*	p_list
503219820Sjeff*		[in] Pointer to a cl_list_t structure into which to insert the objects.
504219820Sjeff*
505219820Sjeff*	p_array
506219820Sjeff*		[in] Pointer to the first object in an array.
507219820Sjeff*
508219820Sjeff*	item_count
509219820Sjeff*		[in] Number of objects in the array.
510219820Sjeff*
511219820Sjeff*	item_size
512219820Sjeff*		[in] Size of the objects added to the list.  This is the stride in the
513219820Sjeff*		array from one object to the next.
514219820Sjeff*
515219820Sjeff* RETURN VALUES
516219820Sjeff*	CL_SUCCESS if the insertion was successful.
517219820Sjeff*
518219820Sjeff*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
519219820Sjeff*
520219820Sjeff* NOTES
521219820Sjeff*	Inserts all objects in the array to the head of the list, preserving the
522219820Sjeff*	ordering of the objects.  If not successful, no items are added.
523219820Sjeff*	List insertion operations are guaranteed to work for the minimum number
524219820Sjeff*	of items as specified in cl_list_init by the min_items parameter.
525219820Sjeff*
526219820Sjeff* SEE ALSO
527219820Sjeff*	List, cl_list_insert_array_tail, cl_list_insert_head, cl_list_insert_tail,
528219820Sjeff*	cl_list_insert_prev, cl_list_insert_next
529219820Sjeff*********/
530219820Sjeff
531219820Sjeff/****f* Component Library: List/cl_list_insert_array_tail
532219820Sjeff* NAME
533219820Sjeff*	cl_list_insert_array_tail
534219820Sjeff*
535219820Sjeff* DESCRIPTION
536219820Sjeff*	The cl_list_insert_array_tail function inserts an array of objects
537219820Sjeff*	at the tail of a list.
538219820Sjeff*
539219820Sjeff* SYNOPSIS
540219820Sjeff*/
541219820Sjeffcl_status_t
542219820Sjeffcl_list_insert_array_tail(IN cl_list_t * const p_list,
543219820Sjeff			  IN const void *const p_array,
544219820Sjeff			  IN uint32_t item_count, IN const uint32_t item_size);
545219820Sjeff/*
546219820Sjeff* PARAMETERS
547219820Sjeff*	p_list
548219820Sjeff*		[in] Pointer to a cl_list_t structure into which to insert the objects.
549219820Sjeff*
550219820Sjeff*	p_array
551219820Sjeff*		[in] Pointer to the first object in an array.
552219820Sjeff*
553219820Sjeff*	item_count
554219820Sjeff*		[in] Number of objects in the array.
555219820Sjeff*
556219820Sjeff*	item_size
557219820Sjeff*		[in] Size of the objects added to the list.  This is the stride in the
558219820Sjeff*		array from one object to the next.
559219820Sjeff*
560219820Sjeff* RETURN VALUES
561219820Sjeff*	CL_SUCCESS if the insertion was successful.
562219820Sjeff*
563219820Sjeff*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
564219820Sjeff*
565219820Sjeff* NOTES
566219820Sjeff*	Inserts all objects in the array to the tail of the list, preserving the
567219820Sjeff*	ordering of the objects.  If not successful, no items are added.
568219820Sjeff*	List insertion operations are guaranteed to work for the minimum number
569219820Sjeff*	of items as specified in cl_list_init by the min_items parameter.
570219820Sjeff*
571219820Sjeff* SEE ALSO
572219820Sjeff*	List, cl_list_insert_array_head, cl_list_insert_head, cl_list_insert_tail,
573219820Sjeff*	cl_list_insert_prev, cl_list_insert_next
574219820Sjeff*********/
575219820Sjeff
576219820Sjeff/****f* Component Library: List/cl_list_insert_next
577219820Sjeff* NAME
578219820Sjeff*	cl_list_insert_next
579219820Sjeff*
580219820Sjeff* DESCRIPTION
581219820Sjeff*	The cl_list_insert_next function inserts an object in a list after
582219820Sjeff*	the object associated with a given iterator.
583219820Sjeff*
584219820Sjeff* SYNOPSIS
585219820Sjeff*/
586219820Sjeffstatic inline cl_status_t
587219820Sjeffcl_list_insert_next(IN cl_list_t * const p_list,
588219820Sjeff		    IN cl_list_iterator_t iterator,
589219820Sjeff		    IN const void *const p_object)
590219820Sjeff{
591219820Sjeff	cl_pool_obj_t *p_pool_obj;
592219820Sjeff
593219820Sjeff	CL_ASSERT(p_list);
594219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
595219820Sjeff
596219820Sjeff	/* Get a list item to add to the list. */
597219820Sjeff	p_pool_obj = (cl_pool_obj_t *) cl_qpool_get(&p_list->list_item_pool);
598219820Sjeff	if (!p_pool_obj)
599219820Sjeff		return (CL_INSUFFICIENT_MEMORY);
600219820Sjeff
601219820Sjeff	p_pool_obj->p_object = p_object;
602219820Sjeff	cl_qlist_insert_next(&p_list->list, (cl_list_item_t *) iterator,
603219820Sjeff			     &p_pool_obj->pool_item.list_item);
604219820Sjeff	return (CL_SUCCESS);
605219820Sjeff}
606219820Sjeff
607219820Sjeff/*
608219820Sjeff* PARAMETERS
609219820Sjeff*	p_list
610219820Sjeff*		[in] Pointer to a cl_list_t structure into which to insert the object.
611219820Sjeff*
612219820Sjeff*	iterator
613219820Sjeff*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
614219820Sjeff*		cl_list_tail, cl_list_next, or cl_list_prev.
615219820Sjeff*
616219820Sjeff*	p_object
617219820Sjeff*		[in] Pointer to an object to insert into the list.
618219820Sjeff*
619219820Sjeff* RETURN VALUES
620219820Sjeff*	CL_SUCCESS if the insertion was successful.
621219820Sjeff*
622219820Sjeff*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
623219820Sjeff*
624219820Sjeff* SEE ALSO
625219820Sjeff*	List, cl_list_insert_prev, cl_list_insert_head, cl_list_insert_tail,
626219820Sjeff*	cl_list_insert_array_head, cl_list_insert_array_tail
627219820Sjeff*********/
628219820Sjeff
629219820Sjeff/****f* Component Library: List/cl_list_insert_prev
630219820Sjeff* NAME
631219820Sjeff*	cl_list_insert_prev
632219820Sjeff*
633219820Sjeff* DESCRIPTION
634219820Sjeff*	The cl_list_insert_prev function inserts an object in a list before
635219820Sjeff*	the object associated with a given iterator.
636219820Sjeff*
637219820Sjeff* SYNOPSIS
638219820Sjeff*/
639219820Sjeffstatic inline cl_status_t
640219820Sjeffcl_list_insert_prev(IN cl_list_t * const p_list,
641219820Sjeff		    IN cl_list_iterator_t iterator,
642219820Sjeff		    IN const void *const p_object)
643219820Sjeff{
644219820Sjeff	cl_pool_obj_t *p_pool_obj;
645219820Sjeff
646219820Sjeff	CL_ASSERT(p_list);
647219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
648219820Sjeff
649219820Sjeff	/* Get a list item to add to the list. */
650219820Sjeff	p_pool_obj = (cl_pool_obj_t *) cl_qpool_get(&p_list->list_item_pool);
651219820Sjeff	if (!p_pool_obj)
652219820Sjeff		return (CL_INSUFFICIENT_MEMORY);
653219820Sjeff
654219820Sjeff	p_pool_obj->p_object = p_object;
655219820Sjeff	cl_qlist_insert_prev(&p_list->list, (cl_list_item_t *) iterator,
656219820Sjeff			     &p_pool_obj->pool_item.list_item);
657219820Sjeff	return (CL_SUCCESS);
658219820Sjeff}
659219820Sjeff
660219820Sjeff/*
661219820Sjeff* PARAMETERS
662219820Sjeff*	p_list
663219820Sjeff*		[in] Pointer to a cl_list_t structure into which to insert the object.
664219820Sjeff*
665219820Sjeff*	iterator
666219820Sjeff*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
667219820Sjeff*		cl_list_tail, cl_list_next, or cl_list_prev.
668219820Sjeff*
669219820Sjeff*	p_object
670219820Sjeff*		[in] Pointer to an object to insert into the list.
671219820Sjeff*
672219820Sjeff* RETURN VALUES
673219820Sjeff*	CL_SUCCESS if the insertion was successful.
674219820Sjeff*
675219820Sjeff*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
676219820Sjeff*
677219820Sjeff* SEE ALSO
678219820Sjeff*	List, cl_list_insert_next, cl_list_insert_head, cl_list_insert_tail,
679219820Sjeff*	cl_list_insert_array_head, cl_list_insert_array_tail
680219820Sjeff*********/
681219820Sjeff
682219820Sjeff/****f* Component Library: List/cl_list_remove_head
683219820Sjeff* NAME
684219820Sjeff*	cl_list_remove_head
685219820Sjeff*
686219820Sjeff* DESCRIPTION
687219820Sjeff*	The cl_list_remove_head function removes an object from the head of a list.
688219820Sjeff*
689219820Sjeff* SYNOPSIS
690219820Sjeff*/
691219820Sjeffstatic inline void *cl_list_remove_head(IN cl_list_t * const p_list)
692219820Sjeff{
693219820Sjeff	cl_pool_obj_t *p_pool_obj;
694219820Sjeff	void *p_obj;
695219820Sjeff
696219820Sjeff	CL_ASSERT(p_list);
697219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
698219820Sjeff
699219820Sjeff	/* See if the list is empty. */
700219820Sjeff	if (cl_is_qlist_empty(&p_list->list))
701219820Sjeff		return (NULL);
702219820Sjeff
703219820Sjeff	/* Get the item at the head of the list. */
704219820Sjeff	p_pool_obj = (cl_pool_obj_t *) cl_qlist_remove_head(&p_list->list);
705219820Sjeff
706219820Sjeff	p_obj = (void *)p_pool_obj->p_object;
707219820Sjeff	/* Place the pool item back into the pool. */
708219820Sjeff	cl_qpool_put(&p_list->list_item_pool, &p_pool_obj->pool_item);
709219820Sjeff
710219820Sjeff	return (p_obj);
711219820Sjeff}
712219820Sjeff
713219820Sjeff/*
714219820Sjeff* PARAMETERS
715219820Sjeff*	p_list
716219820Sjeff*		[in] Pointer to a cl_list_t structure from which to remove an object.
717219820Sjeff*
718219820Sjeff* RETURN VALUES
719219820Sjeff*	Returns the pointer to the object formerly at the head of the list.
720219820Sjeff*
721219820Sjeff*	NULL if the list was empty.
722219820Sjeff*
723219820Sjeff* SEE ALSO
724219820Sjeff*	List, cl_list_remove_tail, cl_list_remove_all, cl_list_remove_object,
725219820Sjeff*	cl_list_remove_item, cl_list_insert_head
726219820Sjeff*********/
727219820Sjeff
728219820Sjeff/****f* Component Library: List/cl_list_remove_tail
729219820Sjeff* NAME
730219820Sjeff*	cl_list_remove_tail
731219820Sjeff*
732219820Sjeff* DESCRIPTION
733219820Sjeff*	The cl_list_remove_tail function removes an object from the tail of a list.
734219820Sjeff*
735219820Sjeff* SYNOPSIS
736219820Sjeff*/
737219820Sjeffstatic inline void *cl_list_remove_tail(IN cl_list_t * const p_list)
738219820Sjeff{
739219820Sjeff	cl_pool_obj_t *p_pool_obj;
740219820Sjeff
741219820Sjeff	CL_ASSERT(p_list);
742219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
743219820Sjeff
744219820Sjeff	/* See if the list is empty. */
745219820Sjeff	if (cl_is_qlist_empty(&p_list->list))
746219820Sjeff		return (NULL);
747219820Sjeff
748219820Sjeff	/* Get the item at the head of the list. */
749219820Sjeff	p_pool_obj = (cl_pool_obj_t *) cl_qlist_remove_tail(&p_list->list);
750219820Sjeff
751219820Sjeff	/* Place the list item back into the pool. */
752219820Sjeff	cl_qpool_put(&p_list->list_item_pool, &p_pool_obj->pool_item);
753219820Sjeff
754219820Sjeff	return ((void *)p_pool_obj->p_object);
755219820Sjeff}
756219820Sjeff
757219820Sjeff/*
758219820Sjeff* PARAMETERS
759219820Sjeff*	p_list
760219820Sjeff*		[in] Pointer to a cl_list_t structure from which to remove an object.
761219820Sjeff*
762219820Sjeff* RETURN VALUES
763219820Sjeff*	Returns the pointer to the object formerly at the tail of the list.
764219820Sjeff*
765219820Sjeff*	NULL if the list was empty.
766219820Sjeff*
767219820Sjeff* SEE ALSO
768219820Sjeff*	List, cl_list_remove_head, cl_list_remove_all, cl_list_remove_object,
769219820Sjeff*	cl_list_remove_item, cl_list_insert_head
770219820Sjeff*********/
771219820Sjeff
772219820Sjeff/****f* Component Library: List/cl_list_remove_all
773219820Sjeff* NAME
774219820Sjeff*	cl_list_remove_all
775219820Sjeff*
776219820Sjeff* DESCRIPTION
777219820Sjeff*	The cl_list_remove_all function removes all objects from a list,
778219820Sjeff*	leaving it empty.
779219820Sjeff*
780219820Sjeff* SYNOPSIS
781219820Sjeff*/
782219820Sjeffstatic inline void cl_list_remove_all(IN cl_list_t * const p_list)
783219820Sjeff{
784219820Sjeff	CL_ASSERT(p_list);
785219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
786219820Sjeff
787219820Sjeff	/* Return all the list items to the pool. */
788219820Sjeff	cl_qpool_put_list(&p_list->list_item_pool, &p_list->list);
789219820Sjeff}
790219820Sjeff
791219820Sjeff/*
792219820Sjeff* PARAMETERS
793219820Sjeff*	p_list
794219820Sjeff*		[in] Pointer to a cl_list_t structure from which to remove all objects.
795219820Sjeff*
796219820Sjeff* RETURN VALUE
797219820Sjeff*	This function does not return a value.
798219820Sjeff*
799219820Sjeff* SEE ALSO
800219820Sjeff*	List, cl_list_remove_head, cl_list_remove_tail, cl_list_remove_object,
801219820Sjeff*	cl_list_remove_item
802219820Sjeff*********/
803219820Sjeff
804219820Sjeff/****f* Component Library: List/cl_list_remove_object
805219820Sjeff* NAME
806219820Sjeff*	cl_list_remove_object
807219820Sjeff*
808219820Sjeff* DESCRIPTION
809219820Sjeff*	The cl_list_remove_object function removes a specific object from a list.
810219820Sjeff*
811219820Sjeff* SYNOPSIS
812219820Sjeff*/
813219820Sjeffcl_status_t
814219820Sjeffcl_list_remove_object(IN cl_list_t * const p_list,
815219820Sjeff		      IN const void *const p_object);
816219820Sjeff/*
817219820Sjeff* PARAMETERS
818219820Sjeff*	p_list
819219820Sjeff*		[in] Pointer to a cl_list_t structure from which to remove the object.
820219820Sjeff*
821219820Sjeff*	p_object
822219820Sjeff*		[in] Pointer to an object to remove from the list.
823219820Sjeff*
824219820Sjeff* RETURN VALUES
825219820Sjeff*	CL_SUCCESS if the object was removed.
826219820Sjeff*
827219820Sjeff*	CL_NOT_FOUND if the object was not found in the list.
828219820Sjeff*
829219820Sjeff* NOTES
830219820Sjeff*	Removes the first occurrence of an object from a list.
831219820Sjeff*
832219820Sjeff* SEE ALSO
833219820Sjeff*	List, cl_list_remove_item, cl_list_remove_head, cl_list_remove_tail,
834219820Sjeff*	cl_list_remove_all
835219820Sjeff*********/
836219820Sjeff
837219820Sjeff/****f* Component Library: List/cl_list_remove_item
838219820Sjeff* NAME
839219820Sjeff*	cl_list_remove_item
840219820Sjeff*
841219820Sjeff* DESCRIPTION
842219820Sjeff*	The cl_list_remove_item function removes an object from the head of a list.
843219820Sjeff*
844219820Sjeff* SYNOPSIS
845219820Sjeff*/
846219820Sjeffstatic inline void
847219820Sjeffcl_list_remove_item(IN cl_list_t * const p_list, IN cl_list_iterator_t iterator)
848219820Sjeff{
849219820Sjeff	CL_ASSERT(p_list);
850219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
851219820Sjeff
852219820Sjeff	cl_qlist_remove_item(&p_list->list, (cl_list_item_t *) iterator);
853219820Sjeff
854219820Sjeff	/* Place the list item back into the pool. */
855219820Sjeff	cl_qpool_put(&p_list->list_item_pool, (cl_pool_item_t *) iterator);
856219820Sjeff}
857219820Sjeff
858219820Sjeff/*
859219820Sjeff* PARAMETERS
860219820Sjeff*	p_list
861219820Sjeff*		[in] Pointer to a cl_list_t structure from which to remove the item.
862219820Sjeff*
863219820Sjeff*	iterator
864219820Sjeff*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
865219820Sjeff*		cl_list_tail, cl_list_next, or cl_list_prev.
866219820Sjeff*
867219820Sjeff* RETURN VALUE
868219820Sjeff*	This function does not return a value.
869219820Sjeff*
870219820Sjeff* SEE ALSO
871219820Sjeff*	List, cl_list_remove_object, cl_list_remove_head, cl_list_remove_tail,
872219820Sjeff*	cl_list_remove_all
873219820Sjeff*********/
874219820Sjeff
875219820Sjeff/****f* Component Library: List/cl_is_object_in_list
876219820Sjeff* NAME
877219820Sjeff*	cl_is_object_in_list
878219820Sjeff*
879219820Sjeff* DESCRIPTION
880219820Sjeff*	The cl_is_object_in_list function returns whether an object
881219820Sjeff*	is stored in a list.
882219820Sjeff*
883219820Sjeff* SYNOPSIS
884219820Sjeff*/
885219820Sjeffboolean_t
886219820Sjeffcl_is_object_in_list(IN const cl_list_t * const p_list,
887219820Sjeff		     IN const void *const p_object);
888219820Sjeff/*
889219820Sjeff* PARAMETERS
890219820Sjeff*	p_list
891219820Sjeff*		[in] Pointer to a cl_list_t structure in which to look for the object.
892219820Sjeff*
893219820Sjeff*	p_object
894219820Sjeff*		[in] Pointer to an object stored in a list.
895219820Sjeff*
896219820Sjeff* RETURN VALUES
897219820Sjeff*	TRUE if p_object was found in the list.
898219820Sjeff*
899219820Sjeff*	FALSE otherwise.
900219820Sjeff*
901219820Sjeff* SEE ALSO
902219820Sjeff*	List
903219820Sjeff*********/
904219820Sjeff
905219820Sjeff/****f* Component Library: List/cl_list_end
906219820Sjeff* NAME
907219820Sjeff*	cl_list_end
908219820Sjeff*
909219820Sjeff* DESCRIPTION
910219820Sjeff*	The cl_list_end function returns returns the list iterator for
911219820Sjeff*	the end of a list.
912219820Sjeff*
913219820Sjeff* SYNOPSIS
914219820Sjeff*/
915219820Sjeffstatic inline cl_list_iterator_t cl_list_end(IN const cl_list_t * const p_list)
916219820Sjeff{
917219820Sjeff	CL_ASSERT(p_list);
918219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
919219820Sjeff
920219820Sjeff	return (cl_qlist_end(&p_list->list));
921219820Sjeff}
922219820Sjeff
923219820Sjeff/*
924219820Sjeff* PARAMETERS
925219820Sjeff*	p_list
926219820Sjeff*		[in] Pointer to a cl_list_t structure for which the iterator for the
927219820Sjeff*		object at the head is to be returned.
928219820Sjeff*
929219820Sjeff* RETURN VALUE
930219820Sjeff*	cl_list_iterator_t for the end of the list.
931219820Sjeff*
932219820Sjeff* NOTES
933219820Sjeff*	Use cl_list_obj to retrieve the object associated with the
934219820Sjeff*	returned cl_list_iterator_t.
935219820Sjeff*
936219820Sjeff* SEE ALSO
937219820Sjeff*	List, cl_list_head, cl_list_tail, cl_list_next, cl_list_prev,
938219820Sjeff*	cl_list_obj
939219820Sjeff*********/
940219820Sjeff
941219820Sjeff/****f* Component Library: List/cl_list_head
942219820Sjeff* NAME
943219820Sjeff*	cl_list_head
944219820Sjeff*
945219820Sjeff* DESCRIPTION
946219820Sjeff*	The cl_list_head function returns returns a list iterator for
947219820Sjeff*	the head of a list.
948219820Sjeff*
949219820Sjeff* SYNOPSIS
950219820Sjeff*/
951219820Sjeffstatic inline cl_list_iterator_t cl_list_head(IN const cl_list_t * const p_list)
952219820Sjeff{
953219820Sjeff	CL_ASSERT(p_list);
954219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
955219820Sjeff
956219820Sjeff	return (cl_qlist_head(&p_list->list));
957219820Sjeff}
958219820Sjeff
959219820Sjeff/*
960219820Sjeff* PARAMETERS
961219820Sjeff*	p_list
962219820Sjeff*		[in] Pointer to a cl_list_t structure for which the iterator for the
963219820Sjeff*		object at the head is to be returned.
964219820Sjeff*
965219820Sjeff* RETURN VALUES
966219820Sjeff*	cl_list_iterator_t for the head of the list.
967219820Sjeff*
968219820Sjeff*	cl_list_iterator_t for the end of the list if the list is empty.
969219820Sjeff*
970219820Sjeff* NOTES
971219820Sjeff*	Use cl_list_obj to retrieve the object associated with the
972219820Sjeff*	returned cl_list_iterator_t.
973219820Sjeff*
974219820Sjeff* SEE ALSO
975219820Sjeff*	List, cl_list_tail, cl_list_next, cl_list_prev, cl_list_end,
976219820Sjeff*	cl_list_obj
977219820Sjeff*********/
978219820Sjeff
979219820Sjeff/****f* Component Library: List/cl_list_tail
980219820Sjeff* NAME
981219820Sjeff*	cl_list_tail
982219820Sjeff*
983219820Sjeff* DESCRIPTION
984219820Sjeff*	The cl_list_tail function returns returns a list iterator for
985219820Sjeff*	the tail of a list.
986219820Sjeff*
987219820Sjeff* SYNOPSIS
988219820Sjeff*/
989219820Sjeffstatic inline cl_list_iterator_t cl_list_tail(IN const cl_list_t * const p_list)
990219820Sjeff{
991219820Sjeff	CL_ASSERT(p_list);
992219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
993219820Sjeff
994219820Sjeff	return (cl_qlist_tail(&p_list->list));
995219820Sjeff}
996219820Sjeff
997219820Sjeff/*
998219820Sjeff* PARAMETERS
999219820Sjeff*	p_list
1000219820Sjeff*		[in] Pointer to a cl_list_t structure for which the iterator for the
1001219820Sjeff*		object at the tail is to be returned.
1002219820Sjeff*
1003219820Sjeff* RETURN VALUES
1004219820Sjeff*	cl_list_iterator_t for the tail of the list.
1005219820Sjeff*
1006219820Sjeff*	cl_list_iterator_t for the end of the list if the list is empty.
1007219820Sjeff*
1008219820Sjeff* NOTES
1009219820Sjeff*	Use cl_list_obj to retrieve the object associated with the
1010219820Sjeff*
1011219820Sjeff*	returned cl_list_iterator_t.
1012219820Sjeff*
1013219820Sjeff* SEE ALSO
1014219820Sjeff*	List, cl_list_head, cl_list_next, cl_list_prev, cl_list_end,
1015219820Sjeff*	cl_list_obj
1016219820Sjeff*********/
1017219820Sjeff
1018219820Sjeff/****f* Component Library: List/cl_list_next
1019219820Sjeff* NAME
1020219820Sjeff*	cl_list_next
1021219820Sjeff*
1022219820Sjeff* DESCRIPTION
1023219820Sjeff*	The cl_list_next function returns a list iterator for the object stored
1024219820Sjeff*	in a list after the object associated with a given list iterator.
1025219820Sjeff*
1026219820Sjeff* SYNOPSIS
1027219820Sjeff*/
1028219820Sjeffstatic inline cl_list_iterator_t cl_list_next(IN cl_list_iterator_t iterator)
1029219820Sjeff{
1030219820Sjeff	CL_ASSERT(iterator);
1031219820Sjeff
1032219820Sjeff	return (cl_qlist_next(iterator));
1033219820Sjeff}
1034219820Sjeff
1035219820Sjeff/*
1036219820Sjeff* PARAMETERS
1037219820Sjeff*	p_list
1038219820Sjeff*		[in] Pointer to a cl_list_t structure for which the iterator for the
1039219820Sjeff*		next object is to be returned.
1040219820Sjeff*
1041219820Sjeff*	iterator
1042219820Sjeff*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
1043219820Sjeff*		cl_list_tail, cl_list_next, or cl_list_prev.
1044219820Sjeff*
1045219820Sjeff* RETURN VALUES
1046219820Sjeff*	cl_list_iterator_t for the object following the object associated with
1047219820Sjeff*	the list iterator specified by the iterator parameter.
1048219820Sjeff*
1049219820Sjeff*	cl_list_iterator_t for the end of the list if the list is empty.
1050219820Sjeff*
1051219820Sjeff* NOTES
1052219820Sjeff*	Use cl_list_obj to retrieve the object associated with the
1053219820Sjeff*	returned cl_list_iterator_t.
1054219820Sjeff*
1055219820Sjeff* SEE ALSO
1056219820Sjeff*	List, cl_list_prev, cl_list_head, cl_list_tail, cl_list_end,
1057219820Sjeff*	cl_list_obj
1058219820Sjeff*********/
1059219820Sjeff
1060219820Sjeff/****f* Component Library: List/cl_list_prev
1061219820Sjeff* NAME
1062219820Sjeff*	cl_list_prev
1063219820Sjeff*
1064219820Sjeff* DESCRIPTION
1065219820Sjeff*	The cl_list_prev function returns a list iterator for the object stored
1066219820Sjeff*	in a list before the object associated with a given list iterator.
1067219820Sjeff*
1068219820Sjeff* SYNOPSIS
1069219820Sjeff*/
1070219820Sjeffstatic inline cl_list_iterator_t cl_list_prev(IN cl_list_iterator_t iterator)
1071219820Sjeff{
1072219820Sjeff	CL_ASSERT(iterator);
1073219820Sjeff
1074219820Sjeff	return (cl_qlist_prev(iterator));
1075219820Sjeff}
1076219820Sjeff
1077219820Sjeff/*
1078219820Sjeff* PARAMETERS
1079219820Sjeff*	p_list
1080219820Sjeff*		[in] Pointer to a cl_list_t structure for which the iterator for the
1081219820Sjeff*		next object is to be returned.
1082219820Sjeff*
1083219820Sjeff*	iterator
1084219820Sjeff*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
1085219820Sjeff*		cl_list_tail, cl_list_next, or cl_list_prev.
1086219820Sjeff*
1087219820Sjeff* RETURN VALUES
1088219820Sjeff*	cl_list_iterator_t for the object preceding the object associated with
1089219820Sjeff*	the list iterator specified by the iterator parameter.
1090219820Sjeff*
1091219820Sjeff*	cl_list_iterator_t for the end of the list if the list is empty.
1092219820Sjeff*
1093219820Sjeff* NOTES
1094219820Sjeff*	Use cl_list_obj to retrieve the object associated with the
1095219820Sjeff*	returned cl_list_iterator_t.
1096219820Sjeff*
1097219820Sjeff* SEE ALSO
1098219820Sjeff*	List, cl_list_next, cl_list_head, cl_list_tail, cl_list_end,
1099219820Sjeff*	cl_list_obj
1100219820Sjeff*********/
1101219820Sjeff
1102219820Sjeff/****f* Component Library: List/cl_list_obj
1103219820Sjeff* NAME
1104219820Sjeff*	cl_list_obj
1105219820Sjeff*
1106219820Sjeff* DESCRIPTION
1107219820Sjeff*	The cl_list_obj function returns the object associated
1108219820Sjeff*	with a list iterator.
1109219820Sjeff*
1110219820Sjeff* SYNOPSIS
1111219820Sjeff*/
1112219820Sjeffstatic inline void *cl_list_obj(IN cl_list_iterator_t iterator)
1113219820Sjeff{
1114219820Sjeff	CL_ASSERT(iterator);
1115219820Sjeff
1116219820Sjeff	return ((void *)((cl_pool_obj_t *) iterator)->p_object);
1117219820Sjeff}
1118219820Sjeff
1119219820Sjeff/*
1120219820Sjeff* PARAMETERS
1121219820Sjeff*	iterator
1122219820Sjeff*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
1123219820Sjeff*		cl_list_tail, cl_list_next, or cl_list_prev whose object is requested.
1124219820Sjeff*
1125219820Sjeff* RETURN VALUE
1126219820Sjeff*	Pointer to the object associated with the list iterator specified
1127219820Sjeff*	by the iterator parameter.
1128219820Sjeff*
1129219820Sjeff* SEE ALSO
1130219820Sjeff*	List, cl_list_head, cl_list_tail, cl_list_next, cl_list_prev
1131219820Sjeff*********/
1132219820Sjeff
1133219820Sjeff/****f* Component Library: List/cl_list_find_from_head
1134219820Sjeff* NAME
1135219820Sjeff*	cl_list_find_from_head
1136219820Sjeff*
1137219820Sjeff* DESCRIPTION
1138219820Sjeff*	The cl_list_find_from_head function uses a specified function
1139219820Sjeff*	to search for an object starting from the head of a list.
1140219820Sjeff*
1141219820Sjeff* SYNOPSIS
1142219820Sjeff*/
1143219820Sjeffcl_list_iterator_t
1144219820Sjeffcl_list_find_from_head(IN const cl_list_t * const p_list,
1145219820Sjeff		       IN cl_pfn_list_find_t pfn_func,
1146219820Sjeff		       IN const void *const context);
1147219820Sjeff/*
1148219820Sjeff* PARAMETERS
1149219820Sjeff*	p_list
1150219820Sjeff*		[in] Pointer to a cl_list_t structure to search.
1151219820Sjeff*
1152219820Sjeff*	pfn_func
1153219820Sjeff*		[in] Function invoked to determine if a match was found.
1154219820Sjeff*		See the cl_pfn_list_find_t function type declaration for details
1155219820Sjeff*		about the callback function.
1156219820Sjeff*
1157219820Sjeff*	context
1158219820Sjeff*		[in] Value to pass to the callback functions to provide context.
1159219820Sjeff*
1160219820Sjeff* RETURN VALUES
1161219820Sjeff*	Returns the iterator for the object if found.
1162219820Sjeff*
1163219820Sjeff*	Returns the iterator for the list end otherwise.
1164219820Sjeff*
1165219820Sjeff* NOTES
1166219820Sjeff*	cl_list_find_from_head does not remove the found object from
1167219820Sjeff*	the list.  The iterator for the object is returned when the function
1168219820Sjeff*	provided by the pfn_func parameter returns CL_SUCCESS.  The function
1169219820Sjeff*	specified by the pfn_func parameter must not perform any list
1170219820Sjeff*	operations as these would corrupt the list.
1171219820Sjeff*
1172219820Sjeff* SEE ALSO
1173219820Sjeff*	List, cl_list_find_from_tail, cl_list_apply_func_t,
1174219820Sjeff*	cl_pfn_list_find_t
1175219820Sjeff*********/
1176219820Sjeff
1177219820Sjeff/****f* Component Library: List/cl_list_find_from_tail
1178219820Sjeff* NAME
1179219820Sjeff*	cl_list_find_from_tail
1180219820Sjeff*
1181219820Sjeff* DESCRIPTION
1182219820Sjeff*	The cl_list_find_from_tail function uses a specified function
1183219820Sjeff*	to search for an object starting from the tail of a list.
1184219820Sjeff*
1185219820Sjeff* SYNOPSIS
1186219820Sjeff*/
1187219820Sjeffcl_list_iterator_t
1188219820Sjeffcl_list_find_from_tail(IN const cl_list_t * const p_list,
1189219820Sjeff		       IN cl_pfn_list_find_t pfn_func,
1190219820Sjeff		       IN const void *const context);
1191219820Sjeff/*
1192219820Sjeff* PARAMETERS
1193219820Sjeff*	p_list
1194219820Sjeff*		[in] Pointer to a cl_list_t structure to search.
1195219820Sjeff*
1196219820Sjeff*	pfn_func
1197219820Sjeff*		[in] Function invoked to determine if a match was found.
1198219820Sjeff*		See the cl_pfn_list_find_t function type declaration for details
1199219820Sjeff*		about the callback function.
1200219820Sjeff*
1201219820Sjeff*	context
1202219820Sjeff*		[in] Value to pass to the callback functions to provide context.
1203219820Sjeff*
1204219820Sjeff* RETURN VALUES
1205219820Sjeff*	Returns the iterator for the object if found.
1206219820Sjeff*
1207219820Sjeff*	Returns the iterator for the list end otherwise.
1208219820Sjeff*
1209219820Sjeff* NOTES
1210219820Sjeff*	cl_list_find_from_tail does not remove the found object from
1211219820Sjeff*	the list.  The iterator for the object is returned when the function
1212219820Sjeff*	provided by the pfn_func parameter returns CL_SUCCESS.  The function
1213219820Sjeff*	specified by the pfn_func parameter must not perform any list
1214219820Sjeff*	operations as these would corrupt the list.
1215219820Sjeff*
1216219820Sjeff* SEE ALSO
1217219820Sjeff*	List, cl_list_find_from_head, cl_list_apply_func_t,
1218219820Sjeff*	cl_pfn_list_find_t
1219219820Sjeff*********/
1220219820Sjeff
1221219820Sjeff/****f* Component Library: List/cl_list_apply_func
1222219820Sjeff* NAME
1223219820Sjeff*	cl_list_apply_func
1224219820Sjeff*
1225219820Sjeff* DESCRIPTION
1226219820Sjeff*	The cl_list_apply_func function executes a specified function for every
1227219820Sjeff*	object stored in a list.
1228219820Sjeff*
1229219820Sjeff* SYNOPSIS
1230219820Sjeff*/
1231219820Sjeffvoid
1232219820Sjeffcl_list_apply_func(IN const cl_list_t * const p_list,
1233219820Sjeff		   IN cl_pfn_list_apply_t pfn_func,
1234219820Sjeff		   IN const void *const context);
1235219820Sjeff/*
1236219820Sjeff* PARAMETERS
1237219820Sjeff*	p_list
1238219820Sjeff*		[in] Pointer to a cl_list_t structure to iterate.
1239219820Sjeff*
1240219820Sjeff*	pfn_func
1241219820Sjeff*		[in] Function invoked for every item in a list.
1242219820Sjeff*		See the cl_pfn_list_apply_t function type declaration for details
1243219820Sjeff*		about the callback function.
1244219820Sjeff*
1245219820Sjeff*	context
1246219820Sjeff*		[in] Value to pass to the callback functions to provide context.
1247219820Sjeff*
1248219820Sjeff* RETURN VALUE
1249219820Sjeff*	This function does not return a value.
1250219820Sjeff*
1251219820Sjeff* NOTES
1252219820Sjeff*	cl_list_apply_func invokes the specified callback function for every
1253219820Sjeff*	object stored in the list, starting from the head.  The function specified
1254219820Sjeff*	by the pfn_func parameter must not perform any list operations as these
1255219820Sjeff*	would corrupt the list.
1256219820Sjeff*
1257219820Sjeff* SEE ALSO
1258219820Sjeff*	List, cl_list_find_from_head, cl_list_find_from_tail,
1259219820Sjeff*	cl_pfn_list_apply_t
1260219820Sjeff*********/
1261219820Sjeff
1262219820Sjeff/****f* Component Library: List/cl_list_count
1263219820Sjeff* NAME
1264219820Sjeff*	cl_list_count
1265219820Sjeff*
1266219820Sjeff* DESCRIPTION
1267219820Sjeff*	The cl_list_count function returns the number of objects stored in a list.
1268219820Sjeff*
1269219820Sjeff* SYNOPSIS
1270219820Sjeff*/
1271219820Sjeffstatic inline size_t cl_list_count(IN const cl_list_t * const p_list)
1272219820Sjeff{
1273219820Sjeff	CL_ASSERT(p_list);
1274219820Sjeff	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
1275219820Sjeff
1276219820Sjeff	return (cl_qlist_count(&p_list->list));
1277219820Sjeff}
1278219820Sjeff
1279219820Sjeff/*
1280219820Sjeff* PARAMETERS
1281219820Sjeff*	p_list
1282219820Sjeff*		[in] Pointer to a cl_list_t structure whose object to count.
1283219820Sjeff*
1284219820Sjeff* RETURN VALUES
1285219820Sjeff*	Number of objects stored in the specified list.
1286219820Sjeff*
1287219820Sjeff* SEE ALSO
1288219820Sjeff*	List
1289219820Sjeff*********/
1290219820Sjeff
1291219820SjeffEND_C_DECLS
1292219820Sjeff#endif				/* _CL_LIST_H_ */
1293