Subversion Repositories Kolibri OS

Rev

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

Rev 1408 Rev 1964
Line 1... Line 1...
1
#ifndef _LINUX_LIST_H
1
#ifndef _LINUX_LIST_H
2
#define _LINUX_LIST_H
2
#define _LINUX_LIST_H
Line -... Line 3...
-
 
3
 
3
 
4
#include 
4
#include 
5
#include 
-
 
6
#include 
5
//#include 
7
 
6
//#include 
-
 
Line 7... Line 8...
7
//#include 
8
#define prefetch(x) __builtin_prefetch(x)
8
 
9
 
9
/*
10
/*
10
 * Simple doubly linked list implementation.
11
 * Simple doubly linked list implementation.
Line 14... Line 15...
14
 * sometimes we already know the next/prev entries and we can
15
 * sometimes we already know the next/prev entries and we can
15
 * generate better code by using them directly rather than
16
 * generate better code by using them directly rather than
16
 * using the generic single-entry routines.
17
 * using the generic single-entry routines.
17
 */
18
 */
Line 18... Line -...
18
 
-
 
19
#define LIST_POISON1   ((struct list_head*)0xFFFF0100)
-
 
20
#define LIST_POISON2   ((struct list_head*)0xFFFF0200)
-
 
21
 
-
 
22
#define prefetch(x) __builtin_prefetch(x)
-
 
23
 
-
 
24
struct list_head {
-
 
25
	struct list_head *next, *prev;
-
 
26
};
-
 
27
 
19
 
Line 28... Line 20...
28
#define LIST_HEAD_INIT(name) { &(name), &(name) }
20
#define LIST_HEAD_INIT(name) { &(name), &(name) }
29
 
21
 
Line 209... Line 201...
209
	struct list_head *next = head->next;
201
	struct list_head *next = head->next;
210
	return (next == head) && (next == head->prev);
202
	return (next == head) && (next == head->prev);
211
}
203
}
Line 212... Line 204...
212
 
204
 
-
 
205
/**
-
 
206
 * list_rotate_left - rotate the list to the left
-
 
207
 * @head: the head of the list
-
 
208
 */
-
 
209
static inline void list_rotate_left(struct list_head *head)
-
 
210
{
-
 
211
	struct list_head *first;
-
 
212
 
-
 
213
	if (!list_empty(head)) {
-
 
214
		first = head->next;
-
 
215
		list_move_tail(first, head);
-
 
216
	}
-
 
217
}
-
 
218
 
213
/**
219
/**
214
 * list_is_singular - tests whether a list has just one entry.
220
 * list_is_singular - tests whether a list has just one entry.
215
 * @head: the list to test.
221
 * @head: the list to test.
216
 */
222
 */
217
static inline int list_is_singular(const struct list_head *head)
223
static inline int list_is_singular(const struct list_head *head)
Line 487... Line 493...
487
		n = list_entry(pos->member.next, typeof(*pos), member);	\
493
		n = list_entry(pos->member.next, typeof(*pos), member);	\
488
	     &pos->member != (head); 					\
494
	     &pos->member != (head); 					\
489
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
495
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
Line 490... Line 496...
490
 
496
 
