Subversion Repositories Kolibri OS

Rev

Rev 5056 | Rev 6082 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5056 Rev 5270
Line 2... Line 2...
2
#define _LINUX_LIST_H
2
#define _LINUX_LIST_H
Line 3... Line 3...
3
 
3
 
4
#include 
4
#include 
5
#include 
5
#include 
-
 
6
#include 
-
 
7
#include 
Line 6... Line 8...
6
#include 
8
#include 
7
 
9
 
8
/*
10
/*
9
 * Simple doubly linked list implementation.
11
 * Simple doubly linked list implementation.
Line 342... Line 344...
342
 
344
 
343
/**
345
/**
344
 * list_entry - get the struct for this entry
346
 * list_entry - get the struct for this entry
345
 * @ptr:	the &struct list_head pointer.
347
 * @ptr:	the &struct list_head pointer.
346
 * @type:	the type of the struct this is embedded in.
348
 * @type:	the type of the struct this is embedded in.
347
 * @member:	the name of the list_struct within the struct.
349
 * @member:	the name of the list_head within the struct.
348
 */
350
 */
349
#define list_entry(ptr, type, member) \
351
#define list_entry(ptr, type, member) \
Line 350... Line 352...
350
	container_of(ptr, type, member)
352
	container_of(ptr, type, member)
351
 
353
 
352
/**
354
/**
353
 * list_first_entry - get the first element from a list
355
 * list_first_entry - get the first element from a list
354
 * @ptr:	the list head to take the element from.
356
 * @ptr:	the list head to take the element from.
355
 * @type:	the type of the struct this is embedded in.
357
 * @type:	the type of the struct this is embedded in.
356
 * @member:	the name of the list_struct within the struct.
358
 * @member:	the name of the list_head within the struct.
357
 *
359
 *
358
 * Note, that list is expected to be not empty.
360
 * Note, that list is expected to be not empty.
359
 */
361
 */
Line 360... Line 362...
360
#define list_first_entry(ptr, type, member) \
362
#define list_first_entry(ptr, type, member) \
361
	list_entry((ptr)->next, type, member)
363
	list_entry((ptr)->next, type, member)
362
 
364
 
363
/**
365
/**
364
 * list_last_entry - get the last element from a list
366
 * list_last_entry - get the last element from a list
365
 * @ptr:	the list head to take the element from.
367
 * @ptr:	the list head to take the element from.
366
 * @type:	the type of the struct this is embedded in.
368
 * @type:	the type of the struct this is embedded in.
367
 * @member:	the name of the list_struct within the struct.
369
 * @member:	the name of the list_head within the struct.
368
 *
370
 *
369
 * Note, that list is expected to be not empty.
371
 * Note, that list is expected to be not empty.
Line 370... Line 372...
370
 */
372
 */
371
#define list_last_entry(ptr, type, member) \
373
#define list_last_entry(ptr, type, member) \
372
	list_entry((ptr)->prev, type, member)
374
	list_entry((ptr)->prev, type, member)
373
 
375
 
374
/**
376
/**
375
 * list_first_entry_or_null - get the first element from a list
377
 * list_first_entry_or_null - get the first element from a list
376
 * @ptr:	the list head to take the element from.
378
 * @ptr:	the list head to take the element from.
377
 * @type:	the type of the struct this is embedded in.
379
 * @type:	the type of the struct this is embedded in.
378
 * @member:	the name of the list_struct within the struct.
380
 * @member:	the name of the list_head within the struct.
379
 *
381
 *
Line 380... Line 382...
380
 * Note that if the list is empty, it returns NULL.
382
 * Note that if the list is empty, it returns NULL.
381
 */
383
 */
