Subversion Repositories Kolibri OS

Rev

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

Rev 1964 Rev 1970
Line 3... Line 3...
3
 
3
 
4
#include 
4
#include 
5
#include 
5
#include 
Line 6... Line -...
6
#include 
-
 
7
 
-
 
8
#define prefetch(x) __builtin_prefetch(x)
6
#include 
9
 
7
 
10
/*
8
/*
11
 * Simple doubly linked list implementation.
9
 * Simple doubly linked list implementation.
12
 *
10
 *
Line 95... Line 93...
95
 * @entry: the element to delete from the list.
93
 * @entry: the element to delete from the list.
96
 * Note: list_empty() on entry does not return true after this, the entry is
94
 * Note: list_empty() on entry does not return true after this, the entry is
97
 * in an undefined state.
95
 * in an undefined state.
98
 */
96
 */
99
#ifndef CONFIG_DEBUG_LIST
97
#ifndef CONFIG_DEBUG_LIST
-
 
98
static inline void __list_del_entry(struct list_head *entry)
-
 
99
{
-
 
100
	__list_del(entry->prev, entry->next);
-
 
101
}
-
 
102
 
100
static inline void list_del(struct list_head *entry)
103
static inline void list_del(struct list_head *entry)
101
{
104
{
102
	__list_del(entry->prev, entry->next);
105
	__list_del(entry->prev, entry->next);
103
	entry->next = LIST_POISON1;
106
	entry->next = LIST_POISON1;
104
	entry->prev = LIST_POISON2;
107
	entry->prev = LIST_POISON2;
105
}
108
}
106
#else
109
#else
-
 
110
extern void __list_del_entry(struct list_head *entry);
107
extern void list_del(struct list_head *entry);
111
extern void list_del(struct list_head *entry);
108
#endif
112
#endif
Line 109... Line 113...
109
 
113
 
110
/**
114
/**
Line 134... Line 138...
134
 * list_del_init - deletes entry from list and reinitialize it.
138
 * list_del_init - deletes entry from list and reinitialize it.
135
 * @entry: the element to delete from the list.
139
 * @entry: the element to delete from the list.
136
 */
140
 */
137
static inline void list_del_init(struct list_head *entry)
141
static inline void list_del_init(struct list_head *entry)
138
{
142
{
139
	__list_del(entry->prev, entry->next);
143
	__list_del_entry(entry);
140
	INIT_LIST_HEAD(entry);
144
	INIT_LIST_HEAD(entry);
141
}
145
}
Line 142... Line 146...
142
 
146
 
143
/**
147
/**
144
 * list_move - delete from one list and add as another's head
148
 * list_move - delete from one list and add as another's head
145
 * @list: the entry to move
149
 * @list: the entry to move
146
 * @head: the head that will precede our entry
150
 * @head: the head that will precede our entry
147
 */
151
 */
148
static inline void list_move(struct list_head *list, struct list_head *head)
152
static inline void list_move(struct list_head *list, struct list_head *head)
149
{
153
{
150
	__list_del(list->prev, list->next);
154
	__list_del_entry(list);
151
	list_add(list, head);
155
	list_add(list, head);
Line 152... Line 156...
152
}
156
}
153
 
157
 
Line 157... Line 161...
157
 * @head: the head that will follow our entry
161
 * @head: the head that will follow our entry
158
 */
162
 */
159
static inline void list_move_tail(struct list_head *list,
163
static inline void list_move_tail(struct list_head *list,
160
				  struct list_head *head)
164
				  struct list_head *head)
161
{
165
{
162
	__list_del(list->prev, list->next);
166
	__list_del_entry(list);
163
	list_add_tail(list, head);
167
	list_add_tail(list, head);
164
}
168
}
Line 165... Line 169...
165
 
169
 
166
/**
170
/**
Line 360... Line 364...
360
 * list_for_each	-	iterate over a list
364
 * list_for_each	-	iterate over a list
361
 * @pos:	the &struct list_head to use as a loop cursor.
365
 * @pos:	the &struct list_head to use as a loop cursor.
362
 * @head:	the head for your list.
366
 * @head:	the head for your list.
363
 */
367
 */
364
#define list_for_each(pos, head) \
368
#define list_for_each(pos, head) \
365
	for (pos = (head)->next; prefetch(pos->next), pos != (head); \
369
	for (pos = (head)->next; pos != (head); pos = pos->next)
366
        	pos = pos->next)
-
 
Line 367... Line 370...
367
 
370
 
368
/**
371
/**
369
 * __list_for_each	-	iterate over a list
372
 * __list_for_each	-	iterate over a list
370
 * @pos:	the &struct list_head to use as a loop cursor.
373
 * @pos:	the &struct list_head to use as a loop cursor.
371
 * @head:	the head for your list.
374
 * @head:	the head for your list.
372
 *
375
 *
373
 * This variant differs from list_for_each() in that it's the
-
 
374
 * simplest possible list iteration code, no prefetching is done.
-
 
375
 * Use this for code that knows the list to be very short (empty
376
 * This variant doesn't differ from list_for_each() any more.
376
 * or 1 entry) most of the time.
377
 * We don't do prefetching in either case.
377
 */
