Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
/*
 * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

/*
 * Abstract:
 *	Declaration of list.
 */

#ifndef _CL_LIST_H_
#define _CL_LIST_H_

#include <complib/cl_qlist.h>
#include <complib/cl_qpool.h>

#ifdef __cplusplus
#  define BEGIN_C_DECLS extern "C" {
#  define END_C_DECLS   }
#else				/* !__cplusplus */
#  define BEGIN_C_DECLS
#  define END_C_DECLS
#endif				/* __cplusplus */

BEGIN_C_DECLS
/****h* Component Library/List
* NAME
*	List
*
* DESCRIPTION
*	List stores objects in a doubly linked list.
*
*	Unlike quick list, users pass pointers to the object being stored, rather
*	than to a cl_list_item_t structure.  Insertion operations on a list can
*	fail, and callers should trap for such failures.
*
*	Use quick list in situations where insertion failures cannot be tolerated.
*
*	List is not thread safe, and users must provide serialization.
*
*	The list functions operates on a cl_list_t structure which should be
*	treated as opaque and should be manipulated only through the provided
*	functions.
*
* SEE ALSO
*	Types:
*		cl_list_iterator_t
*
*	Structures:
*		cl_list_t
*
*	Callbacks:
*		cl_pfn_list_apply_t, cl_pfn_list_find_t
*
*	Initialization/Destruction:
*		cl_list_construct, cl_list_init, cl_list_destroy
*
*	Iteration:
*		cl_list_next, cl_list_prev, cl_list_head, cl_list_tail,
*		cl_list_end
*
*	Manipulation:
*		cl_list_insert_head, cl_list_insert_tail,
*		cl_list_insert_array_head, cl_list_insert_array_tail,
*		cl_list_insert_prev, cl_list_insert_next,
*		cl_list_remove_head, cl_list_remove_tail,
*		cl_list_remove_object, cl_list_remove_item, cl_list_remove_all
*
*	Search:
*		cl_is_object_in_list, cl_list_find_from_head, cl_list_find_from_tail,
*		cl_list_apply_func
*
*	Attributes:
*		cl_list_count, cl_is_list_empty, cl_is_list_inited
*********/
/****s* Component Library: List/cl_list_t
* NAME
*	cl_list_t
*
* DESCRIPTION
*	List structure.
*
*	The cl_list_t structure should be treated as opaque and should be
*	manipulated only through the provided functions.
*
* SYNOPSIS
*/
typedef struct _cl_list {
	cl_qlist_t list;
	cl_qpool_t list_item_pool;
} cl_list_t;
/*
* FIELDS
*	list
*		Quick list of items stored in the list.
*
*	list_item_pool
*		Quick pool of list objects for storing objects in the quick list.
*
* SEE ALSO
*	List
*********/

/****d* Component Library: List/cl_list_iterator_t
* NAME
*	cl_list_iterator_t
*
* DESCRIPTION
*	Iterator type used to walk a list.
*
* SYNOPSIS
*/
typedef const cl_list_item_t *cl_list_iterator_t;
/*
* NOTES
*	The iterator should be treated as opaque to prevent corrupting the list.
*
* SEE ALSO
*	List, cl_list_head, cl_list_tail, cl_list_next, cl_list_prev,
*	cl_list_obj
*********/

/****d* Component Library: List/cl_pfn_list_apply_t
* NAME
*	cl_pfn_list_apply_t
*
* DESCRIPTION
*	The cl_pfn_list_apply_t function type defines the prototype for functions
*	used to iterate objects in a list.
*
* SYNOPSIS
*/
typedef void
 (*cl_pfn_list_apply_t) (IN void *const p_object, IN void *context);
/*
* PARAMETERS
*	p_object
*		[in] Pointer to an object stored in a list.
*
*	context
*		[in] Context provided in a call to cl_list_apply_func.
*
* RETURN VALUE
*	This function does not return a value.
*
* NOTES
*	This function type is provided as function prototype reference for the
*	function provided by users as a parameter to the cl_list_apply_func
*	function.
*
* SEE ALSO
*	List, cl_list_apply_func
*********/

