1 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_PTHREADS_HPP_INCLUDED
\r
2 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_PTHREADS_HPP_INCLUDED
\r
5 // boost/detail/atomic_count_pthreads.hpp
\r
7 // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
\r
9 // Distributed under the Boost Software License, Version 1.0. (See
\r
10 // accompanying file LICENSE_1_0.txt or copy at
\r
11 // http://www.boost.org/LICENSE_1_0.txt)
\r
14 #include <pthread.h>
\r
17 // The generic pthread_mutex-based implementation sometimes leads to
\r
18 // inefficiencies. Example: a class with two atomic_count members
\r
19 // can get away with a single mutex.
\r
21 // Users can detect this situation by checking BOOST_AC_USE_PTHREADS.
\r
38 scoped_lock(pthread_mutex_t & m): m_(m)
\r
40 pthread_mutex_lock(&m_);
\r
45 pthread_mutex_unlock(&m_);
\r
50 pthread_mutex_t & m_;
\r
55 explicit atomic_count(long v): value_(v)
\r
57 pthread_mutex_init(&mutex_, 0);
\r
62 pthread_mutex_destroy(&mutex_);
\r
67 scoped_lock lock(mutex_);
\r
73 scoped_lock lock(mutex_);
\r
77 operator long() const
\r
79 scoped_lock lock(mutex_);
\r
85 atomic_count(atomic_count const &);
\r
86 atomic_count & operator=(atomic_count const &);
\r
88 mutable pthread_mutex_t mutex_;
\r
92 } // namespace detail
\r
94 } // namespace boost
\r
96 #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_PTHREADS_HPP_INCLUDED
\r