forked from boostorg/smart_ptr
spinlock_gcc_arm.hpp added.
[SVN r44138]
This commit is contained in:
@ -30,7 +30,9 @@
|
|||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
#if defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
|
#if defined(__GNUC__) && defined( __arm__ )
|
||||||
|
# include <boost/detail/spinlock_gcc_arm.hpp>
|
||||||
|
#elif defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
|
||||||
# include <boost/detail/spinlock_sync.hpp>
|
# include <boost/detail/spinlock_sync.hpp>
|
||||||
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||||
# include <boost/detail/spinlock_w32.hpp>
|
# include <boost/detail/spinlock_w32.hpp>
|
||||||
|
85
include/boost/detail/spinlock_gcc_arm.hpp
Normal file
85
include/boost/detail/spinlock_gcc_arm.hpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#ifndef BOOST_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED
|
||||||
|
#define BOOST_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED
|
||||||
|
|
||||||
|
//
|
||||||
|
// Copyright (c) 2008 Peter Dimov
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <boost/detail/yield_k.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
class spinlock
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
int v_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
bool try_lock()
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"swp %0, %1, [%2]":
|
||||||
|
"=r"( r ): // outputs
|
||||||
|
"r"( 1 ), "r"( &v_ ): // inputs
|
||||||
|
"memory", "cc" );
|
||||||
|
|
||||||
|
return r == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lock()
|
||||||
|
{
|
||||||
|
for( unsigned k = 0; !try_lock(); ++k )
|
||||||
|
{
|
||||||
|
boost::detail::yield( k );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock()
|
||||||
|
{
|
||||||
|
__asm__ __volatile__( "" ::: "memory" );
|
||||||
|
*const_cast< int volatile* >( &v_ ) = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
class scoped_lock
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
spinlock & sp_;
|
||||||
|
|
||||||
|
scoped_lock( scoped_lock const & );
|
||||||
|
scoped_lock & operator=( scoped_lock const & );
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit scoped_lock( spinlock & sp ): sp_( sp )
|
||||||
|
{
|
||||||
|
sp.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
~scoped_lock()
|
||||||
|
{
|
||||||
|
sp_.unlock();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#define BOOST_DETAIL_SPINLOCK_INIT {0}
|
||||||
|
|
||||||
|
#endif // #ifndef BOOST_DETAIL_SPINLOCK_GCC_ARM_HPP_INCLUDED
|
Reference in New Issue
Block a user