New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
spinlock_gcc_arm.hpp in vendors/XIOS/current/extern/boost/include/boost/smart_ptr/detail – NEMO

source: vendors/XIOS/current/extern/boost/include/boost/smart_ptr/detail/spinlock_gcc_arm.hpp @ 3428

Last change on this file since 3428 was 3428, checked in by rblod, 12 years ago

importing initial XIOS vendor drop

File size: 1.5 KB
Line 
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 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
14namespace boost
15{
16
17namespace detail
18{
19
20class spinlock
21{
22public:
23
24    int v_;
25
26public:
27
28    bool try_lock()
29    {
30        int r;
31
32        __asm__ __volatile__(
33            "swp %0, %1, [%2]":
34            "=&r"( r ): // outputs
35            "r"( 1 ), "r"( &v_ ): // inputs
36            "memory", "cc" );
37
38        return r == 0;
39    }
40
41    void lock()
42    {
43        for( unsigned k = 0; !try_lock(); ++k )
44        {
45            boost::detail::yield( k );
46        }
47    }
48
49    void unlock()
50    {
51        __asm__ __volatile__( "" ::: "memory" );
52        *const_cast< int volatile* >( &v_ ) = 0;
53    }
54
55public:
56
57    class scoped_lock
58    {
59    private:
60
61        spinlock & sp_;
62
63        scoped_lock( scoped_lock const & );
64        scoped_lock & operator=( scoped_lock const & );
65
66    public:
67
68        explicit scoped_lock( spinlock & sp ): sp_( sp )
69        {
70            sp.lock();
71        }
72
73        ~scoped_lock()
74        {
75            sp_.unlock();
76        }
77    };
78};
79
80} // namespace detail
81} // namespace boost
82
83#define BOOST_DETAIL_SPINLOCK_INIT {0}
84
85#endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.