1
0

list.h 21 KB

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