Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. struct __fifo_node_t {
  2. void *next;
  3. };
  4. typedef struct __fifo_node_t fifo_node_t;
  5.  
  6. struct __fifo_list_t {
  7. void *next;
  8. void *tail;
  9. };
  10. typedef struct __fifo_list_t fifo_list_t;
  11.  
  12. static inline void __fifo_list_push(fifo_list_t *head, fifo_node_t *node)
  13. {
  14. fifo_node_t *prev;
  15.  
  16. node->next = head;
  17. prev = atomic_xchg64(&head->tail, node);
  18. prev->next = node;
  19. }
  20.  
  21. static inline fifo_node_t *__fifo_list_pop(fifo_list_t *head)
  22. {
  23. fifo_node_t *node;
  24. while ((node = ACCESS_ONCE(head->next)) != head) {
  25. fifo_node_t *next = ACCESS_ONCE(node->next);
  26. if (cmpxchg_eq(&head->next, node, next) == node) {
  27. if (cmpxchg_eq(&head->tail, node, head) != node &&
  28. next == head)
  29. while (ACCESS_ONCE(head->next) == next)
  30. head->next = ACCESS_ONCE(node->next);
  31. return node;
  32. }
  33. }
  34. return NULL;
  35. }
  36.  
  37. static inline void __fifo_list_init(fifo_list_t *head)
  38. {
  39. head->next = head->tail = head;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement