Pack required boost code together.
[xy_vsfilter.git] / src / thirdparty / boost_1_47_0 / boost / smart_ptr / detail / spinlock_gcc_arm.hpp
blob7d7c786985279c076ade146aa78d32ca456833ed
1 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED
4 //
5 // Copyright (c) 2008 Peter Dimov
6 //
7 // Distributed under the Boost Software License, Version 1.0.
8 // See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
12 #include <boost/smart_ptr/detail/yield_k.hpp>
14 namespace boost
17 namespace detail
20 class spinlock
22 public:
24 int v_;
26 public:
28 bool try_lock()
30 int r;
32 __asm__ __volatile__(
33 "swp %0, %1, [%2]":
34 "=&r"( r ): // outputs
35 "r"( 1 ), "r"( &v_ ): // inputs
36 "memory", "cc" );
38 return r == 0;
41 void lock()
43 for( unsigned k = 0; !try_lock(); ++k )
45 boost::detail::yield( k );
49 void unlock()
51 __asm__ __volatile__( "" ::: "memory" );
52 *const_cast< int volatile* >( &v_ ) = 0;
55 public:
57 class scoped_lock
59 private:
61 spinlock & sp_;
63 scoped_lock( scoped_lock const & );
64 scoped_lock & operator=( scoped_lock const & );
66 public:
68 explicit scoped_lock( spinlock & sp ): sp_( sp )
70 sp.lock();
73 ~scoped_lock()
75 sp_.unlock();
80 } // namespace detail
81 } // namespace boost
83 #define BOOST_DETAIL_SPINLOCK_INIT {0}
85 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED