]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/atomic_count_linux.hpp
major boost update
[lyx.git] / boost / boost / detail / atomic_count_linux.hpp
1 #ifndef BOOST_DETAIL_ATOMIC_COUNT_LINUX_HPP_INCLUDED
2 #define BOOST_DETAIL_ATOMIC_COUNT_LINUX_HPP_INCLUDED
3
4 //
5 //  boost/detail/atomic_count_linux.hpp
6 //
7 //  Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
8 //
9 //  Permission to copy, use, modify, sell and distribute this software
10 //  is granted provided this copyright notice appears in all copies.
11 //  This software is provided "as is" without express or implied
12 //  warranty, and with no claim as to its suitability for any purpose.
13 //
14
15 //
16 //  This implementation uses <asm/atomic.h>. This is a kernel header;
17 //  using kernel headers in a user program may cause a number of problems,
18 //  and not all flavors of Linux provide the atomic instructions.
19 //
20 //  This file is only provided because the performance of this implementation
21 //  is significantly higher than the pthreads version. Use at your own risk
22 //  (by defining BOOST_USE_ASM_ATOMIC_H.)
23 //
24
25 #include <asm/atomic.h>
26
27 namespace boost
28 {
29
30 namespace detail
31 {
32
33 class atomic_count
34 {
35 public:
36
37     explicit atomic_count(long v)
38     {
39         atomic_t init = ATOMIC_INIT(v);
40         value_ = init;
41     }
42
43     void operator++()
44     {
45         atomic_inc(&value_);
46     }
47
48     long operator--()
49     {
50         return !atomic_dec_and_test(&value_);
51     }
52
53     operator long() const
54     {
55         return atomic_read(&value_);
56     }
57
58 private:
59
60     atomic_count(atomic_count const &);
61     atomic_count & operator=(atomic_count const &);
62
63     atomic_t value_;
64 };
65
66 } // namespace detail
67
68 } // namespace boost
69
70 #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_LINUX_HPP_INCLUDED