blob: 39300e17c723ca0bf6d980284843018b8b1159e8 [file] [log] [blame]
Jeff Thompsonf7d49942013-08-01 16:47:40 -07001#ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED
2#define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED
3
4//
5// boost/detail/atomic_count_sync.hpp
6//
7// atomic_count for g++ 4.1+
8//
9// http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html
10//
11// Copyright 2007 Peter Dimov
12//
13// Distributed under the Boost Software License, Version 1.0. (See
14// accompanying file LICENSE_1_0.txt or copy at
15// http://www.boost.org/LICENSE_1_0.txt)
16//
17
18#if defined( __ia64__ ) && defined( __INTEL_COMPILER )
19# include <ia64intrin.h>
20#endif
21
22namespace ndnboost
23{
24
25namespace detail
26{
27
28class atomic_count
29{
30public:
31
32 explicit atomic_count( long v ) : value_( v ) {}
33
34 long operator++()
35 {
36 return __sync_add_and_fetch( &value_, 1 );
37 }
38
39 long operator--()
40 {
41 return __sync_add_and_fetch( &value_, -1 );
42 }
43
44 operator long() const
45 {
46 return __sync_fetch_and_add( &value_, 0 );
47 }
48
49private:
50
51 atomic_count(atomic_count const &);
52 atomic_count & operator=(atomic_count const &);
53
54 mutable long value_;
55};
56
57} // namespace detail
58
59} // namespace ndnboost
60
61#endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED