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 15KB

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