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