From fca2afaa590bf2b4a12c82e06999c5c563646c55 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 11 Dec 2009 13:23:30 +0100 Subject: [PATCH] lockfree: fifo - node->next uses boost.atomic Signed-off-by: Tim Blechmann --- boost/lockfree/fifo.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/boost/lockfree/fifo.hpp b/boost/lockfree/fifo.hpp index 36475fd..035cf47 100644 --- a/boost/lockfree/fifo.hpp +++ b/boost/lockfree/fifo.hpp @@ -15,6 +15,7 @@ #ifndef BOOST_LOCKFREE_FIFO_HPP_INCLUDED #define BOOST_LOCKFREE_FIFO_HPP_INCLUDED +#include #include #include @@ -47,14 +48,17 @@ class fifo: node(T const & v): data(v) { - next.set(NULL, next.get_tag()+1); /* increment tag to avoid ABA problem */ + /* increment tag to avoid ABA problem */ + tagged_ptr_t old_next = next.load(memory_order_acquire); + tagged_ptr_t new_next (NULL, old_next.get_tag()+1); + next.store(new_next, memory_order_release); } node (void): - next(NULL) + next(tagged_ptr_t(NULL, 0)) {} - tagged_ptr_t next; + atomic next; T data; }; @@ -123,7 +127,7 @@ public: { if (next.get_ptr() == 0) { - if ( tail->next.cas(next, n) ) + if ( tail->next.compare_exchange_strong(next, tagged_ptr(n, next.get_tag() + 1)) ) { tail_.cas(tail, n); return true; @@ -143,7 +147,7 @@ public: read_memory_barrier(); atomic_node_ptr tail(tail_); - node * next = head->next.get_ptr(); + node * next = head->next.load(memory_order_acquire).get_ptr(); read_memory_barrier(); if (likely(head == head_)) -- 2.11.4.GIT