diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:12:59 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:12:59 +0900 |
commit | b8cf34c691623e4ec329053cbbf68522a855882d (patch) | |
tree | 34da08632a99677f6b79ecb65e5b655a5b69a67f /boost/thread/win32/thread_primitives.hpp | |
parent | 3fdc3e5ee96dca5b11d1694975a65200787eab86 (diff) | |
download | boost-b8cf34c691623e4ec329053cbbf68522a855882d.tar.gz boost-b8cf34c691623e4ec329053cbbf68522a855882d.tar.bz2 boost-b8cf34c691623e4ec329053cbbf68522a855882d.zip |
Imported Upstream version 1.67.0upstream/1.67.0
Diffstat (limited to 'boost/thread/win32/thread_primitives.hpp')
-rw-r--r-- | boost/thread/win32/thread_primitives.hpp | 180 |
1 files changed, 45 insertions, 135 deletions
diff --git a/boost/thread/win32/thread_primitives.hpp b/boost/thread/win32/thread_primitives.hpp index f93cc2438e..5e378f7664 100644 --- a/boost/thread/win32/thread_primitives.hpp +++ b/boost/thread/win32/thread_primitives.hpp @@ -16,23 +16,22 @@ #include <boost/assert.hpp> #include <boost/thread/exceptions.hpp> #include <boost/detail/interlocked.hpp> -#include <boost/detail/winapi/config.hpp> - -#include <boost/detail/winapi/semaphore.hpp> -#include <boost/detail/winapi/dll.hpp> -#include <boost/detail/winapi/system.hpp> -#include <boost/detail/winapi/time.hpp> -#include <boost/detail/winapi/event.hpp> -#include <boost/detail/winapi/thread.hpp> -#include <boost/detail/winapi/get_current_thread.hpp> -#include <boost/detail/winapi/get_current_thread_id.hpp> -#include <boost/detail/winapi/get_current_process.hpp> -#include <boost/detail/winapi/get_current_process_id.hpp> -#include <boost/detail/winapi/wait.hpp> -#include <boost/detail/winapi/handles.hpp> -#include <boost/detail/winapi/access_rights.hpp> - -//#include <boost/detail/winapi/synchronization.hpp> + +#include <boost/winapi/config.hpp> +#include <boost/winapi/basic_types.hpp> +#include <boost/winapi/semaphore.hpp> +#include <boost/winapi/system.hpp> +#include <boost/winapi/event.hpp> +#include <boost/winapi/thread.hpp> +#include <boost/winapi/get_current_thread.hpp> +#include <boost/winapi/get_current_thread_id.hpp> +#include <boost/winapi/get_current_process.hpp> +#include <boost/winapi/get_current_process_id.hpp> +#include <boost/winapi/wait.hpp> +#include <boost/winapi/handles.hpp> +#include <boost/winapi/access_rights.hpp> + +//#include <boost/winapi/synchronization.hpp> #include <boost/thread/win32/interlocked_read.hpp> #include <algorithm> @@ -46,20 +45,19 @@ namespace boost { namespace win32 { - typedef ::boost::detail::winapi::HANDLE_ handle; - typedef ::boost::detail::winapi::SYSTEM_INFO_ system_info; - typedef unsigned __int64 ticks_type; - typedef ::boost::detail::winapi::FARPROC_ farproc_t; - unsigned const infinite=::boost::detail::winapi::INFINITE_; - unsigned const timeout=::boost::detail::winapi::WAIT_TIMEOUT_; - handle const invalid_handle_value=::boost::detail::winapi::INVALID_HANDLE_VALUE_; - unsigned const event_modify_state=::boost::detail::winapi::EVENT_MODIFY_STATE_; - unsigned const synchronize=::boost::detail::winapi::SYNCHRONIZE_; - unsigned const wait_abandoned=::boost::detail::winapi::WAIT_ABANDONED_; + typedef ::boost::winapi::HANDLE_ handle; + typedef ::boost::winapi::SYSTEM_INFO_ system_info; + typedef ::boost::winapi::ULONGLONG_ ticks_type; + unsigned const infinite=::boost::winapi::INFINITE_; + unsigned const timeout=::boost::winapi::WAIT_TIMEOUT_; + handle const invalid_handle_value=::boost::winapi::INVALID_HANDLE_VALUE_; + unsigned const event_modify_state=::boost::winapi::EVENT_MODIFY_STATE_; + unsigned const synchronize=::boost::winapi::SYNCHRONIZE_; + unsigned const wait_abandoned=::boost::winapi::WAIT_ABANDONED_; unsigned const create_event_initial_set = 0x00000002; unsigned const create_event_manual_reset = 0x00000001; - unsigned const event_all_access = ::boost::detail::winapi::EVENT_ALL_ACCESS_; - unsigned const semaphore_all_access = boost::detail::winapi::SEMAPHORE_ALL_ACCESS_; + unsigned const event_all_access = ::boost::winapi::EVENT_ALL_ACCESS_; + unsigned const semaphore_all_access = boost::winapi::SEMAPHORE_ALL_ACCESS_; } } } @@ -72,96 +70,8 @@ namespace boost { namespace win32 { - namespace detail { typedef ticks_type (__stdcall *gettickcount64_t)(); } -#if !BOOST_PLAT_WINDOWS_RUNTIME - extern "C" - { -#ifdef _MSC_VER - long _InterlockedCompareExchange(long volatile *, long, long); -#pragma intrinsic(_InterlockedCompareExchange) -#elif defined(__MINGW64_VERSION_MAJOR) - long _InterlockedCompareExchange(long volatile *, long, long); -#else - // Mingw doesn't provide intrinsics -#define _InterlockedCompareExchange InterlockedCompareExchange -#endif - } - // Borrowed from https://stackoverflow.com/questions/8211820/userland-interrupt-timer-access-such-as-via-kequeryinterrupttime-or-similar - inline ticks_type __stdcall GetTickCount64emulation() - { - static long count = -1l; - unsigned long previous_count, current_tick32, previous_count_zone, current_tick32_zone; - ticks_type current_tick64; - - previous_count = (unsigned long) boost::detail::interlocked_read_acquire(&count); - current_tick32 = ::boost::detail::winapi::GetTickCount(); - - if(previous_count == (unsigned long)-1l) - { - // count has never been written - unsigned long initial_count; - initial_count = current_tick32 >> 28; - previous_count = (unsigned long) _InterlockedCompareExchange(&count, (long)initial_count, -1l); - - current_tick64 = initial_count; - current_tick64 <<= 28; - current_tick64 += current_tick32 & 0x0FFFFFFF; - return current_tick64; - } - - previous_count_zone = previous_count & 15; - current_tick32_zone = current_tick32 >> 28; - - if(current_tick32_zone == previous_count_zone) - { - // The top four bits of the 32-bit tick count haven't changed since count was last written. - current_tick64 = previous_count; - current_tick64 <<= 28; - current_tick64 += current_tick32 & 0x0FFFFFFF; - return current_tick64; - } - - if(current_tick32_zone == previous_count_zone + 1 || (current_tick32_zone == 0 && previous_count_zone == 15)) - { - // The top four bits of the 32-bit tick count have been incremented since count was last written. - unsigned long new_count = previous_count + 1; - _InterlockedCompareExchange(&count, (long)new_count, (long)previous_count); - current_tick64 = new_count; - current_tick64 <<= 28; - current_tick64 += current_tick32 & 0x0FFFFFFF; - return current_tick64; - } - - // Oops, we weren't called often enough, we're stuck - return 0xFFFFFFFF; - } -#else -#endif - inline detail::gettickcount64_t GetTickCount64_() - { - static detail::gettickcount64_t gettickcount64impl; - if(gettickcount64impl) - return gettickcount64impl; - - // GetTickCount and GetModuleHandle are not allowed in the Windows Runtime, - // and kernel32 isn't used in Windows Phone. -#if BOOST_PLAT_WINDOWS_RUNTIME - gettickcount64impl = &::boost::detail::winapi::GetTickCount64; -#else - farproc_t addr=GetProcAddress( -#if !defined(BOOST_NO_ANSI_APIS) - ::boost::detail::winapi::GetModuleHandleA("KERNEL32.DLL"), -#else - ::boost::detail::winapi::GetModuleHandleW(L"KERNEL32.DLL"), -#endif - "GetTickCount64"); - if(addr) - gettickcount64impl=(detail::gettickcount64_t) addr; - else - gettickcount64impl=&GetTickCount64emulation; -#endif - return gettickcount64impl; - } + namespace detail { typedef ticks_type (WINAPI *gettickcount64_t)(); } + extern BOOST_THREAD_DECL boost::detail::win32::detail::gettickcount64_t gettickcount64; enum event_type { @@ -185,11 +95,11 @@ namespace boost initial_event_state state) { #if !defined(BOOST_NO_ANSI_APIS) - handle const res = ::boost::detail::winapi::CreateEventA(0, type, state, mutex_name); + handle const res = ::boost::winapi::CreateEventA(0, type, state, mutex_name); #elif BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA - handle const res = ::boost::detail::winapi::CreateEventW(0, type, state, mutex_name); + handle const res = ::boost::winapi::CreateEventW(0, type, state, mutex_name); #else - handle const res = ::boost::detail::winapi::CreateEventExW( + handle const res = ::boost::winapi::CreateEventExW( 0, mutex_name, type ? create_event_manual_reset : 0 | state ? create_event_initial_set : 0, @@ -211,12 +121,12 @@ namespace boost inline handle create_anonymous_semaphore_nothrow(long initial_count,long max_count) { #if !defined(BOOST_NO_ANSI_APIS) - handle const res=::boost::detail::winapi::CreateSemaphoreA(0,initial_count,max_count,0); + handle const res=::boost::winapi::CreateSemaphoreA(0,initial_count,max_count,0); #else #if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA - handle const res=::boost::detail::winapi::CreateSemaphoreEx(0,initial_count,max_count,0,0); + handle const res=::boost::winapi::CreateSemaphoreEx(0,initial_count,max_count,0,0); #else - handle const res=::boost::detail::winapi::CreateSemaphoreExW(0,initial_count,max_count,0,0,semaphore_all_access); + handle const res=::boost::winapi::CreateSemaphoreExW(0,initial_count,max_count,0,0,semaphore_all_access); #endif #endif return res; @@ -234,10 +144,10 @@ namespace boost inline handle duplicate_handle(handle source) { - handle const current_process=::boost::detail::winapi::GetCurrentProcess(); + handle const current_process=::boost::winapi::GetCurrentProcess(); long const same_access_flag=2; handle new_handle=0; - bool const success=::boost::detail::winapi::DuplicateHandle(current_process,source,current_process,&new_handle,0,false,same_access_flag)!=0; + bool const success=::boost::winapi::DuplicateHandle(current_process,source,current_process,&new_handle,0,false,same_access_flag)!=0; if(!success) { boost::throw_exception(thread_resource_error()); @@ -247,15 +157,15 @@ namespace boost inline void release_semaphore(handle semaphore,long count) { - BOOST_VERIFY(::boost::detail::winapi::ReleaseSemaphore(semaphore,count,0)!=0); + BOOST_VERIFY(::boost::winapi::ReleaseSemaphore(semaphore,count,0)!=0); } inline void get_system_info(system_info *info) { #if BOOST_PLAT_WINDOWS_RUNTIME - ::boost::detail::winapi::GetNativeSystemInfo(info); + ::boost::winapi::GetNativeSystemInfo(info); #else - ::boost::detail::winapi::GetSystemInfo(info); + ::boost::winapi::GetSystemInfo(info); #endif } @@ -266,15 +176,15 @@ namespace boost #if BOOST_PLAT_WINDOWS_RUNTIME std::this_thread::yield(); #else - ::boost::detail::winapi::Sleep(0); + ::boost::winapi::Sleep(0); #endif } else { #if BOOST_PLAT_WINDOWS_RUNTIME - ::boost::detail::winapi::WaitForSingleObjectEx(::boost::detail::winapi::GetCurrentThread(), milliseconds, 0); + ::boost::winapi::WaitForSingleObjectEx(::boost::winapi::GetCurrentThread(), milliseconds, 0); #else - ::boost::detail::winapi::Sleep(milliseconds); + ::boost::winapi::Sleep(milliseconds); #endif } } @@ -290,7 +200,7 @@ namespace boost { if (m_completionHandle != ::boost::detail::win32::invalid_handle_value) { - ::boost::detail::winapi::CloseHandle(m_completionHandle); + ::boost::winapi::CloseHandle(m_completionHandle); } } @@ -318,7 +228,7 @@ namespace boost { if(handle_to_manage && handle_to_manage!=invalid_handle_value) { - BOOST_VERIFY(::boost::detail::winapi::CloseHandle(handle_to_manage)); + BOOST_VERIFY(::boost::winapi::CloseHandle(handle_to_manage)); } } |