378
 */
378
#define __list_for_each(pos, head) \
379
#define __list_for_each(pos, head) \
Line 379... Line 380...
379
	for (pos = (head)->next; pos != (head); pos = pos->next)
380
	for (pos = (head)->next; pos != (head); pos = pos->next)
380
 
381
 
381
/**
382
/**
382
 * list_for_each_prev	-	iterate over a list backwards
383
 * list_for_each_prev	-	iterate over a list backwards
383
 * @pos:	the &struct list_head to use as a loop cursor.
384
 * @pos:	the &struct list_head to use as a loop cursor.
384
 * @head:	the head for your list.
385
 * @head:	the head for your list.
385
 */
386
 */
386
#define list_for_each_prev(pos, head) \
-
 
Line 387... Line 387...
387
	for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
387
#define list_for_each_prev(pos, head) \
388
        	pos = pos->prev)
388
	for (pos = (head)->prev; pos != (head); pos = pos->prev)
389
 
389
 
390
/**
390
/**
Line 403... Line 403...
403
 * @n:		another &struct list_head to use as temporary storage
403
 * @n:		another &struct list_head to use as temporary storage
404
 * @head:	the head for your list.
404
 * @head:	the head for your list.
405
 */
405
 */
406
#define list_for_each_prev_safe(pos, n, head) \
406
#define list_for_each_prev_safe(pos, n, head) \
407
	for (pos = (head)->prev, n = pos->prev; \
407
	for (pos = (head)->prev, n = pos->prev; \
408
	     prefetch(pos->prev), pos != (head); \
408
	     pos != (head); \
409
	     pos = n, n = pos->prev)
409
	     pos = n, n = pos->prev)
Line 410... Line 410...
410
 
410
 
411
/**
411
/**
412
 * list_for_each_entry	-	iterate over list of given type
412
 * list_for_each_entry	-	iterate over list of given type
413
 * @pos:	the type * to use as a loop cursor.
413
 * @pos:	the type * to use as a loop cursor.
414
 * @head:	the head for your list.
414
 * @head:	the head for your list.
415
 * @member:	the name of the list_struct within the struct.
415
 * @member:	the name of the list_struct within the struct.
416
 */
416
 */
417
#define list_for_each_entry(pos, head, member)				\
417
#define list_for_each_entry(pos, head, member)				\
418
	for (pos = list_entry((head)->next, typeof(*pos), member);	\
418
	for (pos = list_entry((head)->next, typeof(*pos), member);	\
419
	     prefetch(pos->member.next), &pos->member != (head); 	\
419
	     &pos->member != (head); 	\
Line 420... Line 420...
420
	     pos = list_entry(pos->member.next, typeof(*pos), member))
420
	     pos = list_entry(pos->member.next, typeof(*pos), member))
421
 
421
 
422
/**
422
/**
423
 * list_for_each_entry_reverse - iterate backwards over list of given type.
423
 * list_for_each_entry_reverse - iterate backwards over list of given type.
424
 * @pos:	the type * to use as a loop cursor.
424
 * @pos:	the type * to use as a loop cursor.
425
 * @head:	the head for your list.
425
 * @head:	the head for your list.
426
 * @member:	the name of the list_struct within the struct.
426
 * @member:	the name of the list_struct within the struct.
427
 */
427
 */
428
#define list_for_each_entry_reverse(pos, head, member)			\
428
#define list_for_each_entry_reverse(pos, head, member)			\
429
	for (pos = list_entry((head)->prev, typeof(*pos), member);	\
429
	for (pos = list_entry((head)->prev, typeof(*pos), member);	\
Line 430... Line 430...
430
	     prefetch(pos->member.prev), &pos->member != (head); 	\
430
	     &pos->member != (head); 	\
431
	     pos = list_entry(pos->member.prev, typeof(*pos), member))
431
	     pos = list_entry(pos->member.prev, typeof(*pos), member))
432
 
432
 
Line 450... Line 450...
450
 * Continue to iterate over list of given type, continuing after
450
 * Continue to iterate over list of given type, continuing after
451
 * the current position.
451
 * the current position.
452
 */
452
 */
453
#define list_for_each_entry_continue(pos, head, member) 		\
453
#define list_for_each_entry_continue(pos, head, member) 		\
454
	for (pos = list_entry(pos->member.next, typeof(*pos), member);	\
454
	for (pos = list_entry(pos->member.next, typeof(*pos), member);	\
455
	     prefetch(pos->member.next), &pos->member != (head);	\
455
	     &pos->member != (head);	\
456
	     pos = list_entry(pos->member.next, typeof(*pos), member))
456
	     pos = list_entry(pos->member.next, typeof(*pos), member))
Line 457... Line 457...
457
 
457
 