382
#define list_first_entry_or_null(ptr, type, member) \
384
#define list_first_entry_or_null(ptr, type, member) \
383
	(!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
385
	(!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
384
 
386
 
385
/**
387
/**
386
 * list_next_entry - get the next element in list
388
 * list_next_entry - get the next element in list
Line 387... Line 389...
387
 * @pos:	the type * to cursor
389
 * @pos:	the type * to cursor
388
 * @member:	the name of the list_struct within the struct.
390
 * @member:	the name of the list_head within the struct.
389
 */
391
 */
390
#define list_next_entry(pos, member) \
392
#define list_next_entry(pos, member) \
391
	list_entry((pos)->member.next, typeof(*(pos)), member)
393
	list_entry((pos)->member.next, typeof(*(pos)), member)
392
 
394
 
393
/**
395
/**
Line 394... Line 396...
394
 * list_prev_entry - get the prev element in list
396
 * list_prev_entry - get the prev element in list
Line 437... Line 439...
437
 
439
 
438
/**
440
/**
439
 * list_for_each_entry	-	iterate over list of given type
441
 * list_for_each_entry	-	iterate over list of given type
440
 * @pos:	the type * to use as a loop cursor.
442
 * @pos:	the type * to use as a loop cursor.
441
 * @head:	the head for your list.
443
 * @head:	the head for your list.
442
 * @member:	the name of the list_struct within the struct.
444
 * @member:	the name of the list_head within the struct.
443
 */
445
 */
444
#define list_for_each_entry(pos, head, member)				\
446
#define list_for_each_entry(pos, head, member)				\
445
	for (pos = list_first_entry(head, typeof(*pos), member);	\
447
	for (pos = list_first_entry(head, typeof(*pos), member);	\
446
	     &pos->member != (head); 	\
448
	     &pos->member != (head); 	\
Line 447... Line 449...
447
	     pos = list_next_entry(pos, member))
449
	     pos = list_next_entry(pos, member))
448
 
450
 
449
/**
451
/**
450
 * list_for_each_entry_reverse - iterate backwards over list of given type.
452
 * list_for_each_entry_reverse - iterate backwards over list of given type.
451
 * @pos:	the type * to use as a loop cursor.
453
 * @pos:	the type * to use as a loop cursor.
452
 * @head:	the head for your list.
454
 * @head:	the head for your list.
453
 * @member:	the name of the list_struct within the struct.
455
 * @member:	the name of the list_head within the struct.
454
 */
456
 */
455
#define list_for_each_entry_reverse(pos, head, member)			\
457
#define list_for_each_entry_reverse(pos, head, member)			\
456
	for (pos = list_last_entry(head, typeof(*pos), member);		\
458
	for (pos = list_last_entry(head, typeof(*pos), member);		\
Line 457... Line 459...
457
	     &pos->member != (head); 	\
459
	     &pos->member != (head); 	\
458
	     pos = list_prev_entry(pos, member))
460
	     pos = list_prev_entry(pos, member))
459
 
461
 
460
/**
462
/**
461
 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
463
 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
462
 * @pos:	the type * to use as a start point
464
 * @pos:	the type * to use as a start point
463
 * @head:	the head of the list
465
 * @head:	the head of the list
464
 * @member:	the name of the list_struct within the struct.
466
 * @member:	the name of the list_head within the struct.
465
 *
467
 *
466
 * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
468
 * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
Line 467... Line 469...
467
 */
469
 */
468
#define list_prepare_entry(pos, head, member) \
470
#define list_prepare_entry(pos, head, member) \
469
	((pos) ? : list_entry(head, typeof(*pos), member))
471
	((pos) ? : list_entry(head, typeof(*pos), member))
470
 
472
 
471
/**
473
/**
472
 * list_for_each_entry_continue - continue iteration over list of given type
474
 * list_for_each_entry_continue - continue iteration over list of given type
473
 * @pos:	the type * to use as a loop cursor.
475
 * @pos:	the type * to use as a loop cursor.
474
 * @head:	the head for your list.
476
 * @head:	the head for your list.
475
 * @member:	the name of the list_struct within the struct.
477
 * @member:	the name of the list_head within the struct.
476
 *
478
 *
Line 484... Line 486...
484
 
486
 
485
/**
487
/**
486
 * list_for_each_entry_continue_reverse - iterate backwards from the given point
488
 * list_for_each_entry_continue_reverse - iterate backwards from the given point
487
 * @pos:	the type * to use as a loop cursor.
489
 * @pos:	the type * to use as a loop cursor.
488
 * @head:	the head for your list.
490
 * @head:	the head for your list.
489
 * @member:	the name of the list_struct within the struct.
491
 * @member:	the name of the list_head within the struct.
490
 *
492
 *
491
 * Start to iterate over list of given type backwards, continuing after
493
 * Start to iterate over list of given type backwards, continuing after
492
 * the current position.
494
 * the current position.
493
 */
495
 */
Line 498... Line 500...
498
 
500
 
499
/**
501
/**
500
 * list_for_each_entry_from - iterate over list of given type from the current point
502
 * list_for_each_entry_from - iterate over list of given type from the current point
501
 * @pos:	the type * to use as a loop cursor.
503
 * @pos:	the type * to use as a loop cursor.
502
 * @head:	the head for your list.
504
 * @head:	the head for your list.
503
 * @member:	the name of the list_struct within the struct.
505
 * @member:	the name of the list_head within the struct.
504
 *
506
 *
505
 * Iterate over list of given type, continuing from current position.
507
 * Iterate over list of given type, continuing from current position.
506
 */
508
 */
507
#define list_for_each_entry_from(pos, head, member) 			\
509
#define list_for_each_entry_from(pos, head, member) 			\
Line 511... Line 513...
511
/**
513
/**
512
 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
514
 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
513
 * @pos:	the type * to use as a loop cursor.
515
 * @pos:	the type * to use as a loop cursor.
514
 * @n:		another type * to use as temporary storage
516
 * @n:		another type * to use as temporary storage
515
 * @head:	the head for your list.
517
 * @head:	the head for your list.
516
 * @member:	the name of the list_struct within the struct.
518
 * @member:	the name of the list_head within the struct.
517
 */
519
 */
518
#define list_for_each_entry_safe(pos, n, head, member)			\
520
#define list_for_each_entry_safe(pos, n, head, member)			\
519
	for (pos = list_first_entry(head, typeof(*pos), member),	\
521
	for (pos = list_first_entry(head, typeof(*pos), member),	\
520
		n = list_next_entry(pos, member);			\
522
		n = list_next_entry(pos, member);			\
521
	     &pos->member != (head); 					\
523
	     &pos->member != (head); 					\
Line 524... Line 526...
524
/**
526
/**
525
 * list_for_each_entry_safe_continue - continue list iteration safe against removal
527
 * list_for_each_entry_safe_continue - continue list iteration safe against removal
526
 * @pos:	the type * to use as a loop cursor.
528
 * @pos:	the type * to use as a loop cursor.
527
 * @n:		another type * to use as temporary storage
529
 * @n:		another type * to use as temporary storage
528
 * @head:	the head for your list.
530
 * @head:	the head for your list.
529
 * @member:	the name of the list_struct within the struct.
531
 * @member:	the name of the list_head within the struct.
530
 *
532
 *
531
 * Iterate over list of given type, continuing after current point,
533
 * Iterate over list of given type, continuing after current point,
532
 * safe against removal of list entry.
534
 * safe against removal of list entry.
533
 */
535
 */
534
#define list_for_each_entry_safe_continue(pos, n, head, member) 		\
536
#define list_for_each_entry_safe_continue(pos, n, head, member) 		\
Line 540... Line 542...
540
/**
542
/**
541
 * list_for_each_entry_safe_from - iterate over list from current point safe against removal
543
 * list_for_each_entry_safe_from - iterate over list from current point safe against removal
542
 * @pos:	the type * to use as a loop cursor.
544
 * @pos:	the type * to use as a loop cursor.
543
 * @n:		another type * to use as temporary storage
545
 * @n:		another type * to use as temporary storage
544
 * @head:	the head for your list.
546
 * @head:	the head for your list.
545
 * @member:	the name of the list_struct within the struct.
547
 * @member:	the name of the list_head within the struct.
546
 *
548
 *
547
 * Iterate over list of given type from current point, safe against
549
 * Iterate over list of given type from current point, safe against
548
 * removal of list entry.
550
 * removal of list entry.
549
 */
551
 */
550
#define list_for_each_entry_safe_from(pos, n, head, member) 			\
552
#define list_for_each_entry_safe_from(pos, n, head, member) 			\
Line 555... Line 557...
555
/**
557
/**
556
 * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
558
 * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
557
 * @pos:	the type * to use as a loop cursor.
559
 * @pos:	the type * to use as a loop cursor.
558
 * @n:		another type * to use as temporary storage
560
 * @n:		another type * to use as temporary storage
559
 * @head:	the head for your list.
561
 * @head:	the head for your list.
560
 * @member:	the name of the list_struct within the struct.
562
 * @member:	the name of the list_head within the struct.
561
 *
563
 *
562
 * Iterate backwards over list of given type, safe against removal
564
 * Iterate backwards over list of given type, safe against removal
563
 * of list entry.
565
 * of list entry.
564
 */
566
 */
565
#define list_for_each_entry_safe_reverse(pos, n, head, member)		\
567
#define list_for_each_entry_safe_reverse(pos, n, head, member)		\
Line 570... Line 572...
570
 
572
 
571
/**
573
/**
572
 * list_safe_reset_next - reset a stale list_for_each_entry_safe loop
574
 * list_safe_reset_next - reset a stale list_for_each_entry_safe loop
573
 * @pos:	the loop cursor used in the list_for_each_entry_safe loop
575
 * @pos:	the loop cursor used in the list_for_each_entry_safe loop
574
 * @n:		temporary storage used in list_for_each_entry_safe
576
 * @n:		temporary storage used in list_for_each_entry_safe
575
 * @member:	the name of the list_struct within the struct.
577
 * @member:	the name of the list_head within the struct.
576
 *
578
 *
577
 * list_safe_reset_next is not safe to use in general if the list may be
579
 * list_safe_reset_next is not safe to use in general if the list may be
578
 * modified concurrently (eg. the lock is dropped in the loop body). An
580
 * modified concurrently (eg. the lock is dropped in the loop body). An
579
 * exception to this is if the cursor element (pos) is pinned in the list,
581
 * exception to this is if the cursor element (pos) is pinned in the list,