Debian Codegraph @

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

raw
1 #ifndef vcl_atomic_count_gcc_h_
2 #define vcl_atomic_count_gcc_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_gcc.hpp
13 //
14 // vcl_atomic_count for GNU libstdc++ v3
15 //
16 // http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html
17 //
18 // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
19 // Copyright (c) 2002 Lars Gullik Bjonnes <[email protected]>
20 // Copyright 2003-2005 Peter Dimov
21 //
22 // Distributed under the Boost Software License, Version 1.0. (See
23 // accompanying file LICENSE_1_0.txt or copy at
24 // http://www.boost.org/LICENSE_1_0.txt)
25 //
26
27 #include <bits/atomicity.h>
28
29
30 #if defined(__GLIBCXX__) // g++ 3.4+
31
32 using __gnu_cxx::__atomic_add;
33 using __gnu_cxx::__exchange_and_add;
34
35 #endif
36
37 class vcl_atomic_count
38 {
39 public:
40
41 explicit vcl_atomic_count(long v) : value_(v) {}
42
43 void operator++()
44 {
45 __atomic_add(&value_, 1);
46 }
47
48 long operator--()
49 {
50 return __exchange_and_add(&value_, -1) - 1;
51 }
52
53 operator long() const
54 {
55 return __exchange_and_add(&value_, 0);
56 }
57
58 private:
59
60 vcl_atomic_count(vcl_atomic_count const &);
61 vcl_atomic_count & operator=(vcl_atomic_count const &);
62
63 mutable _Atomic_word value_;
64 };
65
66 #endif // #ifndef vcl_atomic_count_gcc_h_