list.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. #ifndef _LINUX_LIST_H
  2. #define _LINUX_LIST_H
  3. #include <linux/types.h>
  4. #include <linux/stddef.h>
  5. #include <linux/poison.h>
  6. #include <linux/const.h>
  7. /*
  8. * Simple doubly linked list implementation.
  9. *
  10. * Some of the internal functions ("__xxx") are useful when
  11. * manipulating whole lists rather than single entries, as
  12. * sometimes we already know the next/prev entries and we can
  13. * generate better code by using them directly rather than
  14. * using the generic single-entry routines.
  15. */
  16. #define LIST_HEAD_INIT(name) { &(name), &(name) }
  17. #define LIST_HEAD(name) \
  18. struct list_head name = LIST_HEAD_INIT(name)
  19. static inline void INIT_LIST_HEAD(struct list_head *list)
  20. {
  21. list->next = list;
  22. list->prev = list;
  23. }
  24. /*
  25. * Insert a new entry between two known consecutive entries.
  26. *
  27. * This is only for internal list manipulation where we know
  28. * the prev/next entries already!
  29. */
  30. #ifndef CONFIG_DEBUG_LIST
  31. static inline void __list_add(struct list_head *new,
  32. struct list_head *prev,
  33. struct list_head *next)
  34. {
  35. next->prev = new;
  36. new->next = next;
  37. new->prev = prev;
  38. prev->next = new;
  39. }
  40. #else
  41. extern void __list_add(struct list_head *new,
  42. struct list_head *prev,
  43. struct list_head *next);
  44. #endif
  45. /**
  46. * list_add - add a new entry
  47. * @new: new entry to be added
  48. * @head: list head to add it after
  49. *
  50. * Insert a new entry after the specified head.
  51. * This is good for implementing stacks.
  52. */
  53. static inline void list_add(struct list_head *new, struct list_head *head)
  54. {
  55. __list_add(new, head, head->next);
  56. }
  57. /**
  58. * list_add_tail - add a new entry
  59. * @new: new entry to be added
  60. * @head: list head to add it before
  61. *
  62. * Insert a new entry before the specified head.
  63. * This is useful for implementing queues.
  64. */
  65. static inline void list_add_tail(struct list_head *new, struct list_head *head)
  66. {
  67. __list_add(new, head->prev, head);
  68. }
  69. /*
  70. * Delete a list entry by making the prev/next entries
  71. * point to each other.
  72. *
  73. * This is only for internal list manipulation where we know
  74. * the prev/next entries already!
  75. */
  76. static inline void __list_del(struct list_head * prev, struct list_head * next)
  77. {
  78. next->prev = prev;
  79. prev->next = next;
  80. }
  81. /**
  82. * list_del - deletes entry from list.
  83. * @entry: the element to delete from the list.
  84. * Note: list_empty() on entry does not return true after this, the entry is
  85. * in an undefined state.
  86. */
  87. #ifndef CONFIG_DEBUG_LIST
  88. static inline void __list_del_entry(struct list_head *entry)
  89. {
  90. __list_del(entry->prev, entry->next);
  91. }
  92. static inline void list_del(struct list_head *entry)
  93. {
  94. __list_del(entry->prev, entry->next);
  95. entry->next = LIST_POISON1;
  96. entry->prev = LIST_POISON2;
  97. }
  98. #else
  99. extern void __list_del_entry(struct list_head *entry);
  100. extern void list_del(struct list_head *entry);
  101. #endif
  102. /**
  103. * list_replace - replace old entry by new one
  104. * @old : the element to be replaced
  105. * @new : the new element to insert
  106. *
  107. * If @old was empty, it will be overwritten.
  108. */
  109. static inline void list_replace(struct list_head *old,
  110. struct list_head *new)
  111. {
  112. new->next = old->next;
  113. new->next->prev = new;
  114. new->prev = old->prev;
  115. new->prev->next = new;
  116. }
  117. static inline void list_replace_init(struct list_head *old,
  118. struct list_head *new)
  119. {
  120. list_replace(old, new);
  121. INIT_LIST_HEAD(old);
  122. }
  123. /**
  124. * list_del_init - deletes entry from list and reinitialize it.
  125. * @entry: the element to delete from the list.
  126. */
  127. static inline void list_del_init(struct list_head *entry)
  128. {
  129. __list_del_entry(entry);
  130. INIT_LIST_HEAD(entry);
  131. }
  132. /**
  133. * list_move - delete from one list and add as another's head
  134. * @list: the entry to move
  135. * @head: the head that will precede our entry
  136. */
  137. static inline void list_move(struct list_head *list, struct list_head *head)
  138. {
  139. __list_del_entry(list);
  140. list_add(list, head);
  141. }
  142. /**
  143. * list_move_tail - delete from one list and add as another's tail
  144. * @list: the entry to move
  145. * @head: the head that will follow our entry
  146. */
  147. static inline void list_move_tail(struct list_head *list,
  148. struct list_head *head)
  149. {
  150. __list_del_entry(list);
  151. list_add_tail(list, head);
  152. }
  153. /**
  154. * list_is_last - tests whether @list is the last entry in list @head
  155. * @list: the entry to test
  156. * @head: the head of the list
  157. */
  158. static inline int list_is_last(const struct list_head *list,
  159. const struct list_head *head)
  160. {
  161. return list->next == head;
  162. }
  163. /**
  164. * list_empty - tests whether a list is empty
  165. * @head: the list to test.
  166. */
  167. static inline int list_empty(const struct list_head *head)
  168. {
  169. return head->next == head;
  170. }
  171. /**
  172. * list_empty_careful - tests whether a list is empty and not being modified
  173. * @head: the list to test
  174. *
  175. * Description:
  176. * tests whether a list is empty _and_ checks that no other CPU might be
  177. * in the process of modifying either member (next or prev)
  178. *
  179. * NOTE: using list_empty_careful() without synchronization
  180. * can only be safe if the only activity that can happen
  181. * to the list entry is list_del_init(). Eg. it cannot be used
  182. * if another CPU could re-list_add() it.
  183. */
  184. static inline int list_empty_careful(const struct list_head *head)
  185. {
  186. struct list_head *next = head->next;
  187. return (next == head) && (next == head->prev);
  188. }
  189. /**
  190. * list_rotate_left - rotate the list to the left
  191. * @head: the head of the list
  192. */
  193. static inline void list_rotate_left(struct list_head *head)
  194. {
  195. struct list_head *first;
  196. if (!list_empty(head)) {
  197. first = head->next;
  198. list_move_tail(first, head);
  199. }
  200. }
  201. /**
  202. * list_is_singular - tests whether a list has just one entry.
  203. * @head: the list to test.
  204. */
  205. static inline int list_is_singular(const struct list_head *head)
  206. {
  207. return !list_empty(head) && (head->next == head->prev);
  208. }
  209. static inline void __list_cut_position(struct list_head *list,
  210. struct list_head *head, struct list_head *entry)
  211. {
  212. struct list_head *new_first = entry->next;
  213. list->next = head->next;
  214. list->next->prev = list;
  215. list->prev = entry;
  216. entry->next = list;
  217. head->next = new_first;
  218. new_first->prev = head;
  219. }
  220. /**
  221. * list_cut_position - cut a list into two
  222. * @list: a new list to add all removed entries
  223. * @head: a list with entries
  224. * @entry: an entry within head, could be the head itself
  225. * and if so we won't cut the list
  226. *
  227. * This helper moves the initial part of @head, up to and
  228. * including @entry, from @head to @list. You should
  229. * pass on @entry an element you know is on @head. @list
  230. * should be an empty list or a list you do not care about
  231. * losing its data.
  232. *
  233. */
  234. static inline void list_cut_position(struct list_head *list,
  235. struct list_head *head, struct list_head *entry)
  236. {
  237. if (list_empty(head))
  238. return;
  239. if (list_is_singular(head) &&
  240. (head->next != entry && head != entry))
  241. return;
  242. if (entry == head)
  243. INIT_LIST_HEAD(list);
  244. else
  245. __list_cut_position(list, head, entry);
  246. }
  247. static inline void __list_splice(const struct list_head *list,
  248. struct list_head *prev,
  249. struct list_head *next)
  250. {
  251. struct list_head *first = list->next;
  252. struct list_head *last = list->prev;
  253. first->prev = prev;
  254. prev->next = first;
  255. last->next = next;
  256. next->prev = last;
  257. }
  258. /**
  259. * list_splice - join two lists, this is designed for stacks
  260. * @list: the new list to add.
  261. * @head: the place to add it in the first list.
  262. */
  263. static inline void list_splice(const struct list_head *list,
  264. struct list_head *head)
  265. {
  266. if (!list_empty(list))
  267. __list_splice(list, head, head->next);
  268. }
  269. /**
  270. * list_splice_tail - join two lists, each list being a queue
  271. * @list: the new list to add.
  272. * @head: the place to add it in the first list.
  273. */
  274. static inline void list_splice_tail(struct list_head *list,
  275. struct list_head *head)
  276. {
  277. if (!list_empty(list))
  278. __list_splice(list, head->prev, head);
  279. }
  280. /**
  281. * list_splice_init - join two lists and reinitialise the emptied list.
  282. * @list: the new list to add.
  283. * @head: the place to add it in the first list.
  284. *
  285. * The list at @list is reinitialised
  286. */
  287. static inline void list_splice_init(struct list_head *list,
  288. struct list_head *head)
  289. {
  290. if (!list_empty(list)) {
  291. __list_splice(list, head, head->next);
  292. INIT_LIST_HEAD(list);
  293. }
  294. }
  295. /**
  296. * list_splice_tail_init - join two lists and reinitialise the emptied list
  297. * @list: the new list to add.
  298. * @head: the place to add it in the first list.
  299. *
  300. * Each of the lists is a queue.
  301. * The list at @list is reinitialised
  302. */
  303. static inline void list_splice_tail_init(struct list_head *list,
  304. struct list_head *head)
  305. {
  306. if (!list_empty(list)) {
  307. __list_splice(list, head->prev, head);
  308. INIT_LIST_HEAD(list);
  309. }
  310. }
  311. /**
  312. * list_entry - get the struct for this entry
  313. * @ptr: the &struct list_head pointer.
  314. * @type: the type of the struct this is embedded in.
  315. * @member: the name of the list_struct within the struct.
  316. */
  317. #define list_entry(ptr, type, member) \
  318. container_of(ptr, type, member)
  319. /**
  320. * list_first_entry - get the first element from a list
  321. * @ptr: the list head to take the element from.
  322. * @type: the type of the struct this is embedded in.
  323. * @member: the name of the list_struct within the struct.
  324. *
  325. * Note, that list is expected to be not empty.
  326. */
  327. #define list_first_entry(ptr, type, member) \
  328. list_entry((ptr)->next, type, member)
  329. /**
  330. * list_next_entry - get the next element in list
  331. * @pos: the type * to cursor
  332. * @member: the name of the list_struct within the struct.
  333. */
  334. #define list_next_entry(pos, member) \
  335. list_entry((pos)->member.next, typeof(*(pos)), member)
  336. /**
  337. * list_prev_entry - get the prev element in list
  338. * @pos: the type * to cursor
  339. * @member: the name of the list_struct within the struct.
  340. */
  341. #define list_prev_entry(pos, member) \
  342. list_entry((pos)->member.prev, typeof(*(pos)), member)
  343. /**
  344. * list_for_each - iterate over a list
  345. * @pos: the &struct list_head to use as a loop cursor.
  346. * @head: the head for your list.
  347. */
  348. #define list_for_each(pos, head) \
  349. for (pos = (head)->next; pos != (head); pos = pos->next)
  350. /**
  351. * __list_for_each - iterate over a list
  352. * @pos: the &struct list_head to use as a loop cursor.
  353. * @head: the head for your list.
  354. *
  355. * This variant doesn't differ from list_for_each() any more.
  356. * We don't do prefetching in either case.
  357. */
  358. #define __list_for_each(pos, head) \
  359. for (pos = (head)->next; pos != (head); pos = pos->next)
  360. /**
  361. * list_for_each_prev - iterate over a list backwards
  362. * @pos: the &struct list_head to use as a loop cursor.
  363. * @head: the head for your list.
  364. */
  365. #define list_for_each_prev(pos, head) \
  366. for (pos = (head)->prev; pos != (head); pos = pos->prev)
  367. /**
  368. * list_for_each_safe - iterate over a list safe against removal of list entry
  369. * @pos: the &struct list_head to use as a loop cursor.
  370. * @n: another &struct list_head to use as temporary storage
  371. * @head: the head for your list.
  372. */
  373. #define list_for_each_safe(pos, n, head) \
  374. for (pos = (head)->next, n = pos->next; pos != (head); \
  375. pos = n, n = pos->next)
  376. /**
  377. * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
  378. * @pos: the &struct list_head to use as a loop cursor.
  379. * @n: another &struct list_head to use as temporary storage
  380. * @head: the head for your list.
  381. */
  382. #define list_for_each_prev_safe(pos, n, head) \
  383. for (pos = (head)->prev, n = pos->prev; \
  384. pos != (head); \
  385. pos = n, n = pos->prev)
  386. /**
  387. * list_for_each_entry - iterate over list of given type
  388. * @pos: the type * to use as a loop cursor.
  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(pos, head, member) \
  393. for (pos = list_entry((head)->next, typeof(*pos), member); \
  394. &pos->member != (head); \
  395. pos = list_entry(pos->member.next, typeof(*pos), member))
  396. /**
  397. * list_for_each_entry_reverse - iterate backwards over list of given type.
  398. * @pos: the type * to use as a loop cursor.
  399. * @head: the head for your list.
  400. * @member: the name of the list_struct within the struct.
  401. */
  402. #define list_for_each_entry_reverse(pos, head, member) \
  403. for (pos = list_entry((head)->prev, typeof(*pos), member); \
  404. &pos->member != (head); \
  405. pos = list_entry(pos->member.prev, typeof(*pos), member))
  406. /**
  407. * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
  408. * @pos: the type * to use as a start point
  409. * @head: the head of the list
  410. * @member: the name of the list_struct within the struct.
  411. *
  412. * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
  413. */
  414. #define list_prepare_entry(pos, head, member) \
  415. ((pos) ? : list_entry(head, typeof(*pos), member))
  416. /**
  417. * list_for_each_entry_continue - continue iteration over list of given type
  418. * @pos: the type * to use as a loop cursor.
  419. * @head: the head for your list.
  420. * @member: the name of the list_struct within the struct.
  421. *
  422. * Continue to iterate over list of given type, continuing after
  423. * the current position.
  424. */
  425. #define list_for_each_entry_continue(pos, head, member) \
  426. for (pos = list_entry(pos->member.next, typeof(*pos), member); \
  427. &pos->member != (head); \
  428. pos = list_entry(pos->member.next, typeof(*pos), member))
  429. /**
  430. * list_for_each_entry_continue_reverse - iterate backwards from the given point
  431. * @pos: the type * to use as a loop cursor.
  432. * @head: the head for your list.
  433. * @member: the name of the list_struct within the struct.
  434. *
  435. * Start to iterate over list of given type backwards, continuing after
  436. * the current position.
  437. */
  438. #define list_for_each_entry_continue_reverse(pos, head, member) \
  439. for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
  440. &pos->member != (head); \
  441. pos = list_entry(pos->member.prev, typeof(*pos), member))
  442. /**
  443. * list_for_each_entry_from - iterate over list of given type from the current point
  444. * @pos: the type * to use as a loop cursor.
  445. * @head: the head for your list.
  446. * @member: the name of the list_struct within the struct.
  447. *
  448. * Iterate over list of given type, continuing from current position.
  449. */
  450. #define list_for_each_entry_from(pos, head, member) \
  451. for (; &pos->member != (head); \
  452. pos = list_entry(pos->member.next, typeof(*pos), member))
  453. /**
  454. * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  455. * @pos: the type * to use as a loop cursor.
  456. * @n: another type * to use as temporary storage
  457. * @head: the head for your list.
  458. * @member: the name of the list_struct within the struct.
  459. */
  460. #define list_for_each_entry_safe(pos, n, head, member) \
  461. for (pos = list_entry((head)->next, typeof(*pos), member), \
  462. n = list_entry(pos->member.next, typeof(*pos), member); \
  463. &pos->member != (head); \
  464. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  465. /**
  466. * list_for_each_entry_safe_continue - continue list iteration safe against removal
  467. * @pos: the type * to use as a loop cursor.
  468. * @n: another type * to use as temporary storage
  469. * @head: the head for your list.
  470. * @member: the name of the list_struct within the struct.
  471. *
  472. * Iterate over list of given type, continuing after current point,
  473. * safe against removal of list entry.
  474. */
  475. #define list_for_each_entry_safe_continue(pos, n, head, member) \
  476. for (pos = list_entry(pos->member.next, typeof(*pos), member), \
  477. n = list_entry(pos->member.next, typeof(*pos), member); \
  478. &pos->member != (head); \
  479. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  480. /**
  481. * list_for_each_entry_safe_from - iterate over list from current point safe against removal
  482. * @pos: the type * to use as a loop cursor.
  483. * @n: another type * to use as temporary storage
  484. * @head: the head for your list.
  485. * @member: the name of the list_struct within the struct.
  486. *
  487. * Iterate over list of given type from current point, safe against
  488. * removal of list entry.
  489. */
  490. #define list_for_each_entry_safe_from(pos, n, head, member) \
  491. for (n = list_entry(pos->member.next, typeof(*pos), member); \
  492. &pos->member != (head); \
  493. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  494. /**
  495. * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
  496. * @pos: the type * to use as a loop cursor.
  497. * @n: another type * to use as temporary storage
  498. * @head: the head for your list.
  499. * @member: the name of the list_struct within the struct.
  500. *
  501. * Iterate backwards over list of given type, safe against removal
  502. * of list entry.
  503. */
  504. #define list_for_each_entry_safe_reverse(pos, n, head, member) \
  505. for (pos = list_entry((head)->prev, typeof(*pos), member), \
  506. n = list_entry(pos->member.prev, typeof(*pos), member); \
  507. &pos->member != (head); \
  508. pos = n, n = list_entry(n->member.prev, typeof(*n), member))
  509. /**
  510. * list_safe_reset_next - reset a stale list_for_each_entry_safe loop
  511. * @pos: the loop cursor used in the list_for_each_entry_safe loop
  512. * @n: temporary storage used in list_for_each_entry_safe
  513. * @member: the name of the list_struct within the struct.
  514. *
  515. * list_safe_reset_next is not safe to use in general if the list may be
  516. * modified concurrently (eg. the lock is dropped in the loop body). An
  517. * exception to this is if the cursor element (pos) is pinned in the list,
  518. * and list_safe_reset_next is called after re-taking the lock and before
  519. * completing the current iteration of the loop body.
  520. */
  521. #define list_safe_reset_next(pos, n, member) \
  522. n = list_entry(pos->member.next, typeof(*pos), member)
  523. /*
  524. * Double linked lists with a single pointer list head.
  525. * Mostly useful for hash tables where the two pointer list head is
  526. * too wasteful.
  527. * You lose the ability to access the tail in O(1).
  528. */
  529. #define HLIST_HEAD_INIT { .first = NULL }
  530. #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
  531. #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
  532. static inline void INIT_HLIST_NODE(struct hlist_node *h)
  533. {
  534. h->next = NULL;
  535. h->pprev = NULL;
  536. }
  537. static inline int hlist_unhashed(const struct hlist_node *h)
  538. {
  539. return !h->pprev;
  540. }
  541. static inline int hlist_empty(const struct hlist_head *h)
  542. {
  543. return !h->first;
  544. }
  545. static inline void __hlist_del(struct hlist_node *n)
  546. {
  547. struct hlist_node *next = n->next;
  548. struct hlist_node **pprev = n->pprev;
  549. *pprev = next;
  550. if (next)
  551. next->pprev = pprev;
  552. }
  553. static inline void hlist_del(struct hlist_node *n)
  554. {
  555. __hlist_del(n);
  556. n->next = LIST_POISON1;
  557. n->pprev = LIST_POISON2;
  558. }
  559. static inline void hlist_del_init(struct hlist_node *n)
  560. {
  561. if (!hlist_unhashed(n)) {
  562. __hlist_del(n);
  563. INIT_HLIST_NODE(n);
  564. }
  565. }
  566. static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
  567. {
  568. struct hlist_node *first = h->first;
  569. n->next = first;
  570. if (first)
  571. first->pprev = &n->next;
  572. h->first = n;
  573. n->pprev = &h->first;
  574. }
  575. /* next must be != NULL */
  576. static inline void hlist_add_before(struct hlist_node *n,
  577. struct hlist_node *next)
  578. {
  579. n->pprev = next->pprev;
  580. n->next = next;
  581. next->pprev = &n->next;
  582. *(n->pprev) = n;
  583. }
  584. static inline void hlist_add_after(struct hlist_node *n,
  585. struct hlist_node *next)
  586. {
  587. next->next = n->next;
  588. n->next = next;
  589. next->pprev = &n->next;
  590. if(next->next)
  591. next->next->pprev = &next->next;
  592. }
  593. /* after that we'll appear to be on some hlist and hlist_del will work */
  594. static inline void hlist_add_fake(struct hlist_node *n)
  595. {
  596. n->pprev = &n->next;
  597. }
  598. /*
  599. * Move a list from one list head to another. Fixup the pprev
  600. * reference of the first entry if it exists.
  601. */
  602. static inline void hlist_move_list(struct hlist_head *old,
  603. struct hlist_head *new)
  604. {
  605. new->first = old->first;
  606. if (new->first)
  607. new->first->pprev = &new->first;
  608. old->first = NULL;
  609. }
  610. #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
  611. #define hlist_entry_safe(ptr, type, member) \
  612. ({ typeof(ptr) ____ptr = (ptr); \
  613. ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
  614. })
  615. #define hlist_for_each(pos, head) \
  616. for (pos = (head)->first; pos ; pos = pos->next)
  617. #define hlist_for_each_safe(pos, n, head) \
  618. for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
  619. pos = n)
  620. /**
  621. * hlist_for_each_entry - iterate over list of given type
  622. * @tpos: the type * to use as a loop cursor.
  623. * @pos: the &struct hlist_node to use as a loop cursor.
  624. * @head: the head for your list.
  625. * @member: the name of the hlist_node within the struct.
  626. */
  627. #define hlist_for_each_entry(tpos, pos, head, member) \
  628. for (pos = (head)->first; \
  629. pos && \
  630. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  631. pos = pos->next)
  632. /**
  633. * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
  634. * @tpos: the type * to use as a loop cursor.
  635. * @pos: the &struct hlist_node to use as a loop cursor.
  636. * @member: the name of the hlist_node within the struct.
  637. */
  638. #define hlist_for_each_entry_continue(tpos, pos, member) \
  639. for (pos = (pos)->next; \
  640. pos && \
  641. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  642. pos = pos->next)
  643. /**
  644. * hlist_for_each_entry_from - iterate over a hlist continuing from current point
  645. * @tpos: the type * to use as a loop cursor.
  646. * @pos: the &struct hlist_node to use as a loop cursor.
  647. * @member: the name of the hlist_node within the struct.
  648. */
  649. #define hlist_for_each_entry_from(tpos, pos, member) \
  650. for (; pos && \
  651. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  652. pos = pos->next)
  653. /**
  654. * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  655. * @tpos: the type * to use as a loop cursor.
  656. * @pos: the &struct hlist_node to use as a loop cursor.
  657. * @n: another &struct hlist_node to use as temporary storage
  658. * @head: the head for your list.
  659. * @member: the name of the hlist_node within the struct.
  660. */
  661. #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
  662. for (pos = (head)->first; \
  663. pos && ({ n = pos->next; 1; }) && \
  664. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  665. pos = n)
  666. /**
  667. * hlist_for_each_entry_safe_new - iterate over list of given type safe against removal of list entry
  668. * @pos: the type * to use as a loop cursor.
  669. * @n: another &struct hlist_node to use as temporary storage
  670. * @head: the head for your list.
  671. * @member: the name of the hlist_node within the struct.
  672. */
  673. #define hlist_for_each_entry_safe_new(pos, n, head, member) \
  674. for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
  675. pos && ({ n = pos->member.next; 1; }); \
  676. pos = hlist_entry_safe(n, typeof(*pos), member))
  677. #endif