/****d* Component Library: List/cl_pfn_list_find_t
* NAME
*	cl_pfn_list_find_t
*
* DESCRIPTION
*	The cl_pfn_list_find_t function type defines the prototype for functions
*	used to find objects in a list.
*
* SYNOPSIS
*/
typedef cl_status_t
    (*cl_pfn_list_find_t) (IN const void *const p_object, IN void *context);
/*
* PARAMETERS
*	p_object
*		[in] Pointer to an object stored in a list.
*
*	context
*		[in] Context provided in a call to ListFindFromHead or ListFindFromTail.
*
* RETURN VALUES
*	Return CL_SUCCESS if the desired item was found.  This stops list iteration.
*
*	Return CL_NOT_FOUND to continue the list iteration.
*
* NOTES
*	This function type is provided as function prototype reference for the
*	function provided by users as a parameter to the cl_list_find_from_head
*	and cl_list_find_from_tail functions.
*
* SEE ALSO
*	List, cl_list_find_from_head, cl_list_find_from_tail
*********/

/****f* Component Library: List/cl_list_construct
* NAME
*	cl_list_construct
*
* DESCRIPTION
*	The cl_list_construct function constructs a list.
*
* SYNOPSIS
*/
void cl_list_construct(IN cl_list_t * const p_list);
/*
* PARAMETERS
*	p_list
*		[in] Pointer to cl_list_t object whose state to initialize.
*
* RETURN VALUE
*	This function does not return a value.
*
* NOTES
*	Allows calling cl_list_init, cl_list_destroy and cl_is_list_inited.
*
*	Calling cl_list_construct is a prerequisite to calling any other
*	list function except cl_list_init.
*
* SEE ALSO
*	List, cl_list_init, cl_list_destroy, cl_is_list_inited
*********/

