]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/smart_ptr/detail/spinlock_nt.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / smart_ptr / detail / spinlock_nt.hpp
1 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED
3
4 // MS compatible compilers support #pragma once
5
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
9
10 //
11 // Copyright (c) 2008 Peter Dimov
12 //
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)
16 //
17
18 #include <boost/assert.hpp>
19
20 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
21
22 #include <boost/config/pragma_message.hpp>
23 BOOST_PRAGMA_MESSAGE("Using single-threaded spinlock emulation")
24
25 #endif
26
27 namespace boost
28 {
29
30 namespace detail
31 {
32
33 class spinlock
34 {
35 public:
36
37 bool locked_;
38
39 public:
40
41 inline bool try_lock()
42 {
43 if( locked_ )
44 {
45 return false;
46 }
47 else
48 {
49 locked_ = true;
50 return true;
51 }
52 }
53
54 inline void lock()
55 {
56 BOOST_ASSERT( !locked_ );
57 locked_ = true;
58 }
59
60 inline void unlock()
61 {
62 BOOST_ASSERT( locked_ );
63 locked_ = false;
64 }
65
66 public:
67
68 class scoped_lock
69 {
70 private:
71
72 spinlock & sp_;
73
74 scoped_lock( scoped_lock const & );
75 scoped_lock & operator=( scoped_lock const & );
76
77 public:
78
79 explicit scoped_lock( spinlock & sp ): sp_( sp )
80 {
81 sp.lock();
82 }
83
84 ~scoped_lock()
85 {
86 sp_.unlock();
87 }
88 };
89 };
90
91 } // namespace detail
92 } // namespace boost
93
94 #define BOOST_DETAIL_SPINLOCK_INIT { false }
95
96 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED