list.h 21 KB

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