forked from boostorg/smart_ptr
spinlock_nt.hpp added, Cygwin fixes.
[SVN r44055]
This commit is contained in:
@ -32,10 +32,12 @@
|
|||||||
|
|
||||||
#if defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
|
#if 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__)
|
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||||
# include <boost/detail/spinlock_w32.hpp>
|
# include <boost/detail/spinlock_w32.hpp>
|
||||||
#elif defined(BOOST_HAS_PTHREADS)
|
#elif defined(BOOST_HAS_PTHREADS)
|
||||||
# include <boost/detail/spinlock_pt.hpp>
|
# include <boost/detail/spinlock_pt.hpp>
|
||||||
|
#elif !defined(BOOST_HAS_THREADS)
|
||||||
|
# include <boost/detail/spinlock_nt.hpp>
|
||||||
#else
|
#else
|
||||||
# error Unrecognized threading platform
|
# error Unrecognized threading platform
|
||||||
#endif
|
#endif
|
||||||
|
67
include/boost/detail/spinlock_nt.hpp
Normal file
67
include/boost/detail/spinlock_nt.hpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#ifndef BOOST_DETAIL_SPINLOCK_NT_HPP_INCLUDED
|
||||||
|
#define BOOST_DETAIL_SPINLOCK_NT_HPP_INCLUDED
|
||||||
|
|
||||||
|
// MS compatible compilers support #pragma once
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
//
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
class spinlock
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
inline bool try_lock()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void lock()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void unlock()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
class scoped_lock
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
scoped_lock( scoped_lock const & );
|
||||||
|
scoped_lock & operator=( scoped_lock const & );
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit scoped_lock( spinlock & /*sp*/ )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~scoped_lock()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#define BOOST_DETAIL_SPINLOCK_INIT {}
|
||||||
|
|
||||||
|
#endif // #ifndef BOOST_DETAIL_SPINLOCK_NT_HPP_INCLUDED
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
#if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
|
#if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
|
||||||
|
|
||||||
#if defined( BOOST_USE_WINDOWS_H )
|
#if defined( BOOST_USE_WINDOWS_H )
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1310
|
#if defined(_MSC_VER) && _MSC_VER >= 1310
|
||||||
extern "C" void _mm_pause();
|
extern "C" void _mm_pause();
|
||||||
|
# pragma intrinsic( _mm_pause )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
|
@ -39,5 +39,6 @@ import testing ;
|
|||||||
[ run esft_constructor_test.cpp ]
|
[ run esft_constructor_test.cpp ]
|
||||||
[ run yield_k_test.cpp ]
|
[ run yield_k_test.cpp ]
|
||||||
[ run spinlock_test.cpp ]
|
[ run spinlock_test.cpp ]
|
||||||
|
[ run spinlock_try_test.cpp ]
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <boost/detail/spinlock.hpp>
|
#include <boost/detail/spinlock.hpp>
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
|
||||||
|
|
||||||
// Sanity check only
|
// Sanity check only
|
||||||
|
|
||||||
@ -18,29 +17,15 @@ static boost::detail::spinlock sp2 = BOOST_DETAIL_SPINLOCK_INIT;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
BOOST_TEST( sp.try_lock() );
|
|
||||||
BOOST_TEST( !sp.try_lock() );
|
|
||||||
BOOST_TEST( sp2.try_lock() );
|
|
||||||
BOOST_TEST( !sp.try_lock() );
|
|
||||||
BOOST_TEST( !sp2.try_lock() );
|
|
||||||
sp.unlock();
|
|
||||||
sp2.unlock();
|
|
||||||
|
|
||||||
sp.lock();
|
sp.lock();
|
||||||
BOOST_TEST( !sp.try_lock() );
|
|
||||||
sp2.lock();
|
sp2.lock();
|
||||||
BOOST_TEST( !sp.try_lock() );
|
|
||||||
BOOST_TEST( !sp2.try_lock() );
|
|
||||||
sp.unlock();
|
sp.unlock();
|
||||||
sp2.unlock();
|
sp2.unlock();
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::detail::spinlock::scoped_lock lock( sp );
|
boost::detail::spinlock::scoped_lock lock( sp );
|
||||||
BOOST_TEST( !sp.try_lock() );
|
|
||||||
boost::detail::spinlock::scoped_lock lock2( sp2 );
|
boost::detail::spinlock::scoped_lock lock2( sp2 );
|
||||||
BOOST_TEST( !sp.try_lock() );
|
|
||||||
BOOST_TEST( !sp2.try_lock() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return 0;
|
||||||
}
|
}
|
||||||
|
46
test/spinlock_try_test.cpp
Normal file
46
test/spinlock_try_test.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// spinlock_try_test.cpp
|
||||||
|
//
|
||||||
|
// Copyright 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/spinlock.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
// Sanity check only
|
||||||
|
|
||||||
|
static boost::detail::spinlock sp = BOOST_DETAIL_SPINLOCK_INIT;
|
||||||
|
static boost::detail::spinlock sp2 = BOOST_DETAIL_SPINLOCK_INIT;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_TEST( sp.try_lock() );
|
||||||
|
BOOST_TEST( !sp.try_lock() );
|
||||||
|
BOOST_TEST( sp2.try_lock() );
|
||||||
|
BOOST_TEST( !sp.try_lock() );
|
||||||
|
BOOST_TEST( !sp2.try_lock() );
|
||||||
|
sp.unlock();
|
||||||
|
sp2.unlock();
|
||||||
|
|
||||||
|
sp.lock();
|
||||||
|
BOOST_TEST( !sp.try_lock() );
|
||||||
|
sp2.lock();
|
||||||
|
BOOST_TEST( !sp.try_lock() );
|
||||||
|
BOOST_TEST( !sp2.try_lock() );
|
||||||
|
sp.unlock();
|
||||||
|
sp2.unlock();
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::detail::spinlock::scoped_lock lock( sp );
|
||||||
|
BOOST_TEST( !sp.try_lock() );
|
||||||
|
boost::detail::spinlock::scoped_lock lock2( sp2 );
|
||||||
|
BOOST_TEST( !sp.try_lock() );
|
||||||
|
BOOST_TEST( !sp2.try_lock() );
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user