2001-10-31 15:47:01 +03:00
/*
* Copyright ( C ) 2001 Sistina Software
*
* This file is released under the LGPL .
*/
2001-09-28 17:19:17 +04:00
2001-10-01 19:14:39 +04:00
# ifndef _LVM_LIST_H
# define _LVM_LIST_H
2001-09-28 17:19:17 +04:00
2001-10-31 15:47:01 +03:00
# include <assert.h>
2001-09-28 17:19:17 +04:00
2001-10-31 15:47:01 +03:00
struct list {
struct list * n , * p ;
2001-09-28 17:19:17 +04:00
} ;
2001-10-31 15:47:01 +03:00
static inline void list_init ( struct list * head ) {
head - > n = head - > p = head ;
}
2001-09-28 17:19:17 +04:00
2001-10-31 15:47:01 +03:00
static inline void list_add ( struct list * head , struct list * elem ) {
assert ( head - > n ) ;
2001-09-28 17:19:17 +04:00
2001-10-31 15:47:01 +03:00
elem - > n = head ;
elem - > p = head - > p ;
2001-09-28 17:19:17 +04:00
2001-10-31 15:47:01 +03:00
head - > p - > n = elem ;
head - > p = elem ;
2001-09-28 17:19:17 +04:00
}
2001-10-31 15:47:01 +03:00
static inline void list_add_h ( struct list * head , struct list * elem ) {
assert ( head - > n ) ;
2001-09-28 17:19:17 +04:00
2001-10-31 15:47:01 +03:00
elem - > n = head - > n ;
elem - > p = head ;
2001-09-28 17:19:17 +04:00
2001-10-31 15:47:01 +03:00
head - > n - > p = elem ;
head - > n = elem ;
2001-09-28 17:19:17 +04:00
}
2001-10-31 15:47:01 +03:00
static inline void list_del ( struct list * elem ) {
elem - > n - > p = elem - > p ;
elem - > p - > n = elem - > n ;
2001-09-28 17:19:17 +04:00
}
2001-10-31 15:47:01 +03:00
static inline int list_empty ( struct list * head ) {
return head - > n = = head ;
2001-09-28 17:19:17 +04:00
}
2001-10-31 15:47:01 +03:00
# define list_iterate(v, head) \
for ( v = ( head ) - > n ; v ! = head ; v = v - > n )
2001-09-28 17:19:17 +04:00
2001-10-31 15:47:01 +03:00
# define list_item(v, t) \
( ( t * ) ( ( char * ) ( v ) - ( unsigned int ) & ( ( t * ) 0 ) - > list ) )
2001-09-28 17:19:17 +04:00
2001-11-14 21:38:07 +03:00
/* Given a known element in a known structure, locate the struct list */
# define list_head(v, t, e) \
( ( ( t * ) ( ( char * ) ( v ) - ( unsigned int ) & ( ( t * ) 0 ) - > e ) ) - > list )
2001-09-28 17:19:17 +04:00
# endif