list.h 21 KB

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