From 485d7468e31f599da003c6b36994569d50e65c3a Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 11 Dec 2009 12:05:28 +0100 Subject: [PATCH] lockfree: remove atomic_int class, use boost.atomic instead Signed-off-by: Tim Blechmann --- boost/lockfree/atomic_int.hpp | 233 ------------------------------------ boost/lockfree/detail/freelist.hpp | 4 +- boost/lockfree/fifo.hpp | 1 - boost/lockfree/stack.hpp | 1 - libs/lockfree/examples/fifo.cpp | 6 +- libs/lockfree/examples/stack.cpp | 6 +- libs/lockfree/test/fifo_test.cpp | 8 +- libs/lockfree/test/test_helpers.hpp | 4 +- 8 files changed, 15 insertions(+), 248 deletions(-) delete mode 100644 boost/lockfree/atomic_int.hpp diff --git a/boost/lockfree/atomic_int.hpp b/boost/lockfree/atomic_int.hpp deleted file mode 100644 index 58d7235..0000000 --- a/boost/lockfree/atomic_int.hpp +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright (C) 2007, 2008 Tim Blechmann & Thomas Grill -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Disclaimer: Not a Boost library. - -#ifndef BOOST_LOCKFREE_ATOMIC_INT_HPP -#define BOOST_LOCKFREE_ATOMIC_INT_HPP - -#include -#include -#include -#include - -namespace boost -{ -namespace lockfree -{ - -#if defined(__GNUC__) && ( (__GNUC__ > 4) || ((__GNUC__ >= 4) && (__GNUC_MINOR__ >= 1)) ) || __INTEL_COMPILER - -template -class atomic_int: - boost::noncopyable -{ -public: - explicit atomic_int(T v = 0): - value(v) - {} - - operator T(void) const - { - return __sync_fetch_and_add(&value, 0); - } - - void operator =(T v) - { - value = v; - __sync_synchronize(); - } - - T operator +=(T v) - { - return __sync_add_and_fetch(&value, v); - } - - T operator -=(T v) - { - return __sync_sub_and_fetch(&value, v); - } - - /* prefix operator */ - T operator ++(void) - { - return __sync_add_and_fetch(&value, 1); - } - - /* prefix operator */ - T operator --(void) - { - return __sync_sub_and_fetch(&value, 1); - } - - /* postfix operator */ - T operator ++(int) - { - return __sync_fetch_and_add(&value, 1); - } - - /* postfix operator */ - T operator --(int) - { - return __sync_fetch_and_sub(&value, 1); - } - -private: - mutable T value; -}; - -#elif defined(__GLIBCPP__) || defined(__GLIBCXX__) - -template -class atomic_int: - boost::noncopyable -{ -public: - explicit atomic_int(T v = 0): - value(v) - {} - - operator T(void) const - { - return __gnu_cxx::__exchange_and_add(&value, 0); - } - - void operator =(T v) - { - value = v; - memory_barrier(); - } - - T operator +=(T v) - { - return __gnu_cxx::__exchange_and_add(&value, v) + v; - } - - T operator -=(T v) - { - return __gnu_cxx::__exchange_and_add(&value, -v) - v; - } - - /* prefix operator */ - T operator ++(void) - { - return operator+=(1); - } - - /* prefix operator */ - T operator --(void) - { - return operator-=(1); - } - - /* postfix operator */ - T operator ++(int) - { - return __gnu_cxx::__exchange_and_add(&value, 1); - } - - /* postfix operator */ - T operator --(int) - { - return __gnu_cxx::__exchange_and_add(&value, -1); - } - -private: - mutable _Atomic_word value; -}; - -#else /* emulate via atomic_cas */ - -template -class atomic_int: - boost::noncopyable -{ -public: - explicit atomic_int(T v = 0) - { - *this = v; - } - - operator T(void) const - { - memory_barrier(); - return value; - } - - void operator =(T v) - { - value = v; - memory_barrier(); - } - - /* prefix operator */ - T operator ++() - { - return *this += 1; - } - - /* prefix operator */ - T operator --() - { - return *this -= 1; - } - - T operator +=(T v) - { - for(;;) - { - T oldv = value; - T newv = oldv + v; - if(likely(cas(&value, oldv, newv))) - return newv; - } - } - - T operator -=(T v) - { - for(;;) - { - T oldv = value; - T newv = oldv - v; - - if(likely(cas(&value, oldv, newv))) - return newv; - } - } - - /* postfix operator */ - T operator ++(int) - { - for(;;) - { - T oldv = value; - if(likely(cas(&value, oldv, oldv+1))) - return oldv; - } - } - - /* postfix operator */ - T operator --(int) - { - for(;;) - { - T oldv = value; - if(likely(cas(&value, oldv, oldv-1))) - return oldv; - } - } - -private: - T value; -}; - - -#endif - -} /* namespace lockfree */ -} /* namespace boost */ - -#endif /* BOOST_LOCKFREE_ATOMIC_INT_HPP */ diff --git a/boost/lockfree/detail/freelist.hpp b/boost/lockfree/detail/freelist.hpp index 7a7fbff..509640b 100644 --- a/boost/lockfree/detail/freelist.hpp +++ b/boost/lockfree/detail/freelist.hpp @@ -12,7 +12,7 @@ #define BOOST_LOCKFREE_FREELIST_HPP_INCLUDED #include -#include +#include #include #include @@ -139,7 +139,7 @@ private: } tagged_ptr pool_; - atomic_int free_list_size; + boost::atomic free_list_size; }; template > diff --git a/boost/lockfree/fifo.hpp b/boost/lockfree/fifo.hpp index a89b03c..36475fd 100644 --- a/boost/lockfree/fifo.hpp +++ b/boost/lockfree/fifo.hpp @@ -15,7 +15,6 @@ #ifndef BOOST_LOCKFREE_FIFO_HPP_INCLUDED #define BOOST_LOCKFREE_FIFO_HPP_INCLUDED -#include #include #include diff --git a/boost/lockfree/stack.hpp b/boost/lockfree/stack.hpp index 9f9d0fb..4f0c3e5 100644 --- a/boost/lockfree/stack.hpp +++ b/boost/lockfree/stack.hpp @@ -18,7 +18,6 @@ #include #include - namespace boost { namespace lockfree diff --git a/libs/lockfree/examples/fifo.cpp b/libs/lockfree/examples/fifo.cpp index 3522b8e..75623f8 100644 --- a/libs/lockfree/examples/fifo.cpp +++ b/libs/lockfree/examples/fifo.cpp @@ -5,12 +5,12 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include #include #include -boost::lockfree::atomic_int producer_count(0); -boost::lockfree::atomic_int consumer_count(0); +boost::atomic_int producer_count(0); +boost::atomic_int consumer_count(0); boost::lockfree::fifo fifo; diff --git a/libs/lockfree/examples/stack.cpp b/libs/lockfree/examples/stack.cpp index 26df70a..ceaeca5 100644 --- a/libs/lockfree/examples/stack.cpp +++ b/libs/lockfree/examples/stack.cpp @@ -5,12 +5,12 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include #include #include -boost::lockfree::atomic_int producer_count(0); -boost::lockfree::atomic_int consumer_count(0); +boost::atomic_int producer_count(0); +boost::atomic_int consumer_count(0); boost::lockfree::stack stack; diff --git a/libs/lockfree/test/fifo_test.cpp b/libs/lockfree/test/fifo_test.cpp index c247389..edc032b 100644 --- a/libs/lockfree/test/fifo_test.cpp +++ b/libs/lockfree/test/fifo_test.cpp @@ -85,7 +85,7 @@ struct fifo_tester { fifo sf; - atomic_int fifo_cnt; + atomic fifo_cnt, received_nodes; static_hashed_set working_set; @@ -94,6 +94,10 @@ struct fifo_tester static const int reader_threads = 2; static const int writer_threads = 2; + fifo_tester(void): + fifo_cnt(0), received_nodes(0) + {} + void add(void) { for (uint i = 0; i != nodes_per_thread; ++i) @@ -114,8 +118,6 @@ struct fifo_tester } } - atomic_int received_nodes; - bool get_element(void) { int data; diff --git a/libs/lockfree/test/test_helpers.hpp b/libs/lockfree/test/test_helpers.hpp index 1d64709..eb9a590 100644 --- a/libs/lockfree/test/test_helpers.hpp +++ b/libs/lockfree/test/test_helpers.hpp @@ -1,12 +1,12 @@ #include #include -#include +#include #include template int_type generate_id(void) { - static boost::lockfree::atomic_int generator(0); + static boost::atomic generator(0); return ++generator; } -- 2.11.4.GIT