spinlock_nt.hpp added, Cygwin fixes.

[SVN r44055]
This commit is contained in:
Peter Dimov
2008-04-05 15:06:31 +00:00
parent 515be965bd
commit acb6824ef7
6 changed files with 120 additions and 18 deletions

View File

@ -32,10 +32,12 @@
#if defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
# 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>
#elif defined(BOOST_HAS_PTHREADS)
# include <boost/detail/spinlock_pt.hpp>
#elif !defined(BOOST_HAS_THREADS)
# include <boost/detail/spinlock_nt.hpp>
#else
# error Unrecognized threading platform
#endif

View 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

View File

@ -25,7 +25,7 @@
#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 )
# include <windows.h>
@ -33,6 +33,7 @@
#if defined(_MSC_VER) && _MSC_VER >= 1310
extern "C" void _mm_pause();
# pragma intrinsic( _mm_pause )
#endif
namespace boost

View File

@ -39,5 +39,6 @@ import testing ;
[ run esft_constructor_test.cpp ]
[ run yield_k_test.cpp ]
[ run spinlock_test.cpp ]
[ run spinlock_try_test.cpp ]
;
}

View File

@ -9,7 +9,6 @@
//
#include <boost/detail/spinlock.hpp>
#include <boost/detail/lightweight_test.hpp>
// Sanity check only
@ -18,29 +17,15 @@ 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();
return 0;
}

View 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();
}