Debian Codegraph @

Modules/ThirdParty/VNL/src/vxl/vcl/internal/vcl_atomic_count_sync.h

raw
1 #ifndef vcl_atomic_count_sync_h_
2 #define vcl_atomic_count_sync_h_
3 //:
4 // \file
5 // \brief thread/SMP safe reference counter
6 // \author www.boost.org
7 // \verbatim
8 // Modifications
9 // Gehua Yang (DualAlign) - 28 Aug. 2008 - first port from Boost 1.36.0
10 // \endverbatim
11 //
12 // boost/detail/atomic_count_sync.hpp
13 //
14 // vcl_atomic_count for g++ 4.1+
15 //
16 // http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html
17 //
18 // Copyright 2007 Peter Dimov
19 //
20 // Distributed under the Boost Software License, Version 1.0. (See
21 // accompanying file LICENSE_1_0.txt or copy at
22 // http://www.boost.org/LICENSE_1_0.txt)
23 //
24
25 class vcl_atomic_count
26 {
27 public:
28
29 explicit vcl_atomic_count( long v ) : value_( v ) {}
30
31 void operator++()
32 {
33 __sync_add_and_fetch( &value_, 1 );
34 }
35
36 long operator--()
37 {
38 return __sync_add_and_fetch( &value_, -1 );
39 }
40
41 operator long() const
42 {
43 return __sync_fetch_and_add( &value_, 0 );
44 }
45
46 private:
47
48 vcl_atomic_count(vcl_atomic_count const &);
49 vcl_atomic_count & operator=(vcl_atomic_count const &);
50
51 mutable long value_;
52 };
53
54 #endif // #ifndef vcl_atomic_count_sync_h_