458
/**
458
/**
459
 * list_for_each_entry_continue_reverse - iterate backwards from the given point
459
 * list_for_each_entry_continue_reverse - iterate backwards from the given point
Line 464... Line 464...
464
 * Start to iterate over list of given type backwards, continuing after
464
 * Start to iterate over list of given type backwards, continuing after
465
 * the current position.
465
 * the current position.
466
 */
466
 */
467
#define list_for_each_entry_continue_reverse(pos, head, member)		\
467
#define list_for_each_entry_continue_reverse(pos, head, member)		\
468
	for (pos = list_entry(pos->member.prev, typeof(*pos), member);	\
468
	for (pos = list_entry(pos->member.prev, typeof(*pos), member);	\
469
	     prefetch(pos->member.prev), &pos->member != (head);	\
469
	     &pos->member != (head);	\
470
	     pos = list_entry(pos->member.prev, typeof(*pos), member))
470
	     pos = list_entry(pos->member.prev, typeof(*pos), member))
Line 471... Line 471...
471
 
471
 
472
/**
472
/**
473
 * list_for_each_entry_from - iterate over list of given type from the current point
473
 * list_for_each_entry_from - iterate over list of given type from the current point
Line 476... Line 476...
476
 * @member:	the name of the list_struct within the struct.
476
 * @member:	the name of the list_struct within the struct.
477
 *
477
 *
478
 * Iterate over list of given type, continuing from current position.
478
 * Iterate over list of given type, continuing from current position.
479
 */
479
 */
480
#define list_for_each_entry_from(pos, head, member) 			\
480
#define list_for_each_entry_from(pos, head, member) 			\
481
	for (; prefetch(pos->member.next), &pos->member != (head);	\
481
	for (; &pos->member != (head);	\
482
	     pos = list_entry(pos->member.next, typeof(*pos), member))
482
	     pos = list_entry(pos->member.next, typeof(*pos), member))
Line 483... Line 483...
483
 
483
 
484
/**
484
/**
485
 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
485
 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
Line 657... Line 657...
657
}
657
}
Line 658... Line 658...
658
 
658
 
Line 659... Line 659...
659
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
659
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
660
 
660
 
661
#define hlist_for_each(pos, head) \
-
 
Line 662... Line 661...
662
	for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
661
#define hlist_for_each(pos, head) \
663
	     pos = pos->next)
662
	for (pos = (head)->first; pos ; pos = pos->next)
664
 
663
 
Line 673... Line 672...
673
 * @head:	the head for your list.
672
 * @head:	the head for your list.
674
 * @member:	the name of the hlist_node within the struct.
673
 * @member:	the name of the hlist_node within the struct.
675
 */
674
 */
676
#define hlist_for_each_entry(tpos, pos, head, member)			 \
675
#define hlist_for_each_entry(tpos, pos, head, member)			 \
677
	for (pos = (head)->first;					 \
676
	for (pos = (head)->first;					 \
678
	     pos && ({ prefetch(pos->next); 1;}) &&			 \
677
	     pos &&							 \
679
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
678
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
680
	     pos = pos->next)
679
	     pos = pos->next)
Line 681... Line 680...
681
 
680
 
682
/**
681
/**
Line 685... Line 684...
685
 * @pos:	the &struct hlist_node to use as a loop cursor.
684
 * @pos:	the &struct hlist_node to use as a loop cursor.
686
 * @member:	the name of the hlist_node within the struct.
685
 * @member:	the name of the hlist_node within the struct.
687
 */
686
 */
688
#define hlist_for_each_entry_continue(tpos, pos, member)		 \
687
#define hlist_for_each_entry_continue(tpos, pos, member)		 \
689
	for (pos = (pos)->next;						 \
688
	for (pos = (pos)->next;						 \
690
	     pos && ({ prefetch(pos->next); 1;}) &&			 \
689
	     pos &&							 \
691
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
690
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
692
	     pos = pos->next)
691
	     pos = pos->next)
Line 693... Line 692...
693
 
692
 
694
/**
693
/**
695
 * hlist_for_each_entry_from - iterate over a hlist continuing from current point
694
 * hlist_for_each_entry_from - iterate over a hlist continuing from current point
696
 * @tpos:	the type * to use as a loop cursor.
695
 * @tpos:	the type * to use as a loop cursor.
697
 * @pos:	the &struct hlist_node to use as a loop cursor.
696
 * @pos:	the &struct hlist_node to use as a loop cursor.
698
 * @member:	the name of the hlist_node within the struct.
697
 * @member:	the name of the hlist_node within the struct.
699
 */
698
 */
700
#define hlist_for_each_entry_from(tpos, pos, member)			 \
699
#define hlist_for_each_entry_from(tpos, pos, member)			 \
701
	for (; pos && ({ prefetch(pos->next); 1;}) &&			 \
700
	for (; pos &&							 \
702
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
701
		({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
Line 703... Line 702...
703
	     pos = pos->next)
702
	     pos = pos->next)
704
 
703