/****f* Component Library: List/cl_is_list_inited
* NAME
*	cl_is_list_inited
*
* DESCRIPTION
*	The cl_is_list_inited function returns whether a list was
*	initialized successfully.
*
* SYNOPSIS
*/
static inline boolean_t cl_is_list_inited(IN const cl_list_t * const p_list)
{
	/* CL_ASSERT that a non-null pointer is provided. */
	CL_ASSERT(p_list);
	/*
	 * The pool is the last thing initialized.  If it is initialized, the
	 * list is initialized too.
	 */
	return (cl_is_qpool_inited(&p_list->list_item_pool));
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure whose initilization state
*		to check.
*
* RETURN VALUES
*	TRUE if the list was initialized successfully.
*
*	FALSE otherwise.
*
* NOTES
*	Allows checking the state of a list to determine if invoking
*	member functions is appropriate.
*
* SEE ALSO
*	List
*********/

/****f* Component Library: List/cl_list_init
* NAME
*	cl_list_init
*
* DESCRIPTION
*	The cl_list_init function initializes a list for use.
*
* SYNOPSIS
*/
cl_status_t
cl_list_init(IN cl_list_t * const p_list, IN const size_t min_items);
/*
* PARAMETERS
*	p_list
*		[in] Pointer to cl_list_t structure to initialize.
*
*	min_items
*		[in] Minimum number of items that can be stored.  All necessary
*		allocations to allow storing the minimum number of items is performed
*		at initialization time.
*
* RETURN VALUES
*	CL_SUCCESS if the list was initialized successfully.
*
*	CL_INSUFFICIENT_MEMORY if there was not enough memory for initialization.
*
* NOTES
*	The list will always be able to store at least as many items as specified
*	by the min_items parameter.
*
* SEE ALSO
*	List, cl_list_construct, cl_list_destroy, cl_list_insert_head,
*	cl_list_insert_tail, cl_list_remove_head, cl_list_remove_tail
*********/

/****f* Component Library: List/cl_list_destroy
* NAME
*	cl_list_destroy
*
* DESCRIPTION
*	The cl_list_destroy function destroys a list.
*
* SYNOPSIS
*/
void cl_list_destroy(IN cl_list_t * const p_list);
/*
* PARAMETERS
*	p_list
*		[in] Pointer to cl_list_t structure to destroy.
*
* RETURN VALUE
*	This function does not return a value.
*
* NOTES
*	cl_list_destroy does not affect any of the objects stored in the list,
*	but does release all memory allocated internally.  Further operations
*	should not be attempted on the list after cl_list_destroy is invoked.
*
*	This function should only be called after a call to cl_list_construct
*	or cl_list_init.
*
*	In debug builds, cl_list_destroy asserts if the list is not empty.
*
* SEE ALSO
*	List, cl_list_construct, cl_list_init
*********/

/****f* Component Library: List/cl_is_list_empty
* NAME
*	cl_is_list_empty
*
* DESCRIPTION
*	The cl_is_list_empty function returns whether a list is empty.
*
* SYNOPSIS
*/
static inline boolean_t cl_is_list_empty(IN const cl_list_t * const p_list)
{
	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
	return (cl_is_qlist_empty(&p_list->list));
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure.
*
* RETURN VALUES
*	TRUE if the specified list is empty.
*
*	FALSE otherwise.
*
* SEE ALSO
*	List, cl_list_count, cl_list_remove_all
*********/

/****f* Component Library: List/cl_list_insert_head
* NAME
*	cl_list_insert_head
*
* DESCRIPTION
*	The cl_list_insert_head function inserts an object at the head of a list.
*
* SYNOPSIS
*/
static inline cl_status_t
cl_list_insert_head(IN cl_list_t * const p_list, IN const void *const p_object)
{
	cl_pool_obj_t *p_pool_obj;

	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	/* Get a list item to add to the list. */
	p_pool_obj = (cl_pool_obj_t *) cl_qpool_get(&p_list->list_item_pool);
	if (!p_pool_obj)
		return (CL_INSUFFICIENT_MEMORY);

	p_pool_obj->p_object = p_object;
	cl_qlist_insert_head(&p_list->list, &p_pool_obj->pool_item.list_item);
	return (CL_SUCCESS);
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure into which to insert the object.
*
*	p_object
*		[in] Pointer to an object to insert into the list.
*
* RETURN VALUES
*	CL_SUCCESS if the insertion was successful.
*
*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
*
* NOTES
*	Inserts the specified object at the head of the list.  List insertion
*	operations are guaranteed to work for the minimum number of items as
*	specified in cl_list_init by the min_items parameter.
*
* SEE ALSO
*	List, cl_list_insert_tail, cl_list_insert_array_head,
*	cl_list_insert_array_tail, cl_list_insert_prev, cl_list_insert_next,
*	cl_list_remove_head
*********/

/****f* Component Library: List/cl_list_insert_tail
* NAME
*	cl_list_insert_tail
*
* DESCRIPTION
*	The cl_list_insert_tail function inserts an object at the tail of a list.
*
* SYNOPSIS
*/
static inline cl_status_t
cl_list_insert_tail(IN cl_list_t * const p_list, IN const void *const p_object)
{
	cl_pool_obj_t *p_pool_obj;

	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	/* Get a list item to add to the list. */
	p_pool_obj = (cl_pool_obj_t *) cl_qpool_get(&p_list->list_item_pool);
	if (!p_pool_obj)
		return (CL_INSUFFICIENT_MEMORY);

	p_pool_obj->p_object = p_object;
	cl_qlist_insert_tail(&p_list->list, &p_pool_obj->pool_item.list_item);
	return (CL_SUCCESS);
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure into which to insert the object.
*
*	p_object
*		[in] Pointer to an object to insert into the list.
*
* RETURN VALUES
*	CL_SUCCESS if the insertion was successful.
*
*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
*
* NOTES
*	Inserts the specified object at the tail of the list.  List insertion
*	operations are guaranteed to work for the minimum number of items as
*	specified in cl_list_init by the min_items parameter.
*
* SEE ALSO
*	List, cl_list_insert_head, cl_list_insert_array_head,
*	cl_list_insert_array_tail, cl_list_insert_prev, cl_list_insert_next,
*	cl_list_remove_tail
*********/

/****f* Component Library: List/cl_list_insert_array_head
* NAME
*	cl_list_insert_array_head
*
* DESCRIPTION:
*	The cl_list_insert_array_head function inserts an array of objects
*	at the head of a list.
*
* SYNOPSIS
*/
cl_status_t
cl_list_insert_array_head(IN cl_list_t * const p_list,
			  IN const void *const p_array,
			  IN uint32_t item_count, IN const uint32_t item_size);
/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure into which to insert the objects.
*
*	p_array
*		[in] Pointer to the first object in an array.
*
*	item_count
*		[in] Number of objects in the array.
*
*	item_size
*		[in] Size of the objects added to the list.  This is the stride in the
*		array from one object to the next.
*
* RETURN VALUES
*	CL_SUCCESS if the insertion was successful.
*
*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
*
* NOTES
*	Inserts all objects in the array to the head of the list, preserving the
*	ordering of the objects.  If not successful, no items are added.
*	List insertion operations are guaranteed to work for the minimum number
*	of items as specified in cl_list_init by the min_items parameter.
*
* SEE ALSO
*	List, cl_list_insert_array_tail, cl_list_insert_head, cl_list_insert_tail,
*	cl_list_insert_prev, cl_list_insert_next
*********/

/****f* Component Library: List/cl_list_insert_array_tail
* NAME
*	cl_list_insert_array_tail
*
* DESCRIPTION
*	The cl_list_insert_array_tail function inserts an array of objects
*	at the tail of a list.
*
* SYNOPSIS
*/
cl_status_t
cl_list_insert_array_tail(IN cl_list_t * const p_list,
			  IN const void *const p_array,
			  IN uint32_t item_count, IN const uint32_t item_size);
/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure into which to insert the objects.
*
*	p_array
*		[in] Pointer to the first object in an array.
*
*	item_count
*		[in] Number of objects in the array.
*
*	item_size
*		[in] Size of the objects added to the list.  This is the stride in the
*		array from one object to the next.
*
* RETURN VALUES
*	CL_SUCCESS if the insertion was successful.
*
*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
*
* NOTES
*	Inserts all objects in the array to the tail of the list, preserving the
*	ordering of the objects.  If not successful, no items are added.
*	List insertion operations are guaranteed to work for the minimum number
*	of items as specified in cl_list_init by the min_items parameter.
*
* SEE ALSO
*	List, cl_list_insert_array_head, cl_list_insert_head, cl_list_insert_tail,
*	cl_list_insert_prev, cl_list_insert_next
*********/

/****f* Component Library: List/cl_list_insert_next
* NAME
*	cl_list_insert_next
*
* DESCRIPTION
*	The cl_list_insert_next function inserts an object in a list after
*	the object associated with a given iterator.
*
* SYNOPSIS
*/
static inline cl_status_t
cl_list_insert_next(IN cl_list_t * const p_list,
		    IN cl_list_iterator_t iterator,
		    IN const void *const p_object)
{
	cl_pool_obj_t *p_pool_obj;

	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	/* Get a list item to add to the list. */
	p_pool_obj = (cl_pool_obj_t *) cl_qpool_get(&p_list->list_item_pool);
	if (!p_pool_obj)
		return (CL_INSUFFICIENT_MEMORY);

	p_pool_obj->p_object = p_object;
	cl_qlist_insert_next(&p_list->list, (cl_list_item_t *) iterator,
			     &p_pool_obj->pool_item.list_item);
	return (CL_SUCCESS);
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure into which to insert the object.
*
*	iterator
*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
*		cl_list_tail, cl_list_next, or cl_list_prev.
*
*	p_object
*		[in] Pointer to an object to insert into the list.
*
* RETURN VALUES
*	CL_SUCCESS if the insertion was successful.
*
*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
*
* SEE ALSO
*	List, cl_list_insert_prev, cl_list_insert_head, cl_list_insert_tail,
*	cl_list_insert_array_head, cl_list_insert_array_tail
*********/

/****f* Component Library: List/cl_list_insert_prev
* NAME
*	cl_list_insert_prev
*
* DESCRIPTION
*	The cl_list_insert_prev function inserts an object in a list before
*	the object associated with a given iterator.
*
* SYNOPSIS
*/
static inline cl_status_t
cl_list_insert_prev(IN cl_list_t * const p_list,
		    IN cl_list_iterator_t iterator,
		    IN const void *const p_object)
{
	cl_pool_obj_t *p_pool_obj;

	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	/* Get a list item to add to the list. */
	p_pool_obj = (cl_pool_obj_t *) cl_qpool_get(&p_list->list_item_pool);
	if (!p_pool_obj)
		return (CL_INSUFFICIENT_MEMORY);

	p_pool_obj->p_object = p_object;
	cl_qlist_insert_prev(&p_list->list, (cl_list_item_t *) iterator,
			     &p_pool_obj->pool_item.list_item);
	return (CL_SUCCESS);
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure into which to insert the object.
*
*	iterator
*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
*		cl_list_tail, cl_list_next, or cl_list_prev.
*
*	p_object
*		[in] Pointer to an object to insert into the list.
*
* RETURN VALUES
*	CL_SUCCESS if the insertion was successful.
*
*	CL_INSUFFICIENT_MEMORY if there was not enough memory for the insertion.
*
* SEE ALSO
*	List, cl_list_insert_next, cl_list_insert_head, cl_list_insert_tail,
*	cl_list_insert_array_head, cl_list_insert_array_tail
*********/

/****f* Component Library: List/cl_list_remove_head
* NAME
*	cl_list_remove_head
*
* DESCRIPTION
*	The cl_list_remove_head function removes an object from the head of a list.
*
* SYNOPSIS
*/
static inline void *cl_list_remove_head(IN cl_list_t * const p_list)
{
	cl_pool_obj_t *p_pool_obj;
	void *p_obj;

	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	/* See if the list is empty. */
	if (cl_is_qlist_empty(&p_list->list))
		return (NULL);

	/* Get the item at the head of the list. */
	p_pool_obj = (cl_pool_obj_t *) cl_qlist_remove_head(&p_list->list);

	p_obj = (void *)p_pool_obj->p_object;
	/* Place the pool item back into the pool. */
	cl_qpool_put(&p_list->list_item_pool, &p_pool_obj->pool_item);

	return (p_obj);
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure from which to remove an object.
*
* RETURN VALUES
*	Returns the pointer to the object formerly at the head of the list.
*
*	NULL if the list was empty.
*
* SEE ALSO
*	List, cl_list_remove_tail, cl_list_remove_all, cl_list_remove_object,
*	cl_list_remove_item, cl_list_insert_head
*********/

/****f* Component Library: List/cl_list_remove_tail
* NAME
*	cl_list_remove_tail
*
* DESCRIPTION
*	The cl_list_remove_tail function removes an object from the tail of a list.
*
* SYNOPSIS
*/
static inline void *cl_list_remove_tail(IN cl_list_t * const p_list)
{
	cl_pool_obj_t *p_pool_obj;

	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	/* See if the list is empty. */
	if (cl_is_qlist_empty(&p_list->list))
		return (NULL);

	/* Get the item at the head of the list. */
	p_pool_obj = (cl_pool_obj_t *) cl_qlist_remove_tail(&p_list->list);

	/* Place the list item back into the pool. */
	cl_qpool_put(&p_list->list_item_pool, &p_pool_obj->pool_item);

	return ((void *)p_pool_obj->p_object);
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure from which to remove an object.
*
* RETURN VALUES
*	Returns the pointer to the object formerly at the tail of the list.
*
*	NULL if the list was empty.
*
* SEE ALSO
*	List, cl_list_remove_head, cl_list_remove_all, cl_list_remove_object,
*	cl_list_remove_item, cl_list_insert_head
*********/

/****f* Component Library: List/cl_list_remove_all
* NAME
*	cl_list_remove_all
*
* DESCRIPTION
*	The cl_list_remove_all function removes all objects from a list,
*	leaving it empty.
*
* SYNOPSIS
*/
static inline void cl_list_remove_all(IN cl_list_t * const p_list)
{
	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	/* Return all the list items to the pool. */
	cl_qpool_put_list(&p_list->list_item_pool, &p_list->list);
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure from which to remove all objects.
*
* RETURN VALUE
*	This function does not return a value.
*
* SEE ALSO
*	List, cl_list_remove_head, cl_list_remove_tail, cl_list_remove_object,
*	cl_list_remove_item
*********/

/****f* Component Library: List/cl_list_remove_object
* NAME
*	cl_list_remove_object
*
* DESCRIPTION
*	The cl_list_remove_object function removes a specific object from a list.
*
* SYNOPSIS
*/
cl_status_t
cl_list_remove_object(IN cl_list_t * const p_list,
		      IN const void *const p_object);
/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure from which to remove the object.
*
*	p_object
*		[in] Pointer to an object to remove from the list.
*
* RETURN VALUES
*	CL_SUCCESS if the object was removed.
*
*	CL_NOT_FOUND if the object was not found in the list.
*
* NOTES
*	Removes the first occurrence of an object from a list.
*
* SEE ALSO
*	List, cl_list_remove_item, cl_list_remove_head, cl_list_remove_tail,
*	cl_list_remove_all
*********/

/****f* Component Library: List/cl_list_remove_item
* NAME
*	cl_list_remove_item
*
* DESCRIPTION
*	The cl_list_remove_item function removes an object from the head of a list.
*
* SYNOPSIS
*/
static inline void
cl_list_remove_item(IN cl_list_t * const p_list, IN cl_list_iterator_t iterator)
{
	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	cl_qlist_remove_item(&p_list->list, (cl_list_item_t *) iterator);

	/* Place the list item back into the pool. */
	cl_qpool_put(&p_list->list_item_pool, (cl_pool_item_t *) iterator);
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure from which to remove the item.
*
*	iterator
*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
*		cl_list_tail, cl_list_next, or cl_list_prev.
*
* RETURN VALUE
*	This function does not return a value.
*
* SEE ALSO
*	List, cl_list_remove_object, cl_list_remove_head, cl_list_remove_tail,
*	cl_list_remove_all
*********/

/****f* Component Library: List/cl_is_object_in_list
* NAME
*	cl_is_object_in_list
*
* DESCRIPTION
*	The cl_is_object_in_list function returns whether an object
*	is stored in a list.
*
* SYNOPSIS
*/
boolean_t
cl_is_object_in_list(IN const cl_list_t * const p_list,
		     IN const void *const p_object);
/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure in which to look for the object.
*
*	p_object
*		[in] Pointer to an object stored in a list.
*
* RETURN VALUES
*	TRUE if p_object was found in the list.
*
*	FALSE otherwise.
*
* SEE ALSO
*	List
*********/

/****f* Component Library: List/cl_list_end
* NAME
*	cl_list_end
*
* DESCRIPTION
*	The cl_list_end function returns returns the list iterator for
*	the end of a list.
*
* SYNOPSIS
*/
static inline cl_list_iterator_t cl_list_end(IN const cl_list_t * const p_list)
{
	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	return (cl_qlist_end(&p_list->list));
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure for which the iterator for the
*		object at the head is to be returned.
*
* RETURN VALUE
*	cl_list_iterator_t for the end of the list.
*
* NOTES
*	Use cl_list_obj to retrieve the object associated with the
*	returned cl_list_iterator_t.
*
* SEE ALSO
*	List, cl_list_head, cl_list_tail, cl_list_next, cl_list_prev,
*	cl_list_obj
*********/

/****f* Component Library: List/cl_list_head
* NAME
*	cl_list_head
*
* DESCRIPTION
*	The cl_list_head function returns returns a list iterator for
*	the head of a list.
*
* SYNOPSIS
*/
static inline cl_list_iterator_t cl_list_head(IN const cl_list_t * const p_list)
{
	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	return (cl_qlist_head(&p_list->list));
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure for which the iterator for the
*		object at the head is to be returned.
*
* RETURN VALUES
*	cl_list_iterator_t for the head of the list.
*
*	cl_list_iterator_t for the end of the list if the list is empty.
*
* NOTES
*	Use cl_list_obj to retrieve the object associated with the
*	returned cl_list_iterator_t.
*
* SEE ALSO
*	List, cl_list_tail, cl_list_next, cl_list_prev, cl_list_end,
*	cl_list_obj
*********/

/****f* Component Library: List/cl_list_tail
* NAME
*	cl_list_tail
*
* DESCRIPTION
*	The cl_list_tail function returns returns a list iterator for
*	the tail of a list.
*
* SYNOPSIS
*/
static inline cl_list_iterator_t cl_list_tail(IN const cl_list_t * const p_list)
{
	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	return (cl_qlist_tail(&p_list->list));
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure for which the iterator for the
*		object at the tail is to be returned.
*
* RETURN VALUES
*	cl_list_iterator_t for the tail of the list.
*
*	cl_list_iterator_t for the end of the list if the list is empty.
*
* NOTES
*	Use cl_list_obj to retrieve the object associated with the
*
*	returned cl_list_iterator_t.
*
* SEE ALSO
*	List, cl_list_head, cl_list_next, cl_list_prev, cl_list_end,
*	cl_list_obj
*********/

/****f* Component Library: List/cl_list_next
* NAME
*	cl_list_next
*
* DESCRIPTION
*	The cl_list_next function returns a list iterator for the object stored
*	in a list after the object associated with a given list iterator.
*
* SYNOPSIS
*/
static inline cl_list_iterator_t cl_list_next(IN cl_list_iterator_t iterator)
{
	CL_ASSERT(iterator);

	return (cl_qlist_next(iterator));
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure for which the iterator for the
*		next object is to be returned.
*
*	iterator
*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
*		cl_list_tail, cl_list_next, or cl_list_prev.
*
* RETURN VALUES
*	cl_list_iterator_t for the object following the object associated with
*	the list iterator specified by the iterator parameter.
*
*	cl_list_iterator_t for the end of the list if the list is empty.
*
* NOTES
*	Use cl_list_obj to retrieve the object associated with the
*	returned cl_list_iterator_t.
*
* SEE ALSO
*	List, cl_list_prev, cl_list_head, cl_list_tail, cl_list_end,
*	cl_list_obj
*********/

/****f* Component Library: List/cl_list_prev
* NAME
*	cl_list_prev
*
* DESCRIPTION
*	The cl_list_prev function returns a list iterator for the object stored
*	in a list before the object associated with a given list iterator.
*
* SYNOPSIS
*/
static inline cl_list_iterator_t cl_list_prev(IN cl_list_iterator_t iterator)
{
	CL_ASSERT(iterator);

	return (cl_qlist_prev(iterator));
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure for which the iterator for the
*		next object is to be returned.
*
*	iterator
*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
*		cl_list_tail, cl_list_next, or cl_list_prev.
*
* RETURN VALUES
*	cl_list_iterator_t for the object preceding the object associated with
*	the list iterator specified by the iterator parameter.
*
*	cl_list_iterator_t for the end of the list if the list is empty.
*
* NOTES
*	Use cl_list_obj to retrieve the object associated with the
*	returned cl_list_iterator_t.
*
* SEE ALSO
*	List, cl_list_next, cl_list_head, cl_list_tail, cl_list_end,
*	cl_list_obj
*********/

/****f* Component Library: List/cl_list_obj
* NAME
*	cl_list_obj
*
* DESCRIPTION
*	The cl_list_obj function returns the object associated
*	with a list iterator.
*
* SYNOPSIS
*/
static inline void *cl_list_obj(IN cl_list_iterator_t iterator)
{
	CL_ASSERT(iterator);

	return ((void *)((cl_pool_obj_t *) iterator)->p_object);
}

/*
* PARAMETERS
*	iterator
*		[in] cl_list_iterator_t returned by a previous call to cl_list_head,
*		cl_list_tail, cl_list_next, or cl_list_prev whose object is requested.
*
* RETURN VALUE
*	Pointer to the object associated with the list iterator specified
*	by the iterator parameter.
*
* SEE ALSO
*	List, cl_list_head, cl_list_tail, cl_list_next, cl_list_prev
*********/

/****f* Component Library: List/cl_list_find_from_head
* NAME
*	cl_list_find_from_head
*
* DESCRIPTION
*	The cl_list_find_from_head function uses a specified function
*	to search for an object starting from the head of a list.
*
* SYNOPSIS
*/
cl_list_iterator_t
cl_list_find_from_head(IN const cl_list_t * const p_list,
		       IN cl_pfn_list_find_t pfn_func,
		       IN const void *const context);
/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure to search.
*
*	pfn_func
*		[in] Function invoked to determine if a match was found.
*		See the cl_pfn_list_find_t function type declaration for details
*		about the callback function.
*
*	context
*		[in] Value to pass to the callback functions to provide context.
*
* RETURN VALUES
*	Returns the iterator for the object if found.
*
*	Returns the iterator for the list end otherwise.
*
* NOTES
*	cl_list_find_from_head does not remove the found object from
*	the list.  The iterator for the object is returned when the function
*	provided by the pfn_func parameter returns CL_SUCCESS.  The function
*	specified by the pfn_func parameter must not perform any list
*	operations as these would corrupt the list.
*
* SEE ALSO
*	List, cl_list_find_from_tail, cl_list_apply_func_t,
*	cl_pfn_list_find_t
*********/

/****f* Component Library: List/cl_list_find_from_tail
* NAME
*	cl_list_find_from_tail
*
* DESCRIPTION
*	The cl_list_find_from_tail function uses a specified function
*	to search for an object starting from the tail of a list.
*
* SYNOPSIS
*/
cl_list_iterator_t
cl_list_find_from_tail(IN const cl_list_t * const p_list,
		       IN cl_pfn_list_find_t pfn_func,
		       IN const void *const context);
/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure to search.
*
*	pfn_func
*		[in] Function invoked to determine if a match was found.
*		See the cl_pfn_list_find_t function type declaration for details
*		about the callback function.
*
*	context
*		[in] Value to pass to the callback functions to provide context.
*
* RETURN VALUES
*	Returns the iterator for the object if found.
*
*	Returns the iterator for the list end otherwise.
*
* NOTES
*	cl_list_find_from_tail does not remove the found object from
*	the list.  The iterator for the object is returned when the function
*	provided by the pfn_func parameter returns CL_SUCCESS.  The function
*	specified by the pfn_func parameter must not perform any list
*	operations as these would corrupt the list.
*
* SEE ALSO
*	List, cl_list_find_from_head, cl_list_apply_func_t,
*	cl_pfn_list_find_t
*********/

/****f* Component Library: List/cl_list_apply_func
* NAME
*	cl_list_apply_func
*
* DESCRIPTION
*	The cl_list_apply_func function executes a specified function for every
*	object stored in a list.
*
* SYNOPSIS
*/
void
cl_list_apply_func(IN const cl_list_t * const p_list,
		   IN cl_pfn_list_apply_t pfn_func,
		   IN const void *const context);
/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure to iterate.
*
*	pfn_func
*		[in] Function invoked for every item in a list.
*		See the cl_pfn_list_apply_t function type declaration for details
*		about the callback function.
*
*	context
*		[in] Value to pass to the callback functions to provide context.
*
* RETURN VALUE
*	This function does not return a value.
*
* NOTES
*	cl_list_apply_func invokes the specified callback function for every
*	object stored in the list, starting from the head.  The function specified
*	by the pfn_func parameter must not perform any list operations as these
*	would corrupt the list.
*
* SEE ALSO
*	List, cl_list_find_from_head, cl_list_find_from_tail,
*	cl_pfn_list_apply_t
*********/

/****f* Component Library: List/cl_list_count
* NAME
*	cl_list_count
*
* DESCRIPTION
*	The cl_list_count function returns the number of objects stored in a list.
*
* SYNOPSIS
*/
static inline size_t cl_list_count(IN const cl_list_t * const p_list)
{
	CL_ASSERT(p_list);
	CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));

	return (cl_qlist_count(&p_list->list));
}

/*
* PARAMETERS
*	p_list
*		[in] Pointer to a cl_list_t structure whose object to count.
*
* RETURN VALUES
*	Number of objects stored in the specified list.
*
* SEE ALSO
*	List
*********/

END_C_DECLS
#endif				/* _CL_LIST_H_ */