]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/boost/boost/smart_ptr/detail/spinlock_gcc_arm.hpp
Add subset of boost library headers needed for compilation on PowerPC
[eurobot/public.git] / src / boost / boost / smart_ptr / detail / spinlock_gcc_arm.hpp
1 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED
3
4 //
5 //  Copyright (c) 2008, 2011 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)
10 //
11
12 #include <boost/smart_ptr/detail/yield_k.hpp>
13
14 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
15
16 # define BOOST_SP_ARM_BARRIER "dmb"
17
18 #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__)
19
20 # define BOOST_SP_ARM_BARRIER "mcr p15, 0, r0, c7, c10, 5"
21
22 #else
23
24 # define BOOST_SP_ARM_BARRIER ""
25
26 #endif
27
28 namespace boost
29 {
30
31 namespace detail
32 {
33
34 class spinlock
35 {
36 public:
37
38     int v_;
39
40 public:
41
42     bool try_lock()
43     {
44         int r;
45
46         __asm__ __volatile__(
47             "swp %0, %1, [%2]\n\t"
48                         BOOST_SP_ARM_BARRIER :
49             "=&r"( r ): // outputs
50             "r"( 1 ), "r"( &v_ ): // inputs
51             "memory", "cc" );
52
53         return r == 0;
54     }
55
56     void lock()
57     {
58         for( unsigned k = 0; !try_lock(); ++k )
59         {
60             boost::detail::yield( k );
61         }
62     }
63
64     void unlock()
65     {
66         __asm__ __volatile__( BOOST_SP_ARM_BARRIER ::: "memory" );
67         *const_cast< int volatile* >( &v_ ) = 0;
68     }
69
70 public:
71
72     class scoped_lock
73     {
74     private:
75
76         spinlock & sp_;
77
78         scoped_lock( scoped_lock const & );
79         scoped_lock & operator=( scoped_lock const & );
80
81     public:
82
83         explicit scoped_lock( spinlock & sp ): sp_( sp )
84         {
85             sp.lock();
86         }
87
88         ~scoped_lock()
89         {
90             sp_.unlock();
91         }
92     };
93 };
94
95 } // namespace detail
96 } // namespace boost
97
98 #define BOOST_DETAIL_SPINLOCK_INIT {0}
99
100 #undef BOOST_SP_ARM_BARRIER
101
102 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED