diff --git a/include/boost/detail/spinlock.hpp b/include/boost/detail/spinlock.hpp index 605fccb..4fbf553 100644 --- a/include/boost/detail/spinlock.hpp +++ b/include/boost/detail/spinlock.hpp @@ -32,10 +32,12 @@ #if defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 ) # include -#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) # include #elif defined(BOOST_HAS_PTHREADS) # include +#elif !defined(BOOST_HAS_THREADS) +# include #else # error Unrecognized threading platform #endif diff --git a/include/boost/detail/spinlock_nt.hpp b/include/boost/detail/spinlock_nt.hpp new file mode 100644 index 0000000..106c7e7 --- /dev/null +++ b/include/boost/detail/spinlock_nt.hpp @@ -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 diff --git a/include/boost/detail/yield_k.hpp b/include/boost/detail/yield_k.hpp index e3f6917..fea98d4 100644 --- a/include/boost/detail/yield_k.hpp +++ b/include/boost/detail/yield_k.hpp @@ -25,7 +25,7 @@ #include -#if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) +#if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ ) #if defined( BOOST_USE_WINDOWS_H ) # include @@ -33,6 +33,7 @@ #if defined(_MSC_VER) && _MSC_VER >= 1310 extern "C" void _mm_pause(); +# pragma intrinsic( _mm_pause ) #endif namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d3b92a3..d77a4b3 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 ] ; } diff --git a/test/spinlock_test.cpp b/test/spinlock_test.cpp index faec048..0820b96 100644 --- a/test/spinlock_test.cpp +++ b/test/spinlock_test.cpp @@ -9,7 +9,6 @@ // #include -#include // 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; } diff --git a/test/spinlock_try_test.cpp b/test/spinlock_try_test.cpp new file mode 100644 index 0000000..59e3390 --- /dev/null +++ b/test/spinlock_try_test.cpp @@ -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 +#include + +// 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(); +}