491
/**
497
/**
492
 * list_for_each_entry_safe_continue
498
 * list_for_each_entry_safe_continue - continue list iteration safe against removal
493
 * @pos:	the type * to use as a loop cursor.
499
 * @pos:	the type * to use as a loop cursor.
494
 * @n:		another type * to use as temporary storage
500
 * @n:		another type * to use as temporary storage
495
 * @head:	the head for your list.
501
 * @head:	the head for your list.
496
 * @member:	the name of the list_struct within the struct.
502
 * @member:	the name of the list_struct within the struct.
Line 503... Line 509...
503
		n = list_entry(pos->member.next, typeof(*pos), member);		\
509
		n = list_entry(pos->member.next, typeof(*pos), member);		\
504
	     &pos->member != (head);						\
510
	     &pos->member != (head);						\
505
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
511
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
Line 506... Line 512...
506
 
512
 
507
/**
513
/**
508
 * list_for_each_entry_safe_from
514
 * list_for_each_entry_safe_from - iterate over list from current point safe against removal
509
 * @pos:	the type * to use as a loop cursor.
515
 * @pos:	the type * to use as a loop cursor.
510
 * @n:		another type * to use as temporary storage
516
 * @n:		another type * to use as temporary storage
511
 * @head:	the head for your list.
517
 * @head:	the head for your list.
512
 * @member:	the name of the list_struct within the struct.
518
 * @member:	the name of the list_struct within the struct.
Line 518... Line 524...
518
	for (n = list_entry(pos->member.next, typeof(*pos), member);		\
524
	for (n = list_entry(pos->member.next, typeof(*pos), member);		\
519
	     &pos->member != (head);						\
525
	     &pos->member != (head);						\
520
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
526
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
Line 521... Line 527...
521
 
527
 
522
/**
528
/**
523
 * list_for_each_entry_safe_reverse
529
 * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
524
 * @pos:	the type * to use as a loop cursor.
530
 * @pos:	the type * to use as a loop cursor.
525
 * @n:		another type * to use as temporary storage
531
 * @n:		another type * to use as temporary storage
526
 * @head:	the head for your list.
532
 * @head:	the head for your list.
527
 * @member:	the name of the list_struct within the struct.
533
 * @member:	the name of the list_struct within the struct.
Line 533... Line 539...
533
	for (pos = list_entry((head)->prev, typeof(*pos), member),	\
539
	for (pos = list_entry((head)->prev, typeof(*pos), member),	\
534
		n = list_entry(pos->member.prev, typeof(*pos), member);	\
540
		n = list_entry(pos->member.prev, typeof(*pos), member);	\
535
	     &pos->member != (head); 					\
541
	     &pos->member != (head); 					\
536
	     pos = n, n = list_entry(n->member.prev, typeof(*n), member))
542
	     pos = n, n = list_entry(n->member.prev, typeof(*n), member))
Line -... Line 543...
-
 
543
 
-
 
544
/**
-
 
545
 * list_safe_reset_next - reset a stale list_for_each_entry_safe loop
-
 
546
 * @pos:	the loop cursor used in the list_for_each_entry_safe loop
-
 
547
 * @n:		temporary storage used in list_for_each_entry_safe
-
 
548
 * @member:	the name of the list_struct within the struct.
-
 
549
 *
-
 
550
 * list_safe_reset_next is not safe to use in general if the list may be
-
 
551
 * modified concurrently (eg. the lock is dropped in the loop body). An
-
 
552
 * exception to this is if the cursor element (pos) is pinned in the list,
-
 
553
 * and list_safe_reset_next is called after re-taking the lock and before
-
 
554
 * completing the current iteration of the loop body.
-
 
555
 */
-
 
556
#define list_safe_reset_next(pos, n, member)				\
-
 
557
	n = list_entry(pos->member.next, typeof(*pos), member)
537
 
558
 
538
/*
559
/*
539
 * Double linked lists with a single pointer list head.
560
 * Double linked lists with a single pointer list head.
540
 * Mostly useful for hash tables where the two pointer list head is
561
 * Mostly useful for hash tables where the two pointer list head is
541
 * too wasteful.
562
 * too wasteful.
542
 * You lose the ability to access the tail in O(1).
563
 * You lose the ability to access the tail in O(1).
Line 543... Line -...
543
 */
-
 
544
 
-
 
545
struct hlist_head {
-
 
546
	struct hlist_node *first;
-
 
547
};
-
 
548
 
-
 
549
struct hlist_node {
-
 
550
	struct hlist_node *next, **pprev;
-
 
551
};
564
 */
552
 
565
 
553
#define HLIST_HEAD_INIT { .first = NULL }
566
#define HLIST_HEAD_INIT { .first = NULL }
554
#define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
567
#define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
555
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
568
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
Line 579... Line 592...
579
}
592
}
Line 580... Line 593...
580
 
593
 
581
static inline void hlist_del(struct hlist_node *n)
594
static inline void hlist_del(struct hlist_node *n)
582
{
595
{
583
	__hlist_del(n);
596
	__hlist_del(n);
584
    n->next = (struct hlist_node*)LIST_POISON1;
597
	n->next = LIST_POISON1;
585
    n->pprev = (struct hlist_node**)LIST_POISON2;
598
	n->pprev = LIST_POISON2;
Line 586... Line 599...
586
}
599
}
587
 
600
 
588
static inline void hlist_del_init(struct hlist_node *n)
601
static inline void hlist_del_init(struct hlist_node *n)
Line 622... Line 635...
622
 
635
 
623
	if(next->next)
636
	if(next->next)
624
		next->next->pprev  = &next->next;
637
		next->next->pprev  = &next->next;
Line -... Line 638...
-
 
638
}
-
 
639
 
-
 
640
/* after that we'll appear to be on some hlist and hlist_del will work */
-
 
641
static inline void hlist_add_fake(struct hlist_node *n)
-
 
642
{
-
 
643
	n->pprev = &n->next;
625
}
644
}
626
 
645
 
627
/*
646
/*
628
 * Move a list from one list head to another. Fixup the pprev
647
 * Move a list from one list head to another. Fixup the pprev
629
 * reference of the first entry if it exists.
648
 * reference of the first entry if it exists.