4 #if __GNUC__ == 4 && __GNUC_MINOR__ == 4
5 # include <cstdatomic> // <atomic> is named <cstdatomic> in gcc 4.4
15 node* n = new node(NULL, NULL);
16 std::atomic_store(&head, n); // head.store(n);
17 std::atomic_store(&tail, n); // tail.store(n);
22 node* n = head.load();
32 return head.load() == tail.load();
35 // size() is not not thread-safe
39 for (node* n = head.load()->next; n != NULL; n = n->next)
44 bool push(const T& val)
46 node* old_tail = tail.load();
47 node* n = new node(val, NULL);
49 std::atomic_store(&tail, n); // tail.store(n);
50 return (old_tail == head.load());
55 node* old_head = head.load();
56 if (old_head == tail.load()) { // empty?
59 node* new_head = old_head->next;
60 std::atomic_store(&head, new_head); // head.store(new_head);
62 res = new_head->value;
69 node(const T& v, node* n): value(v), next(n) { }
74 std::atomic<node*> head;
75 std::atomic<node*> tail;
78 #endif // !SYNC_QUEUE_H