package version up to 1.7.7
[platform/core/uifw/libtdm.git] / ut / stubs / tdm_list_stubs.h
1 /**
2  * \file
3  * List macros heavily inspired by the Linux kernel
4  * list handling. No list looping yet.
5  *
6  * Is not threadsafe, so common operations need to
7  * be protected using an external mutex.
8  */
9 #ifndef _U_DOUBLE_LIST_H_
10 #define _U_DOUBLE_LIST_H_
11
12 #include <stddef.h>
13
14 struct list_head {
15         struct list_head *prev;
16         struct list_head *next;
17 };
18
19 static inline void list_inithead(struct list_head *item) { }
20
21 static inline void list_add(struct list_head *item, struct list_head *list) { }
22
23 static inline void list_addtail(struct list_head *item, struct list_head *list) { }
24
25 static inline void list_replace(struct list_head *from, struct list_head *to) { }
26
27 static inline void list_del(struct list_head *item) { }
28
29 static inline void list_delinit(struct list_head *item) { }
30
31 #define LIST_INITHEAD(__item) list_inithead(__item)
32 #define LIST_ADD(__item, __list) list_add(__item, __list)
33 #define LIST_ADDTAIL(__item, __list) list_addtail(__item, __list)
34 #define LIST_REPLACE(__from, __to) list_replace(__from, __to)
35 #define LIST_DEL(__item) list_del(__item)
36 #define LIST_DELINIT(__item) list_delinit(__item)
37
38 #define LIST_ENTRY(__type, __item, __field)   \
39         ((__type *)(((char *)(__item)) - offsetof(__type, __field)))
40
41 #define LIST_IS_EMPTY(__list)                   \
42         ((__list)->next == (__list))
43
44 #ifndef container_of
45 #define container_of(ptr, sample, member)                               \
46         (void *)((char *)(ptr)                                          \
47                  - ((char *)&(sample)->member - (char *)(sample)))
48 #endif
49
50 #define LIST_FOR_EACH_ENTRY(pos, head, member)                          \
51    for (;                       \
52         1 < 0;                                          \
53         )
54
55 #define LIST_FOR_EACH_ENTRY_SAFE(pos, storage, head, member)    \
56    for (;       \
57         1 < 0;                                          \
58         )
59
60 #define LIST_FOR_EACH_ENTRY_SAFE_REV(pos, storage, head, member)        \
61    for (pos = container_of((head)->prev, pos, member),                  \
62         storage = container_of(pos->member.prev, pos, member);          \
63         &pos->member != (head);                                         \
64         pos = storage, storage = container_of(storage->member.prev, storage, member))
65
66 #define LIST_FOR_EACH_ENTRY_FROM(pos, start, head, member)              \
67    for (pos = container_of((start), pos, member);                       \
68         &pos->member != (head);                                         \
69         pos = container_of(pos->member.next, pos, member))
70
71 #define LIST_FOR_EACH_ENTRY_FROM_REV(pos, start, head, member)          \
72    for (pos = container_of((start), pos, member);                       \
73         &pos->member != (head);                                         \
74         pos = container_of(pos->member.prev, pos, member))
75
76 #define LIST_LENGTH(__item) 1
77
78 #endif /*_U_DOUBLE_LIST_H_*/