Pack required boost code together.
[xy_vsfilter.git] / src / thirdparty / boost_1_47_0 / boost / smart_ptr / detail / spinlock_nt.hpp
blob920d67e1621b3b121afeff0cd0554486dd79d976
1 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
11 // Copyright (c) 2008 Peter Dimov
13 // Distributed under the Boost Software License, Version 1.0.
14 // See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
18 #include <boost/assert.hpp>
20 namespace boost
23 namespace detail
26 class spinlock
28 public:
30 bool locked_;
32 public:
34 inline bool try_lock()
36 if( locked_ )
38 return false;
40 else
42 locked_ = true;
43 return true;
47 inline void lock()
49 BOOST_ASSERT( !locked_ );
50 locked_ = true;
53 inline void unlock()
55 BOOST_ASSERT( locked_ );
56 locked_ = false;
59 public:
61 class scoped_lock
63 private:
65 spinlock & sp_;
67 scoped_lock( scoped_lock const & );
68 scoped_lock & operator=( scoped_lock const & );
70 public:
72 explicit scoped_lock( spinlock & sp ): sp_( sp )
74 sp.lock();
77 ~scoped_lock()
79 sp_.unlock();
84 } // namespace detail
85 } // namespace boost
87 #define BOOST_DETAIL_SPINLOCK_INIT { false }
89 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED