list.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. #ifndef _LINUX_LIST_H
  2. #define _LINUX_LIST_H
  3. #ifdef __KERNEL__
  4. #include <linux/stddef.h>
  5. #include <linux/prefetch.h>
  6. #include <asm/system.h>
  7. /*
  8. * These are non-NULL pointers that will result in page faults
  9. * under normal circumstances, used to verify that nobody uses
  10. * non-initialized list entries.
  11. */
  12. #define LIST_POISON1 ((void *) 0x00100100)
  13. #define LIST_POISON2 ((void *) 0x00200200)
  14. /*
  15. * Simple doubly linked list implementation.
  16. *
  17. * Some of the internal functions ("__xxx") are useful when
  18. * manipulating whole lists rather than single entries, as
  19. * sometimes we already know the next/prev entries and we can
  20. * generate better code by using them directly rather than
  21. * using the generic single-entry routines.
  22. */
  23. struct list_head {
  24. struct list_head *next, *prev;
  25. };
  26. #define LIST_HEAD_INIT(name) { &(name), &(name) }
  27. #define LIST_HEAD(name) \
  28. struct list_head name = LIST_HEAD_INIT(name)
  29. #define INIT_LIST_HEAD(ptr) do { \
  30. (ptr)->next = (ptr); (ptr)->prev = (ptr); \
  31. } while (0)
  32. /*
  33. * Insert a new entry between two known consecutive entries.
  34. *
  35. * This is only for internal list manipulation where we know
  36. * the prev/next entries already!
  37. */
  38. static inline void __list_add(struct list_head *new,
  39. struct list_head *prev,
  40. struct list_head *next)
  41. {
  42. next->prev = new;
  43. new->next = next;
  44. new->prev = prev;
  45. prev->next = new;
  46. }
  47. /**
  48. * list_add - add a new entry
  49. * @new: new entry to be added
  50. * @head: list head to add it after
  51. *
  52. * Insert a new entry after the specified head.
  53. * This is good for implementing stacks.
  54. */
  55. static inline void list_add(struct list_head *new, struct list_head *head)
  56. {
  57. __list_add(new, head, head->next);
  58. }
  59. /**
  60. * list_add_tail - add a new entry
  61. * @new: new entry to be added
  62. * @head: list head to add it before
  63. *
  64. * Insert a new entry before the specified head.
  65. * This is useful for implementing queues.
  66. */
  67. static inline void list_add_tail(struct list_head *new, struct list_head *head)
  68. {
  69. __list_add(new, head->prev, head);
  70. }
  71. /*
  72. * Insert a new entry between two known consecutive entries.
  73. *
  74. * This is only for internal list manipulation where we know
  75. * the prev/next entries already!
  76. */
  77. static inline void __list_add_rcu(struct list_head * new,
  78. struct list_head * prev, struct list_head * next)
  79. {
  80. new->next = next;
  81. new->prev = prev;
  82. smp_wmb();
  83. next->prev = new;
  84. prev->next = new;
  85. }
  86. /**
  87. * list_add_rcu - add a new entry to rcu-protected list
  88. * @new: new entry to be added
  89. * @head: list head to add it after
  90. *
  91. * Insert a new entry after the specified head.
  92. * This is good for implementing stacks.
  93. *
  94. * The caller must take whatever precautions are necessary
  95. * (such as holding appropriate locks) to avoid racing
  96. * with another list-mutation primitive, such as list_add_rcu()
  97. * or list_del_rcu(), running on this same list.
  98. * However, it is perfectly legal to run concurrently with
  99. * the _rcu list-traversal primitives, such as
  100. * list_for_each_entry_rcu().
  101. */
  102. static inline void list_add_rcu(struct list_head *new, struct list_head *head)
  103. {
  104. __list_add_rcu(new, head, head->next);
  105. }
  106. /**
  107. * list_add_tail_rcu - add a new entry to rcu-protected list
  108. * @new: new entry to be added
  109. * @head: list head to add it before
  110. *
  111. * Insert a new entry before the specified head.
  112. * This is useful for implementing queues.
  113. *
  114. * The caller must take whatever precautions are necessary
  115. * (such as holding appropriate locks) to avoid racing
  116. * with another list-mutation primitive, such as list_add_tail_rcu()
  117. * or list_del_rcu(), running on this same list.
  118. * However, it is perfectly legal to run concurrently with
  119. * the _rcu list-traversal primitives, such as
  120. * list_for_each_entry_rcu().
  121. */
  122. static inline void list_add_tail_rcu(struct list_head *new,
  123. struct list_head *head)
  124. {
  125. __list_add_rcu(new, head->prev, head);
  126. }
  127. /*
  128. * Delete a list entry by making the prev/next entries
  129. * point to each other.
  130. *
  131. * This is only for internal list manipulation where we know
  132. * the prev/next entries already!
  133. */
  134. static inline void __list_del(struct list_head * prev, struct list_head * next)
  135. {
  136. next->prev = prev;
  137. prev->next = next;
  138. }
  139. /**
  140. * list_del - deletes entry from list.
  141. * @entry: the element to delete from the list.
  142. * Note: list_empty on entry does not return true after this, the entry is
  143. * in an undefined state.
  144. */
  145. static inline void list_del(struct list_head *entry)
  146. {
  147. __list_del(entry->prev, entry->next);
  148. entry->next = LIST_POISON1;
  149. entry->prev = LIST_POISON2;
  150. }
  151. /**
  152. * list_del_rcu - deletes entry from list without re-initialization
  153. * @entry: the element to delete from the list.
  154. *
  155. * Note: list_empty on entry does not return true after this,
  156. * the entry is in an undefined state. It is useful for RCU based
  157. * lockfree traversal.
  158. *
  159. * In particular, it means that we can not poison the forward
  160. * pointers that may still be used for walking the list.
  161. *
  162. * The caller must take whatever precautions are necessary
  163. * (such as holding appropriate locks) to avoid racing
  164. * with another list-mutation primitive, such as list_del_rcu()
  165. * or list_add_rcu(), running on this same list.
  166. * However, it is perfectly legal to run concurrently with
  167. * the _rcu list-traversal primitives, such as
  168. * list_for_each_entry_rcu().
  169. *
  170. * Note that the caller is not permitted to immediately free
  171. * the newly deleted entry. Instead, either synchronize_rcu()
  172. * or call_rcu() must be used to defer freeing until an RCU
  173. * grace period has elapsed.
  174. */
  175. static inline void list_del_rcu(struct list_head *entry)
  176. {
  177. __list_del(entry->prev, entry->next);
  178. entry->prev = LIST_POISON2;
  179. }
  180. /*
  181. * list_replace_rcu - replace old entry by new one
  182. * @old : the element to be replaced
  183. * @new : the new element to insert
  184. *
  185. * The old entry will be replaced with the new entry atomically.
  186. */
  187. static inline void list_replace_rcu(struct list_head *old, struct list_head *new){
  188. new->next = old->next;
  189. new->prev = old->prev;
  190. smp_wmb();
  191. new->next->prev = new;
  192. new->prev->next = new;
  193. }
  194. /**
  195. * list_del_init - deletes entry from list and reinitialize it.
  196. * @entry: the element to delete from the list.
  197. */
  198. static inline void list_del_init(struct list_head *entry)
  199. {
  200. __list_del(entry->prev, entry->next);
  201. INIT_LIST_HEAD(entry);
  202. }
  203. /**
  204. * list_move - delete from one list and add as another's head
  205. * @list: the entry to move
  206. * @head: the head that will precede our entry
  207. */
  208. static inline void list_move(struct list_head *list, struct list_head *head)
  209. {
  210. __list_del(list->prev, list->next);
  211. list_add(list, head);
  212. }
  213. /**
  214. * list_move_tail - delete from one list and add as another's tail
  215. * @list: the entry to move
  216. * @head: the head that will follow our entry
  217. */
  218. static inline void list_move_tail(struct list_head *list,
  219. struct list_head *head)
  220. {
  221. __list_del(list->prev, list->next);
  222. list_add_tail(list, head);
  223. }
  224. /**
  225. * list_empty - tests whether a list is empty
  226. * @head: the list to test.
  227. */
  228. static inline int list_empty(const struct list_head *head)
  229. {
  230. return head->next == head;
  231. }
  232. /**
  233. * list_empty_careful - tests whether a list is
  234. * empty _and_ checks that no other CPU might be
  235. * in the process of still modifying either member
  236. *
  237. * NOTE: using list_empty_careful() without synchronization
  238. * can only be safe if the only activity that can happen
  239. * to the list entry is list_del_init(). Eg. it cannot be used
  240. * if another CPU could re-list_add() it.
  241. *
  242. * @head: the list to test.
  243. */
  244. static inline int list_empty_careful(const struct list_head *head)
  245. {
  246. struct list_head *next = head->next;
  247. return (next == head) && (next == head->prev);
  248. }
  249. static inline void __list_splice(struct list_head *list,
  250. struct list_head *head)
  251. {
  252. struct list_head *first = list->next;
  253. struct list_head *last = list->prev;
  254. struct list_head *at = head->next;
  255. first->prev = head;
  256. head->next = first;
  257. last->next = at;
  258. at->prev = last;
  259. }
  260. /**
  261. * list_splice - join two lists
  262. * @list: the new list to add.
  263. * @head: the place to add it in the first list.
  264. */
  265. static inline void list_splice(struct list_head *list, struct list_head *head)
  266. {
  267. if (!list_empty(list))
  268. __list_splice(list, head);
  269. }
  270. /**
  271. * list_splice_init - join two lists and reinitialise the emptied list.
  272. * @list: the new list to add.
  273. * @head: the place to add it in the first list.
  274. *
  275. * The list at @list is reinitialised
  276. */
  277. static inline void list_splice_init(struct list_head *list,
  278. struct list_head *head)
  279. {
  280. if (!list_empty(list)) {
  281. __list_splice(list, head);
  282. INIT_LIST_HEAD(list);
  283. }
  284. }
  285. /**
  286. * list_entry - get the struct for this entry
  287. * @ptr: the &struct list_head pointer.
  288. * @type: the type of the struct this is embedded in.
  289. * @member: the name of the list_struct within the struct.
  290. */
  291. #define list_entry(ptr, type, member) \
  292. container_of(ptr, type, member)
  293. /**
  294. * list_for_each - iterate over a list
  295. * @pos: the &struct list_head to use as a loop counter.
  296. * @head: the head for your list.
  297. */
  298. #define list_for_each(pos, head) \
  299. for (pos = (head)->next; prefetch(pos->next), pos != (head); \
  300. pos = pos->next)
  301. /**
  302. * __list_for_each - iterate over a list
  303. * @pos: the &struct list_head to use as a loop counter.
  304. * @head: the head for your list.
  305. *
  306. * This variant differs from list_for_each() in that it's the
  307. * simplest possible list iteration code, no prefetching is done.
  308. * Use this for code that knows the list to be very short (empty
  309. * or 1 entry) most of the time.
  310. */
  311. #define __list_for_each(pos, head) \
  312. for (pos = (head)->next; pos != (head); pos = pos->next)
  313. /**
  314. * list_for_each_prev - iterate over a list backwards
  315. * @pos: the &struct list_head to use as a loop counter.
  316. * @head: the head for your list.
  317. */
  318. #define list_for_each_prev(pos, head) \
  319. for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
  320. pos = pos->prev)
  321. /**
  322. * list_for_each_safe - iterate over a list safe against removal of list entry
  323. * @pos: the &struct list_head to use as a loop counter.
  324. * @n: another &struct list_head to use as temporary storage
  325. * @head: the head for your list.
  326. */
  327. #define list_for_each_safe(pos, n, head) \
  328. for (pos = (head)->next, n = pos->next; pos != (head); \
  329. pos = n, n = pos->next)
  330. /**
  331. * list_for_each_entry - iterate over list of given type
  332. * @pos: the type * to use as a loop counter.
  333. * @head: the head for your list.
  334. * @member: the name of the list_struct within the struct.
  335. */
  336. #define list_for_each_entry(pos, head, member) \
  337. for (pos = list_entry((head)->next, typeof(*pos), member); \
  338. prefetch(pos->member.next), &pos->member != (head); \
  339. pos = list_entry(pos->member.next, typeof(*pos), member))
  340. /**
  341. * list_for_each_entry_reverse - iterate backwards over list of given type.
  342. * @pos: the type * to use as a loop counter.
  343. * @head: the head for your list.
  344. * @member: the name of the list_struct within the struct.
  345. */
  346. #define list_for_each_entry_reverse(pos, head, member) \
  347. for (pos = list_entry((head)->prev, typeof(*pos), member); \
  348. prefetch(pos->member.prev), &pos->member != (head); \
  349. pos = list_entry(pos->member.prev, typeof(*pos), member))
  350. /**
  351. * list_prepare_entry - prepare a pos entry for use as a start point in
  352. * list_for_each_entry_continue
  353. * @pos: the type * to use as a start point
  354. * @head: the head of the list
  355. * @member: the name of the list_struct within the struct.
  356. */
  357. #define list_prepare_entry(pos, head, member) \
  358. ((pos) ? : list_entry(head, typeof(*pos), member))
  359. /**
  360. * list_for_each_entry_continue - iterate over list of given type
  361. * continuing after existing point
  362. * @pos: the type * to use as a loop counter.
  363. * @head: the head for your list.
  364. * @member: the name of the list_struct within the struct.
  365. */
  366. #define list_for_each_entry_continue(pos, head, member) \
  367. for (pos = list_entry(pos->member.next, typeof(*pos), member); \
  368. prefetch(pos->member.next), &pos->member != (head); \
  369. pos = list_entry(pos->member.next, typeof(*pos), member))
  370. /**
  371. * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  372. * @pos: the type * to use as a loop counter.
  373. * @n: another type * to use as temporary storage
  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_safe(pos, n, head, member) \
  378. for (pos = list_entry((head)->next, typeof(*pos), member), \
  379. n = list_entry(pos->member.next, typeof(*pos), member); \
  380. &pos->member != (head); \
  381. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  382. /**
  383. * list_for_each_rcu - iterate over an rcu-protected list
  384. * @pos: the &struct list_head to use as a loop counter.
  385. * @head: the head for your list.
  386. *
  387. * This list-traversal primitive may safely run concurrently with
  388. * the _rcu list-mutation primitives such as list_add_rcu()
  389. * as long as the traversal is guarded by rcu_read_lock().
  390. */
  391. #define list_for_each_rcu(pos, head) \
  392. for (pos = (head)->next; prefetch(pos->next), pos != (head); \
  393. pos = rcu_dereference(pos->next))
  394. #define __list_for_each_rcu(pos, head) \
  395. for (pos = (head)->next; pos != (head); \
  396. pos = rcu_dereference(pos->next))
  397. /**
  398. * list_for_each_safe_rcu - iterate over an rcu-protected list safe
  399. * against removal of list entry
  400. * @pos: the &struct list_head to use as a loop counter.
  401. * @n: another &struct list_head to use as temporary storage
  402. * @head: the head for your list.
  403. *
  404. * This list-traversal primitive may safely run concurrently with
  405. * the _rcu list-mutation primitives such as list_add_rcu()
  406. * as long as the traversal is guarded by rcu_read_lock().
  407. */
  408. #define list_for_each_safe_rcu(pos, n, head) \
  409. for (pos = (head)->next, n = pos->next; pos != (head); \
  410. pos = rcu_dereference(n), n = pos->next)
  411. /**
  412. * list_for_each_entry_rcu - iterate over rcu list of given type
  413. * @pos: the type * to use as a loop counter.
  414. * @head: the head for your list.
  415. * @member: the name of the list_struct within the struct.
  416. *
  417. * This list-traversal primitive may safely run concurrently with
  418. * the _rcu list-mutation primitives such as list_add_rcu()
  419. * as long as the traversal is guarded by rcu_read_lock().
  420. */
  421. #define list_for_each_entry_rcu(pos, head, member) \
  422. for (pos = list_entry((head)->next, typeof(*pos), member); \
  423. prefetch(pos->member.next), &pos->member != (head); \
  424. pos = rcu_dereference(list_entry(pos->member.next, \
  425. typeof(*pos), member)))
  426. /**
  427. * list_for_each_continue_rcu - iterate over an rcu-protected list
  428. * continuing after existing point.
  429. * @pos: the &struct list_head to use as a loop counter.
  430. * @head: the head for your list.
  431. *
  432. * This list-traversal primitive may safely run concurrently with
  433. * the _rcu list-mutation primitives such as list_add_rcu()
  434. * as long as the traversal is guarded by rcu_read_lock().
  435. */
  436. #define list_for_each_continue_rcu(pos, head) \
  437. for ((pos) = (pos)->next; prefetch((pos)->next), (pos) != (head); \
  438. (pos) = rcu_dereference((pos)->next))
  439. /*
  440. * Double linked lists with a single pointer list head.
  441. * Mostly useful for hash tables where the two pointer list head is
  442. * too wasteful.
  443. * You lose the ability to access the tail in O(1).
  444. */
  445. struct hlist_head {
  446. struct hlist_node *first;
  447. };
  448. struct hlist_node {
  449. struct hlist_node *next, **pprev;
  450. };
  451. #define HLIST_HEAD_INIT { .first = NULL }
  452. #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
  453. #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
  454. #define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
  455. static inline int hlist_unhashed(const struct hlist_node *h)
  456. {
  457. return !h->pprev;
  458. }
  459. static inline int hlist_empty(const struct hlist_head *h)
  460. {
  461. return !h->first;
  462. }
  463. static inline void __hlist_del(struct hlist_node *n)
  464. {
  465. struct hlist_node *next = n->next;
  466. struct hlist_node **pprev = n->pprev;
  467. *pprev = next;
  468. if (next)
  469. next->pprev = pprev;
  470. }
  471. static inline void hlist_del(struct hlist_node *n)
  472. {
  473. __hlist_del(n);
  474. n->next = LIST_POISON1;
  475. n->pprev = LIST_POISON2;
  476. }
  477. /**
  478. * hlist_del_rcu - deletes entry from hash list without re-initialization
  479. * @n: the element to delete from the hash list.
  480. *
  481. * Note: list_unhashed() on entry does not return true after this,
  482. * the entry is in an undefined state. It is useful for RCU based
  483. * lockfree traversal.
  484. *
  485. * In particular, it means that we can not poison the forward
  486. * pointers that may still be used for walking the hash list.
  487. *
  488. * The caller must take whatever precautions are necessary
  489. * (such as holding appropriate locks) to avoid racing
  490. * with another list-mutation primitive, such as hlist_add_head_rcu()
  491. * or hlist_del_rcu(), running on this same list.
  492. * However, it is perfectly legal to run concurrently with
  493. * the _rcu list-traversal primitives, such as
  494. * hlist_for_each_entry().
  495. */
  496. static inline void hlist_del_rcu(struct hlist_node *n)
  497. {
  498. __hlist_del(n);
  499. n->pprev = LIST_POISON2;
  500. }
  501. static inline void hlist_del_init(struct hlist_node *n)
  502. {
  503. if (n->pprev) {
  504. __hlist_del(n);
  505. INIT_HLIST_NODE(n);
  506. }
  507. }
  508. static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
  509. {
  510. struct hlist_node *first = h->first;
  511. n->next = first;
  512. if (first)
  513. first->pprev = &n->next;
  514. h->first = n;
  515. n->pprev = &h->first;
  516. }
  517. /**
  518. * hlist_add_head_rcu - adds the specified element to the specified hlist,
  519. * while permitting racing traversals.
  520. * @n: the element to add to the hash list.
  521. * @h: the list to add to.
  522. *
  523. * The caller must take whatever precautions are necessary
  524. * (such as holding appropriate locks) to avoid racing
  525. * with another list-mutation primitive, such as hlist_add_head_rcu()
  526. * or hlist_del_rcu(), running on this same list.
  527. * However, it is perfectly legal to run concurrently with
  528. * the _rcu list-traversal primitives, such as
  529. * hlist_for_each_rcu(), used to prevent memory-consistency
  530. * problems on Alpha CPUs. Regardless of the type of CPU, the
  531. * list-traversal primitive must be guarded by rcu_read_lock().
  532. */
  533. static inline void hlist_add_head_rcu(struct hlist_node *n,
  534. struct hlist_head *h)
  535. {
  536. struct hlist_node *first = h->first;
  537. n->next = first;
  538. n->pprev = &h->first;
  539. smp_wmb();
  540. if (first)
  541. first->pprev = &n->next;
  542. h->first = n;
  543. }
  544. /* next must be != NULL */
  545. static inline void hlist_add_before(struct hlist_node *n,
  546. struct hlist_node *next)
  547. {
  548. n->pprev = next->pprev;
  549. n->next = next;
  550. next->pprev = &n->next;
  551. *(n->pprev) = n;
  552. }
  553. static inline void hlist_add_after(struct hlist_node *n,
  554. struct hlist_node *next)
  555. {
  556. next->next = n->next;
  557. n->next = next;
  558. next->pprev = &n->next;
  559. if(next->next)
  560. next->next->pprev = &next->next;
  561. }
  562. #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
  563. #define hlist_for_each(pos, head) \
  564. for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
  565. pos = pos->next)
  566. #define hlist_for_each_safe(pos, n, head) \
  567. for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
  568. pos = n)
  569. #define hlist_for_each_rcu(pos, head) \
  570. for ((pos) = (head)->first; pos && ({ prefetch((pos)->next); 1; }); \
  571. (pos) = rcu_dereference((pos)->next))
  572. /**
  573. * hlist_for_each_entry - iterate over list of given type
  574. * @tpos: the type * to use as a loop counter.
  575. * @pos: the &struct hlist_node to use as a loop counter.
  576. * @head: the head for your list.
  577. * @member: the name of the hlist_node within the struct.
  578. */
  579. #define hlist_for_each_entry(tpos, pos, head, member) \
  580. for (pos = (head)->first; \
  581. pos && ({ prefetch(pos->next); 1;}) && \
  582. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  583. pos = pos->next)
  584. /**
  585. * hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
  586. * @tpos: the type * to use as a loop counter.
  587. * @pos: the &struct hlist_node to use as a loop counter.
  588. * @member: the name of the hlist_node within the struct.
  589. */
  590. #define hlist_for_each_entry_continue(tpos, pos, member) \
  591. for (pos = (pos)->next; \
  592. pos && ({ prefetch(pos->next); 1;}) && \
  593. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  594. pos = pos->next)
  595. /**
  596. * hlist_for_each_entry_from - iterate over a hlist continuing from existing point
  597. * @tpos: the type * to use as a loop counter.
  598. * @pos: the &struct hlist_node to use as a loop counter.
  599. * @member: the name of the hlist_node within the struct.
  600. */
  601. #define hlist_for_each_entry_from(tpos, pos, member) \
  602. for (; pos && ({ prefetch(pos->next); 1;}) && \
  603. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  604. pos = pos->next)
  605. /**
  606. * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  607. * @tpos: the type * to use as a loop counter.
  608. * @pos: the &struct hlist_node to use as a loop counter.
  609. * @n: another &struct hlist_node to use as temporary storage
  610. * @head: the head for your list.
  611. * @member: the name of the hlist_node within the struct.
  612. */
  613. #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
  614. for (pos = (head)->first; \
  615. pos && ({ n = pos->next; 1; }) && \
  616. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  617. pos = n)
  618. /**
  619. * hlist_for_each_entry_rcu - iterate over rcu list of given type
  620. * @pos: the type * to use as a loop counter.
  621. * @pos: the &struct hlist_node to use as a loop counter.
  622. * @head: the head for your list.
  623. * @member: the name of the hlist_node within the struct.
  624. *
  625. * This list-traversal primitive may safely run concurrently with
  626. * the _rcu list-mutation primitives such as hlist_add_head_rcu()
  627. * as long as the traversal is guarded by rcu_read_lock().
  628. */
  629. #define hlist_for_each_entry_rcu(tpos, pos, head, member) \
  630. for (pos = (head)->first; \
  631. pos && ({ prefetch(pos->next); 1;}) && \
  632. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  633. pos = rcu_dereference(pos->next))
  634. #else
  635. #warning "don't include kernel headers in userspace"
  636. #endif /* __KERNEL__ */
  637. #endif