From 71c9165119b688e7e1b5e8344f5f35c55e9457a2 Mon Sep 17 00:00:00 2001 From: Steve Gates Date: Tue, 10 Jun 2014 22:07:51 -0700 Subject: [PATCH 1/3] Replacing banned APIs Sleep and InitializeCriticalSection for Windows store and phone. --- include/boost/smart_ptr/detail/lwm_win32_cs.hpp | 9 +++++++++ include/boost/smart_ptr/detail/yield_k.hpp | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/boost/smart_ptr/detail/lwm_win32_cs.hpp b/include/boost/smart_ptr/detail/lwm_win32_cs.hpp index 00477e4..9dfc2c6 100644 --- a/include/boost/smart_ptr/detail/lwm_win32_cs.hpp +++ b/include/boost/smart_ptr/detail/lwm_win32_cs.hpp @@ -11,6 +11,7 @@ // boost/detail/lwm_win32_cs.hpp // // Copyright (c) 2002, 2003 Peter Dimov +// Copyright (c) Microsoft Corporation 2014 // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -43,7 +44,11 @@ struct critical_section #endif }; +#if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(critical_section *); +#else +extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSectionEx(critical_section *, unsigned long, unsigned long); +#endif extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(critical_section *); extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(critical_section *); extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(critical_section *); @@ -67,7 +72,11 @@ public: lightweight_mutex() { +#if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA InitializeCriticalSection(&cs_); +#else + InitializeCriticalSectionEx(&cs_, 4000, 0); +#endif } ~lightweight_mutex() diff --git a/include/boost/smart_ptr/detail/yield_k.hpp b/include/boost/smart_ptr/detail/yield_k.hpp index 14af524..686780a 100644 --- a/include/boost/smart_ptr/detail/yield_k.hpp +++ b/include/boost/smart_ptr/detail/yield_k.hpp @@ -11,6 +11,7 @@ // yield_k.hpp // // Copyright (c) 2008 Peter Dimov +// Copyright (c) Microsoft Corporation 2014 // // void yield( unsigned k ); // @@ -24,6 +25,11 @@ // #include +#include + +#if BOOST_PLAT_WINDOWS_RUNTIME +#include +#endif // BOOST_SMT_PAUSE @@ -53,7 +59,7 @@ namespace boost namespace detail { -#if !defined( BOOST_USE_WINDOWS_H ) +#if !defined( BOOST_USE_WINDOWS_H ) && BOOST_PLAT_WINDOWS_DESKTOP extern "C" void __stdcall Sleep( unsigned long ms ); #endif @@ -68,6 +74,7 @@ inline void yield( unsigned k ) BOOST_SMT_PAUSE } #endif +#if BOOST_PLAT_WINDOWS_DESKTOP else if( k < 32 ) { Sleep( 0 ); @@ -76,6 +83,13 @@ inline void yield( unsigned k ) { Sleep( 1 ); } +#else + else + { + // Sleep isn't supported on the Windows Runtime. + std::this_thread::yield(); + } +#endif } } // namespace detail From 07e222217b2a13c31c4ce0145d571d61c8fea8a5 Mon Sep 17 00:00:00 2001 From: Steve Gates Date: Wed, 11 Jun 2014 11:33:03 -0700 Subject: [PATCH 2/3] Updating to use BOOST_PLAT_WINDOWS_RUNTIME based on review feedback. --- include/boost/smart_ptr/detail/lwm_win32_cs.hpp | 12 ++++++------ include/boost/smart_ptr/detail/yield_k.hpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/boost/smart_ptr/detail/lwm_win32_cs.hpp b/include/boost/smart_ptr/detail/lwm_win32_cs.hpp index 9dfc2c6..9de2d65 100644 --- a/include/boost/smart_ptr/detail/lwm_win32_cs.hpp +++ b/include/boost/smart_ptr/detail/lwm_win32_cs.hpp @@ -44,10 +44,10 @@ struct critical_section #endif }; -#if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA -extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(critical_section *); -#else +#if BOOST_PLAT_WINDOWS_RUNTIME extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSectionEx(critical_section *, unsigned long, unsigned long); +#else +extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(critical_section *); #endif extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(critical_section *); extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(critical_section *); @@ -72,10 +72,10 @@ public: lightweight_mutex() { -#if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA - InitializeCriticalSection(&cs_); -#else +#if BOOST_PLAT_WINDOWS_RUNTIME InitializeCriticalSectionEx(&cs_, 4000, 0); +#else + InitializeCriticalSection(&cs_); #endif } diff --git a/include/boost/smart_ptr/detail/yield_k.hpp b/include/boost/smart_ptr/detail/yield_k.hpp index 686780a..9f4496b 100644 --- a/include/boost/smart_ptr/detail/yield_k.hpp +++ b/include/boost/smart_ptr/detail/yield_k.hpp @@ -59,7 +59,7 @@ namespace boost namespace detail { -#if !defined( BOOST_USE_WINDOWS_H ) && BOOST_PLAT_WINDOWS_DESKTOP +#if !defined( BOOST_USE_WINDOWS_H ) && !BOOST_PLAT_WINDOWS_RUNTIME extern "C" void __stdcall Sleep( unsigned long ms ); #endif @@ -74,7 +74,7 @@ inline void yield( unsigned k ) BOOST_SMT_PAUSE } #endif -#if BOOST_PLAT_WINDOWS_DESKTOP +#if !BOOST_PLAT_WINDOWS_RUNTIME else if( k < 32 ) { Sleep( 0 ); From 1a74757cfa92b90525cf890d00a67859a91ba80b Mon Sep 17 00:00:00 2001 From: Steve Gates Date: Wed, 11 Jun 2014 11:44:25 -0700 Subject: [PATCH 3/3] Adding missing include for boost\predef.h. --- include/boost/smart_ptr/detail/lwm_win32_cs.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/smart_ptr/detail/lwm_win32_cs.hpp b/include/boost/smart_ptr/detail/lwm_win32_cs.hpp index 9de2d65..11edd73 100644 --- a/include/boost/smart_ptr/detail/lwm_win32_cs.hpp +++ b/include/boost/smart_ptr/detail/lwm_win32_cs.hpp @@ -18,6 +18,8 @@ // http://www.boost.org/LICENSE_1_0.txt) // +#include + #ifdef BOOST_USE_WINDOWS_H # include #endif