Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

list.h 13KB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /*****************************************************************************
  2. *
  3. * Linux kernel header adapted for user-mode
  4. * The 2.6.17-rt1 version was used.
  5. *
  6. * Original copyright holders of this code are unknown, they were not
  7. * mentioned in the original file.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; version 2 of the License
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. *****************************************************************************/
  23. #ifndef __LINUX_LIST_H__
  24. #define __LINUX_LIST_H__
  25. /* This file is from Linux Kernel (include/linux/list.h)
  26. * and modified by simply removing hardware prefetching of list items.
  27. * Here by copyright, credits attributed to wherever they belong.
  28. * Filipe Coelho (aka falkTX <falktx@falktx.com>)
  29. */
  30. #include <stddef.h>
  31. #if !defined(offsetof)
  32. # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  33. #endif
  34. /**
  35. * container_of - cast a member of a structure out to the containing structure
  36. * @ptr: the pointer to the member.
  37. * @type: the type of the container struct this is embedded in.
  38. * @member: the name of the member within the struct.
  39. *
  40. */
  41. #define container_of(ptr, type, member) ({ \
  42. const typeof( ((type *)0)->member ) *__mptr = (ptr); \
  43. (type *)( (char *)__mptr - offsetof(type,member) );})
  44. #define prefetch(x) (x = x)
  45. /*
  46. * These are non-NULL pointers that will result in page faults
  47. * under normal circumstances, used to verify that nobody uses
  48. * non-initialized list entries.
  49. */
  50. #define LIST_POISON1 ((void *) 0x00100100)
  51. #define LIST_POISON2 ((void *) 0x00200200)
  52. /*
  53. * Simple doubly linked list implementation.
  54. *
  55. * Some of the internal functions ("__xxx") are useful when
  56. * manipulating whole lists rather than single entries, as
  57. * sometimes we already know the next/prev entries and we can
  58. * generate better code by using them directly rather than
  59. * using the generic single-entry routines.
  60. */
  61. struct list_head {
  62. struct list_head *next, *prev;
  63. };
  64. #define LIST_HEAD_INIT(name) { &(name), &(name) }
  65. #define LIST_HEAD(name) \
  66. struct list_head name = LIST_HEAD_INIT(name)
  67. static inline void INIT_LIST_HEAD(struct list_head *list)
  68. {
  69. list->next = list;
  70. list->prev = list;
  71. }
  72. /*
  73. * Insert a new entry between two known consecutive entries.
  74. *
  75. * This is only for internal list manipulation where we know
  76. * the prev/next entries already!
  77. */
  78. static inline void __list_add(struct list_head *new_, struct list_head *prev, struct list_head *next)
  79. {
  80. next->prev = new_;
  81. new_->next = next;
  82. new_->prev = prev;
  83. prev->next = new_;
  84. }
  85. /**
  86. * list_add - add a new entry
  87. * @new: new entry to be added
  88. * @head: list head to add it after
  89. *
  90. * Insert a new entry after the specified head.
  91. * This is good for implementing stacks.
  92. */
  93. static inline void list_add(struct list_head *new_, struct list_head *head)
  94. {
  95. __list_add(new_, head, head->next);
  96. }
  97. /**
  98. * list_add_tail - add a new entry
  99. * @new: new entry to be added
  100. * @head: list head to add it before
  101. *
  102. * Insert a new entry before the specified head.
  103. * This is useful for implementing queues.
  104. */
  105. static inline void list_add_tail(struct list_head *new_, struct list_head *head)
  106. {
  107. __list_add(new_, head->prev, head);
  108. }
  109. /*
  110. * Delete a list entry by making the prev/next entries
  111. * point to each other.
  112. *
  113. * This is only for internal list manipulation where we know
  114. * the prev/next entries already!
  115. */
  116. static inline void __list_del(struct list_head *prev, struct list_head *next)
  117. {
  118. next->prev = prev;
  119. prev->next = next;
  120. }
  121. /**
  122. * list_del - deletes entry from list.
  123. * @entry: the element to delete from the list.
  124. * Note: list_empty on entry does not return true after this, the entry is
  125. * in an undefined state.
  126. */
  127. static inline void list_del(struct list_head *entry)
  128. {
  129. __list_del(entry->prev, entry->next);
  130. entry->next = (struct list_head*)LIST_POISON1;
  131. entry->prev = (struct list_head*)LIST_POISON2;
  132. }
  133. /**
  134. * list_del_init - deletes entry from list and reinitialize it.
  135. * @entry: the element to delete from the list.
  136. */
  137. static inline void list_del_init(struct list_head *entry)
  138. {
  139. __list_del(entry->prev, entry->next);
  140. INIT_LIST_HEAD(entry);
  141. }
  142. /**
  143. * list_move - delete from one list and add as another's head
  144. * @list: the entry to move
  145. * @head: the head that will precede our entry
  146. */
  147. static inline void list_move(struct list_head *list, struct list_head *head)
  148. {
  149. __list_del(list->prev, list->next);
  150. list_add(list, head);
  151. }
  152. /**
  153. * list_move_tail - delete from one list and add as another's tail
  154. * @list: the entry to move
  155. * @head: the head that will follow our entry
  156. */
  157. static inline void list_move_tail(struct list_head *list, struct list_head *head)
  158. {
  159. __list_del(list->prev, list->next);
  160. list_add_tail(list, head);
  161. }
  162. /**
  163. * list_empty - tests whether a list is empty
  164. * @head: the list to test.
  165. */
  166. static inline int list_empty(const struct list_head *head)
  167. {
  168. return head->next == head;
  169. }
  170. /**
  171. * list_empty_careful - tests whether a list is
  172. * empty _and_ checks that no other CPU might be
  173. * in the process of still modifying either member
  174. *
  175. * NOTE: using list_empty_careful() without synchronization
  176. * can only be safe if the only activity that can happen
  177. * to the list entry is list_del_init(). Eg. it cannot be used
  178. * if another CPU could re-list_add() it.
  179. *
  180. * @head: the list to test.
  181. */
  182. static inline int list_empty_careful(const struct list_head *head)
  183. {
  184. struct list_head *next = head->next;
  185. return (next == head) && (next == head->prev);
  186. }
  187. static inline void __list_splice(struct list_head *list, struct list_head *head)
  188. {
  189. struct list_head *first = list->next;
  190. struct list_head *last = list->prev;
  191. struct list_head *at = head->next;
  192. first->prev = head;
  193. head->next = first;
  194. last->next = at;
  195. at->prev = last;
  196. }
  197. /**
  198. * list_splice - join two lists
  199. * @list: the new list to add.
  200. * @head: the place to add it in the first list.
  201. */
  202. static inline void list_splice(struct list_head *list, struct list_head *head)
  203. {
  204. if (!list_empty(list))
  205. __list_splice(list, head);
  206. }
  207. /**
  208. * list_splice_init - join two lists and reinitialise the emptied list.
  209. * @list: the new list to add.
  210. * @head: the place to add it in the first list.
  211. *
  212. * The list at @list is reinitialised
  213. */
  214. static inline void list_splice_init(struct list_head *list, struct list_head *head)
  215. {
  216. if (!list_empty(list)) {
  217. __list_splice(list, head);
  218. INIT_LIST_HEAD(list);
  219. }
  220. }
  221. /**
  222. * list_entry - get the struct for this entry
  223. * @ptr: the &struct list_head pointer.
  224. * @type: the type of the struct this is embedded in.
  225. * @member: the name of the list_struct within the struct.
  226. */
  227. #define list_entry(ptr, type, member) \
  228. ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
  229. //container_of(ptr, type, member)
  230. /**
  231. * list_for_each - iterate over a list
  232. * @pos: the &struct list_head to use as a loop counter.
  233. * @head: the head for your list.
  234. */
  235. #define list_for_each(pos, head) \
  236. for (pos = (head)->next; prefetch(pos->next), pos != (head); \
  237. pos = pos->next)
  238. /**
  239. * __list_for_each - iterate over a list
  240. * @pos: the &struct list_head to use as a loop counter.
  241. * @head: the head for your list.
  242. *
  243. * This variant differs from list_for_each() in that it's the
  244. * simplest possible list iteration code, no prefetching is done.
  245. * Use this for code that knows the list to be very short (empty
  246. * or 1 entry) most of the time.
  247. */
  248. #define __list_for_each(pos, head) \
  249. for (pos = (head)->next; pos != (head); pos = pos->next)
  250. /**
  251. * list_for_each_prev - iterate over a list backwards
  252. * @pos: the &struct list_head to use as a loop counter.
  253. * @head: the head for your list.
  254. */
  255. #define list_for_each_prev(pos, head) \
  256. for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
  257. pos = pos->prev)
  258. /**
  259. * list_for_each_safe - iterate over a list safe against removal of list entry
  260. * @pos: the &struct list_head to use as a loop counter.
  261. * @n: another &struct list_head to use as temporary storage
  262. * @head: the head for your list.
  263. */
  264. #define list_for_each_safe(pos, n, head) \
  265. for (pos = (head)->next, n = pos->next; pos != (head); \
  266. pos = n, n = pos->next)
  267. /**
  268. * list_for_each_entry - iterate over list of given type
  269. * @pos: the type * to use as a loop counter.
  270. * @head: the head for your list.
  271. * @member: the name of the list_struct within the struct.
  272. */
  273. #define list_for_each_entry(pos, head, member) \
  274. for (pos = list_entry((head)->next, typeof(*pos), member); \
  275. prefetch(pos->member.next), &pos->member != (head); \
  276. pos = list_entry(pos->member.next, typeof(*pos), member))
  277. /**
  278. * list_for_each_entry_reverse - iterate backwards over list of given type.
  279. * @pos: the type * to use as a loop counter.
  280. * @head: the head for your list.
  281. * @member: the name of the list_struct within the struct.
  282. */
  283. #define list_for_each_entry_reverse(pos, head, member) \
  284. for (pos = list_entry((head)->prev, typeof(*pos), member); \
  285. prefetch(pos->member.prev), &pos->member != (head); \
  286. pos = list_entry(pos->member.prev, typeof(*pos), member))
  287. /**
  288. * list_prepare_entry - prepare a pos entry for use as a start point in list_for_each_entry_continue
  289. * @pos: the type * to use as a start point
  290. * @head: the head of the list
  291. * @member: the name of the list_struct within the struct.
  292. */
  293. #define list_prepare_entry(pos, head, member) \
  294. ((pos) ? : list_entry(head, typeof(*pos), member))
  295. /**
  296. * list_for_each_entry_continue - iterate over list of given type continuing after existing point
  297. * @pos: the type * to use as a loop counter.
  298. * @head: the head for your list.
  299. * @member: the name of the list_struct within the struct.
  300. */
  301. #define list_for_each_entry_continue(pos, head, member) \
  302. for (pos = list_entry(pos->member.next, typeof(*pos), member); \
  303. prefetch(pos->member.next), &pos->member != (head); \
  304. pos = list_entry(pos->member.next, typeof(*pos), member))
  305. /**
  306. * list_for_each_entry_from - iterate over list of given type continuing from existing point
  307. * @pos: the type * to use as a loop counter.
  308. * @head: the head for your list.
  309. * @member: the name of the list_struct within the struct.
  310. */
  311. #define list_for_each_entry_from(pos, head, member) \
  312. for (; prefetch(pos->member.next), &pos->member != (head); \
  313. pos = list_entry(pos->member.next, typeof(*pos), member))
  314. /**
  315. * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  316. * @pos: the type * to use as a loop counter.
  317. * @n: another type * to use as temporary storage
  318. * @head: the head for your list.
  319. * @member: the name of the list_struct within the struct.
  320. */
  321. #define list_for_each_entry_safe(pos, n, head, member) \
  322. for (pos = list_entry((head)->next, typeof(*pos), member), \
  323. n = list_entry(pos->member.next, typeof(*pos), member); \
  324. &pos->member != (head); \
  325. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  326. /**
  327. * list_for_each_entry_safe_continue - iterate over list of given type continuing after existing point safe against removal of list entry
  328. * @pos: the type * to use as a loop counter.
  329. * @n: another type * to use as temporary storage
  330. * @head: the head for your list.
  331. * @member: the name of the list_struct within the struct.
  332. */
  333. #define list_for_each_entry_safe_continue(pos, n, head, member) \
  334. for (pos = list_entry(pos->member.next, typeof(*pos), member), \
  335. n = list_entry(pos->member.next, typeof(*pos), member); \
  336. &pos->member != (head); \
  337. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  338. /**
  339. * list_for_each_entry_safe_from - iterate over list of given type from existing point safe against removal of list entry
  340. * @pos: the type * to use as a loop counter.
  341. * @n: another type * to use as temporary storage
  342. * @head: the head for your list.
  343. * @member: the name of the list_struct within the struct.
  344. */
  345. #define list_for_each_entry_safe_from(pos, n, head, member) \
  346. for (n = list_entry(pos->member.next, typeof(*pos), member); \
  347. &pos->member != (head); \
  348. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  349. /**
  350. * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against removal of list entry
  351. * @pos: the type * to use as a loop counter.
  352. * @n: another type * to use as temporary storage
  353. * @head: the head for your list.
  354. * @member: the name of the list_struct within the struct.
  355. */
  356. #define list_for_each_entry_safe_reverse(pos, n, head, member) \
  357. for (pos = list_entry((head)->prev, typeof(*pos), member), \
  358. n = list_entry(pos->member.prev, typeof(*pos), member); \
  359. &pos->member != (head); \
  360. pos = n, n = list_entry(n->member.prev, typeof(*n), member))
  361. #endif // __LINUX_LIST_H__