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