]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/smart_ptr/detail/spinlock_gcc_arm.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
7d7c786985279c076ade146aa78d32ca456833ed
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / smart_ptr / detail / spinlock_gcc_arm.hpp
1 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED\r
2 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED\r
3 \r
4 //\r
5 //  Copyright (c) 2008 Peter Dimov\r
6 //\r
7 //  Distributed under the Boost Software License, Version 1.0.\r
8 //  See accompanying file LICENSE_1_0.txt or copy at\r
9 //  http://www.boost.org/LICENSE_1_0.txt)\r
10 //\r
11 \r
12 #include <boost/smart_ptr/detail/yield_k.hpp>\r
13 \r
14 namespace boost\r
15 {\r
16 \r
17 namespace detail\r
18 {\r
19 \r
20 class spinlock\r
21 {\r
22 public:\r
23 \r
24     int v_;\r
25 \r
26 public:\r
27 \r
28     bool try_lock()\r
29     {\r
30         int r;\r
31 \r
32         __asm__ __volatile__(\r
33             "swp %0, %1, [%2]":\r
34             "=&r"( r ): // outputs\r
35             "r"( 1 ), "r"( &v_ ): // inputs\r
36             "memory", "cc" );\r
37 \r
38         return r == 0;\r
39     }\r
40 \r
41     void lock()\r
42     {\r
43         for( unsigned k = 0; !try_lock(); ++k )\r
44         {\r
45             boost::detail::yield( k );\r
46         }\r
47     }\r
48 \r
49     void unlock()\r
50     {\r
51         __asm__ __volatile__( "" ::: "memory" );\r
52         *const_cast< int volatile* >( &v_ ) = 0;\r
53     }\r
54 \r
55 public:\r
56 \r
57     class scoped_lock\r
58     {\r
59     private:\r
60 \r
61         spinlock & sp_;\r
62 \r
63         scoped_lock( scoped_lock const & );\r
64         scoped_lock & operator=( scoped_lock const & );\r
65 \r
66     public:\r
67 \r
68         explicit scoped_lock( spinlock & sp ): sp_( sp )\r
69         {\r
70             sp.lock();\r
71         }\r
72 \r
73         ~scoped_lock()\r
74         {\r
75             sp_.unlock();\r
76         }\r
77     };\r
78 };\r
79 \r
80 } // namespace detail\r
81 } // namespace boost\r
82 \r
83 #define BOOST_DETAIL_SPINLOCK_INIT {0}\r
84 \r
85 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED\r