diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:11:01 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:11:01 +0900 |
commit | 3fdc3e5ee96dca5b11d1694975a65200787eab86 (patch) | |
tree | 5c1733853892b8397d67706fa453a9bd978d2102 /boost/thread/win32 | |
parent | 88e602c57797660ebe0f9e15dbd64c1ff16dead3 (diff) | |
download | boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.gz boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.bz2 boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.zip |
Imported Upstream version 1.66.0upstream/1.66.0
Diffstat (limited to 'boost/thread/win32')
-rw-r--r-- | boost/thread/win32/basic_recursive_mutex.hpp | 10 | ||||
-rw-r--r-- | boost/thread/win32/basic_timed_mutex.hpp | 14 | ||||
-rw-r--r-- | boost/thread/win32/condition_variable.hpp | 6 | ||||
-rw-r--r-- | boost/thread/win32/mfc_thread_init.hpp | 6 | ||||
-rw-r--r-- | boost/thread/win32/once.hpp | 50 | ||||
-rw-r--r-- | boost/thread/win32/shared_mutex.hpp | 30 | ||||
-rw-r--r-- | boost/thread/win32/thread_data.hpp | 2 | ||||
-rw-r--r-- | boost/thread/win32/thread_heap_alloc.hpp | 144 | ||||
-rw-r--r-- | boost/thread/win32/thread_primitives.hpp | 248 |
9 files changed, 207 insertions, 303 deletions
diff --git a/boost/thread/win32/basic_recursive_mutex.hpp b/boost/thread/win32/basic_recursive_mutex.hpp index cfdfa043a3..351f9acc71 100644 --- a/boost/thread/win32/basic_recursive_mutex.hpp +++ b/boost/thread/win32/basic_recursive_mutex.hpp @@ -44,13 +44,13 @@ namespace boost bool try_lock() BOOST_NOEXCEPT { - long const current_thread_id=win32::GetCurrentThreadId(); + long const current_thread_id=boost::detail::winapi::GetCurrentThreadId(); return try_recursive_lock(current_thread_id) || try_basic_lock(current_thread_id); } void lock() { - long const current_thread_id=win32::GetCurrentThreadId(); + long const current_thread_id=boost::detail::winapi::GetCurrentThreadId(); if(!try_recursive_lock(current_thread_id)) { mutex.lock(); @@ -61,7 +61,7 @@ namespace boost #if defined BOOST_THREAD_USES_DATETIME bool timed_lock(::boost::system_time const& target) { - long const current_thread_id=win32::GetCurrentThreadId(); + long const current_thread_id=boost::detail::winapi::GetCurrentThreadId(); return try_recursive_lock(current_thread_id) || try_timed_lock(current_thread_id,target); } template<typename Duration> @@ -75,13 +75,13 @@ namespace boost template <class Rep, class Period> bool try_lock_for(const chrono::duration<Rep, Period>& rel_time) { - long const current_thread_id=win32::GetCurrentThreadId(); + long const current_thread_id=boost::detail::winapi::GetCurrentThreadId(); return try_recursive_lock(current_thread_id) || try_timed_lock_for(current_thread_id,rel_time); } template <class Clock, class Duration> bool try_lock_until(const chrono::time_point<Clock, Duration>& t) { - long const current_thread_id=win32::GetCurrentThreadId(); + long const current_thread_id=boost::detail::winapi::GetCurrentThreadId(); return try_recursive_lock(current_thread_id) || try_timed_lock_until(current_thread_id,t); } #endif diff --git a/boost/thread/win32/basic_timed_mutex.hpp b/boost/thread/win32/basic_timed_mutex.hpp index d20c6589e6..b579d50530 100644 --- a/boost/thread/win32/basic_timed_mutex.hpp +++ b/boost/thread/win32/basic_timed_mutex.hpp @@ -55,7 +55,7 @@ namespace boost #endif if(old_event) { - win32::CloseHandle(old_event); + winapi::CloseHandle(old_event); } } @@ -81,9 +81,9 @@ namespace boost do { - unsigned const retval(win32::WaitForSingleObjectEx(sem, ::boost::detail::win32::infinite,0)); + unsigned const retval(winapi::WaitForSingleObjectEx(sem, ::boost::detail::win32::infinite,0)); BOOST_VERIFY(0 == retval || ::boost::detail::win32::wait_abandoned == retval); -// BOOST_VERIFY(win32::WaitForSingleObject( +// BOOST_VERIFY(winapi::WaitForSingleObject( // sem,::boost::detail::win32::infinite)==0); clear_waiting_and_try_lock(old_count); lock_acquired=!(old_count&lock_flag_value); @@ -142,7 +142,7 @@ namespace boost do { - if(win32::WaitForSingleObjectEx(sem,::boost::detail::get_milliseconds_until(wait_until),0)!=0) + if(winapi::WaitForSingleObjectEx(sem,::boost::detail::get_milliseconds_until(wait_until),0)!=0) { BOOST_INTERLOCKED_DECREMENT(&active_count); return false; @@ -210,7 +210,7 @@ namespace boost } chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-now); - if(win32::WaitForSingleObjectEx(sem,static_cast<unsigned long>(rel_time.count()),0)!=0) + if(winapi::WaitForSingleObjectEx(sem,static_cast<unsigned long>(rel_time.count()),0)!=0) { BOOST_INTERLOCKED_DECREMENT(&active_count); return false; @@ -232,7 +232,7 @@ namespace boost { if(!win32::interlocked_bit_test_and_set(&active_count,event_set_flag_bit)) { - win32::SetEvent(get_event()); + winapi::SetEvent(get_event()); } } } @@ -256,7 +256,7 @@ namespace boost #endif if(old_event!=0) { - win32::CloseHandle(new_event); + winapi::CloseHandle(new_event); return old_event; } else diff --git a/boost/thread/win32/condition_variable.hpp b/boost/thread/win32/condition_variable.hpp index 7f670bb990..5ff342f1fa 100644 --- a/boost/thread/win32/condition_variable.hpp +++ b/boost/thread/win32/condition_variable.hpp @@ -76,7 +76,7 @@ namespace boost void release(unsigned count_to_release) { notified=true; - detail::win32::ReleaseSemaphore(semaphore,count_to_release,0); + detail::winapi::ReleaseSemaphore(semaphore,count_to_release,0); } void release_waiters() @@ -96,7 +96,7 @@ namespace boost bool woken() { - unsigned long const woken_result=detail::win32::WaitForSingleObjectEx(wake_sem,0,0); + unsigned long const woken_result=detail::winapi::WaitForSingleObjectEx(wake_sem,0,0); BOOST_ASSERT((woken_result==detail::win32::timeout) || (woken_result==0)); return woken_result==0; } @@ -135,7 +135,7 @@ namespace boost void wake_waiters(long count_to_wake) { detail::interlocked_write_release(&total_count,total_count-count_to_wake); - detail::win32::ReleaseSemaphore(wake_sem,count_to_wake,0); + detail::winapi::ReleaseSemaphore(wake_sem,count_to_wake,0); } template<typename lock_type> diff --git a/boost/thread/win32/mfc_thread_init.hpp b/boost/thread/win32/mfc_thread_init.hpp index e866f8949f..5565a5a485 100644 --- a/boost/thread/win32/mfc_thread_init.hpp +++ b/boost/thread/win32/mfc_thread_init.hpp @@ -27,12 +27,12 @@ inline BOOL WINAPI ExtRawDllMain(HINSTANCE, DWORD dwReason, LPVOID) return TRUE; // ok } -extern "C" __declspec(selectany) BOOL (WINAPI * const _pRawDllMainOrig)(HANDLE, DWORD, LPVOID) = &ExtRawDllMain; +extern "C" __declspec(selectany) BOOL (WINAPI * const _pRawDllMainOrig)(HINSTANCE, DWORD, LPVOID) = &ExtRawDllMain; # elif defined(_USRDLL) -extern "C" BOOL WINAPI RawDllMain(HANDLE, DWORD dwReason, LPVOID); -extern "C" __declspec(selectany) BOOL (WINAPI * const _pRawDllMainOrig)(HANDLE, DWORD, LPVOID) = &RawDllMain; +extern "C" BOOL WINAPI RawDllMain(HINSTANCE, DWORD dwReason, LPVOID); +extern "C" __declspec(selectany) BOOL (WINAPI * const _pRawDllMainOrig)(HINSTANCE, DWORD, LPVOID) = &RawDllMain; # endif #endif diff --git a/boost/thread/win32/once.hpp b/boost/thread/win32/once.hpp index 24eb0f29d0..e7c565fbfa 100644 --- a/boost/thread/win32/once.hpp +++ b/boost/thread/win32/once.hpp @@ -124,7 +124,7 @@ namespace boost std::memcpy(mutex_name,fixed_mutex_name,sizeof(fixed_mutex_name)); detail::int_to_string(reinterpret_cast<std::ptrdiff_t>(flag_address), mutex_name + once_mutex_name_fixed_length); - detail::int_to_string(win32::GetCurrentProcessId(), + detail::int_to_string(winapi::GetCurrentProcessId(), mutex_name + once_mutex_name_fixed_length + sizeof(void*)*2); } @@ -136,9 +136,9 @@ namespace boost } #ifdef BOOST_NO_ANSI_APIS - return ::boost::detail::win32::OpenEventW( + return ::boost::detail::winapi::OpenEventW( #else - return ::boost::detail::win32::OpenEventA( + return ::boost::detail::winapi::OpenEventA( #endif ::boost::detail::win32::synchronize | ::boost::detail::win32::event_modify_state, @@ -186,7 +186,7 @@ namespace boost } if(ctx.event_handle) { - ::boost::detail::win32::ResetEvent(ctx.event_handle); + ::boost::detail::winapi::ResetEvent(ctx.event_handle); } return true; } @@ -207,7 +207,7 @@ namespace boost } if(ctx.event_handle) { - ::boost::detail::win32::SetEvent(ctx.event_handle); + ::boost::detail::winapi::SetEvent(ctx.event_handle); } } inline void rollback_once_region(once_flag& flag, once_context& ctx) BOOST_NOEXCEPT @@ -219,7 +219,7 @@ namespace boost } if(ctx.event_handle) { - ::boost::detail::win32::SetEvent(ctx.event_handle); + ::boost::detail::winapi::SetEvent(ctx.event_handle); } } } @@ -264,7 +264,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite, 0)); } } @@ -308,7 +308,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -355,7 +355,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -400,7 +400,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -443,7 +443,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -486,7 +486,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -529,7 +529,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -574,7 +574,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -617,7 +617,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -660,7 +660,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -703,7 +703,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -748,7 +748,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -793,7 +793,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -839,7 +839,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -886,7 +886,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -930,7 +930,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -977,7 +977,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -1024,7 +1024,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } @@ -1073,7 +1073,7 @@ namespace boost continue; } } - BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObjectEx( + BOOST_VERIFY(!::boost::detail::winapi::WaitForSingleObjectEx( ctx.event_handle,::boost::detail::win32::infinite,0)); } } diff --git a/boost/thread/win32/shared_mutex.hpp b/boost/thread/win32/shared_mutex.hpp index b7822d1142..d1bd971770 100644 --- a/boost/thread/win32/shared_mutex.hpp +++ b/boost/thread/win32/shared_mutex.hpp @@ -67,19 +67,19 @@ namespace boost { if(old_state.exclusive_waiting) { - BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[exclusive_sem],1,0)!=0); + BOOST_VERIFY(detail::winapi::ReleaseSemaphore(semaphores[exclusive_sem],1,0)!=0); } if(old_state.shared_waiting || old_state.exclusive_waiting) { - BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[unlock_sem],old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0); + BOOST_VERIFY(detail::winapi::ReleaseSemaphore(semaphores[unlock_sem],old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0); } } void release_shared_waiters(state_data old_state) { if(old_state.shared_waiting || old_state.exclusive_waiting) { - BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[unlock_sem],old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0); + BOOST_VERIFY(detail::winapi::ReleaseSemaphore(semaphores[unlock_sem],old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0); } } @@ -107,9 +107,9 @@ namespace boost ~shared_mutex() { - detail::win32::CloseHandle(upgrade_sem); - detail::win32::CloseHandle(semaphores[unlock_sem]); - detail::win32::CloseHandle(semaphores[exclusive_sem]); + detail::winapi::CloseHandle(upgrade_sem); + detail::winapi::CloseHandle(semaphores[unlock_sem]); + detail::winapi::CloseHandle(semaphores[exclusive_sem]); } bool try_lock_shared() @@ -191,7 +191,7 @@ namespace boost return true; } - unsigned long const res=detail::win32::WaitForSingleObjectEx(semaphores[unlock_sem],::boost::detail::get_milliseconds_until(wait_until), 0); + unsigned long const res=detail::winapi::WaitForSingleObjectEx(semaphores[unlock_sem],::boost::detail::get_milliseconds_until(wait_until), 0); if(res==detail::win32::timeout) { for(;;) @@ -296,7 +296,7 @@ namespace boost unsigned long res; if (tp>n) { chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-n); - res=detail::win32::WaitForSingleObjectEx(semaphores[unlock_sem], + res=detail::winapi::WaitForSingleObjectEx(semaphores[unlock_sem], static_cast<unsigned long>(rel_time.count()), 0); } else { res=detail::win32::timeout; @@ -375,7 +375,7 @@ namespace boost { if(old_state.upgrade) { - BOOST_VERIFY(detail::win32::ReleaseSemaphore(upgrade_sem,1,0)!=0); + BOOST_VERIFY(detail::winapi::ReleaseSemaphore(upgrade_sem,1,0)!=0); } else { @@ -474,7 +474,7 @@ namespace boost #else const bool wait_all = false; #endif - unsigned long const wait_res=detail::win32::WaitForMultipleObjectsEx(2,semaphores,wait_all,::boost::detail::get_milliseconds_until(wait_until), 0); + unsigned long const wait_res=detail::winapi::WaitForMultipleObjectsEx(2,semaphores,wait_all,::boost::detail::get_milliseconds_until(wait_until), 0); if(wait_res==detail::win32::timeout) { for(;;) @@ -500,7 +500,7 @@ namespace boost state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state); if (must_notify) { - BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[unlock_sem],1,0)!=0); + BOOST_VERIFY(detail::winapi::ReleaseSemaphore(semaphores[unlock_sem],1,0)!=0); } if(current_state==old_state) @@ -586,7 +586,7 @@ namespace boost unsigned long wait_res; if (tp>n) { chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-chrono::system_clock::now()); - wait_res=detail::win32::WaitForMultipleObjectsEx(2,semaphores,wait_all, + wait_res=detail::winapi::WaitForMultipleObjectsEx(2,semaphores,wait_all, static_cast<unsigned long>(rel_time.count()), 0); } else { wait_res=detail::win32::timeout; @@ -616,7 +616,7 @@ namespace boost state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state); if (must_notify) { - BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[unlock_sem],1,0)!=0); + BOOST_VERIFY(detail::winapi::ReleaseSemaphore(semaphores[unlock_sem],1,0)!=0); } if(current_state==old_state) { @@ -698,7 +698,7 @@ namespace boost return; } - BOOST_VERIFY(!detail::win32::WaitForSingleObjectEx(semaphores[unlock_sem],detail::win32::infinite, 0)); + BOOST_VERIFY(!detail::winapi::WaitForSingleObjectEx(semaphores[unlock_sem],detail::winapi::infinite, 0)); } } @@ -790,7 +790,7 @@ namespace boost { if(!last_reader) { - BOOST_VERIFY(!detail::win32::WaitForSingleObjectEx(upgrade_sem,detail::win32::infinite, 0)); + BOOST_VERIFY(!detail::winapi::WaitForSingleObjectEx(upgrade_sem,detail::win32::infinite, 0)); } break; } diff --git a/boost/thread/win32/thread_data.hpp b/boost/thread/win32/thread_data.hpp index 005f3ba503..ed74198fbe 100644 --- a/boost/thread/win32/thread_data.hpp +++ b/boost/thread/win32/thread_data.hpp @@ -153,7 +153,7 @@ namespace boost #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS void interrupt() { - BOOST_VERIFY(detail::win32::SetEvent(interruption_handle)!=0); + BOOST_VERIFY(detail::winapi::SetEvent(interruption_handle)!=0); } #endif typedef detail::win32::handle native_handle_type; diff --git a/boost/thread/win32/thread_heap_alloc.hpp b/boost/thread/win32/thread_heap_alloc.hpp index 610fe3263e..96621355c5 100644 --- a/boost/thread/win32/thread_heap_alloc.hpp +++ b/boost/thread/win32/thread_heap_alloc.hpp @@ -12,45 +12,7 @@ #include <boost/throw_exception.hpp> #include <boost/core/no_exceptions_support.hpp> -#if defined( BOOST_USE_WINDOWS_H ) -# include <windows.h> - -namespace boost -{ - namespace detail - { - namespace win32 - { - using ::GetProcessHeap; - using ::HeapAlloc; - using ::HeapFree; - } - } -} - -#else - -# ifdef HeapAlloc -# undef HeapAlloc -# endif - -namespace boost -{ - namespace detail - { - namespace win32 - { - extern "C" - { - __declspec(dllimport) handle __stdcall GetProcessHeap(); - __declspec(dllimport) void* __stdcall HeapAlloc(handle,unsigned long,ulong_ptr); - __declspec(dllimport) int __stdcall HeapFree(handle,unsigned long,void*); - } - } - } -} - -#endif +#include <boost/detail/winapi/heap_memory.hpp> #include <boost/config/abi_prefix.hpp> @@ -60,7 +22,7 @@ namespace boost { inline void* allocate_raw_heap_memory(unsigned size) { - void* const heap_memory=detail::win32::HeapAlloc(detail::win32::GetProcessHeap(),0,size); + void* const heap_memory=detail::winapi::HeapAlloc(detail::winapi::GetProcessHeap(),0,size); if(!heap_memory) { boost::throw_exception(std::bad_alloc()); @@ -70,9 +32,26 @@ namespace boost inline void free_raw_heap_memory(void* heap_memory) { - BOOST_VERIFY(detail::win32::HeapFree(detail::win32::GetProcessHeap(),0,heap_memory)!=0); + BOOST_VERIFY(detail::winapi::HeapFree(detail::winapi::GetProcessHeap(),0,heap_memory)!=0); + } +#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) && ! defined (BOOST_NO_CXX11_RVALUE_REFERENCES) + template<typename T,typename... Args> + inline T* heap_new(Args&&... args) + { + void* const heap_memory=allocate_raw_heap_memory(sizeof(T)); + BOOST_TRY + { + T* const data=new (heap_memory) T(static_cast<Args&&>(args)...); + return data; + } + BOOST_CATCH(...) + { + free_raw_heap_memory(heap_memory); + BOOST_RETHROW + } + BOOST_CATCH_END } - +#else template<typename T> inline T* heap_new() { @@ -225,6 +204,86 @@ namespace boost } BOOST_CATCH_END } + template<typename T,typename A1,typename A2,typename A3,typename A4,typename A5> + inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) + { + void* const heap_memory=allocate_raw_heap_memory(sizeof(T)); + BOOST_TRY + { + T* const data=new (heap_memory) T(a1,a2,a3,a4,a5); + return data; + } + BOOST_CATCH(...) + { + free_raw_heap_memory(heap_memory); + BOOST_RETHROW + } + BOOST_CATCH_END + } + template<typename T,typename A1,typename A2,typename A3,typename A4,typename A5,typename A6> + inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6) + { + void* const heap_memory=allocate_raw_heap_memory(sizeof(T)); + BOOST_TRY + { + T* const data=new (heap_memory) T(a1,a2,a3,a4,a5,a6); + return data; + } + BOOST_CATCH(...) + { + free_raw_heap_memory(heap_memory); + BOOST_RETHROW + } + BOOST_CATCH_END + } + template<typename T,typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7> + inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7) + { + void* const heap_memory=allocate_raw_heap_memory(sizeof(T)); + BOOST_TRY + { + T* const data=new (heap_memory) T(a1,a2,a3,a4,a5,a6,a7); + return data; + } + BOOST_CATCH(...) + { + free_raw_heap_memory(heap_memory); + BOOST_RETHROW + } + BOOST_CATCH_END + } + template<typename T,typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7,typename A8> + inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8) + { + void* const heap_memory=allocate_raw_heap_memory(sizeof(T)); + BOOST_TRY + { + T* const data=new (heap_memory) T(a1,a2,a3,a4,a5,a6,a7,a8); + return data; + } + BOOST_CATCH(...) + { + free_raw_heap_memory(heap_memory); + BOOST_RETHROW + } + BOOST_CATCH_END + } + template<typename T,typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7,typename A8,typename A9> + inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8,A9 a9) + { + void* const heap_memory=allocate_raw_heap_memory(sizeof(T)); + BOOST_TRY + { + T* const data=new (heap_memory) T(a1,a2,a3,a4,a5,a6,a7,a8,a9); + return data; + } + BOOST_CATCH(...) + { + free_raw_heap_memory(heap_memory); + BOOST_RETHROW + } + BOOST_CATCH_END + } template<typename T,typename A1> @@ -385,6 +444,7 @@ namespace boost } #endif +#endif template<typename T> inline void heap_delete(T* data) { diff --git a/boost/thread/win32/thread_primitives.hpp b/boost/thread/win32/thread_primitives.hpp index 133cc9c761..f93cc2438e 100644 --- a/boost/thread/win32/thread_primitives.hpp +++ b/boost/thread/win32/thread_primitives.hpp @@ -17,6 +17,21 @@ #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/thread/win32/interlocked_read.hpp> #include <algorithm> @@ -25,200 +40,29 @@ #include <thread> #endif -#if defined( BOOST_USE_WINDOWS_H ) -# include <windows.h> - -namespace boost -{ - namespace detail - { - namespace win32 - { - typedef HANDLE handle; - typedef SYSTEM_INFO system_info; - typedef unsigned __int64 ticks_type; - typedef FARPROC farproc_t; - unsigned const infinite=INFINITE; - unsigned const timeout=WAIT_TIMEOUT; - handle const invalid_handle_value=INVALID_HANDLE_VALUE; - unsigned const event_modify_state=EVENT_MODIFY_STATE; - unsigned const synchronize=SYNCHRONIZE; - unsigned const wait_abandoned=WAIT_ABANDONED; - unsigned const create_event_initial_set = 0x00000002; - unsigned const create_event_manual_reset = 0x00000001; - unsigned const event_all_access = EVENT_ALL_ACCESS; - unsigned const semaphore_all_access = SEMAPHORE_ALL_ACCESS; - - -# ifdef BOOST_NO_ANSI_APIS -# if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA - using ::CreateMutexW; - using ::CreateEventW; - using ::CreateSemaphoreW; -# else - using ::CreateMutexExW; - using ::CreateEventExW; - using ::CreateSemaphoreExW; -# endif - using ::OpenEventW; - using ::GetModuleHandleW; -# else - using ::CreateMutexA; - using ::CreateEventA; - using ::OpenEventA; - using ::CreateSemaphoreA; - using ::GetModuleHandleA; -# endif -#if BOOST_PLAT_WINDOWS_RUNTIME - using ::GetNativeSystemInfo; - using ::GetTickCount64; -#else - using ::GetSystemInfo; - using ::GetTickCount; -#endif - using ::CloseHandle; - using ::ReleaseMutex; - using ::ReleaseSemaphore; - using ::SetEvent; - using ::ResetEvent; - using ::WaitForMultipleObjectsEx; - using ::WaitForSingleObjectEx; - using ::GetCurrentProcessId; - using ::GetCurrentThreadId; - using ::GetCurrentThread; - using ::GetCurrentProcess; - using ::DuplicateHandle; -#if !BOOST_PLAT_WINDOWS_RUNTIME - using ::SleepEx; - using ::Sleep; - using ::QueueUserAPC; - using ::GetProcAddress; -#endif - } - } -} -#elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) - -# ifdef UNDER_CE -# ifndef WINAPI -# ifndef _WIN32_WCE_EMULATION -# define WINAPI __cdecl // Note this doesn't match the desktop definition -# else -# define WINAPI __stdcall -# endif -# endif - -# ifdef __cplusplus -extern "C" { -# endif -typedef int BOOL; -typedef unsigned long DWORD; -typedef void* HANDLE; -# include <kfuncs.h> -# ifdef __cplusplus -} -# endif -# endif - -# ifdef __cplusplus -extern "C" { -# endif -struct _SYSTEM_INFO; -# ifdef __cplusplus -} -#endif - namespace boost { namespace detail { namespace win32 { -# ifdef _WIN64 - typedef unsigned __int64 ulong_ptr; -# else - typedef unsigned long ulong_ptr; -# endif - typedef void* handle; - typedef _SYSTEM_INFO system_info; + typedef ::boost::detail::winapi::HANDLE_ handle; + typedef ::boost::detail::winapi::SYSTEM_INFO_ system_info; typedef unsigned __int64 ticks_type; - typedef int (__stdcall *farproc_t)(); - unsigned const infinite=~0U; - unsigned const timeout=258U; - handle const invalid_handle_value=(handle)(-1); - unsigned const event_modify_state=2; - unsigned const synchronize=0x100000u; - unsigned const wait_abandoned=0x00000080u; + 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_; unsigned const create_event_initial_set = 0x00000002; unsigned const create_event_manual_reset = 0x00000001; - unsigned const event_all_access = 0x1F0003; - unsigned const semaphore_all_access = 0x1F0003; - - extern "C" - { - struct _SECURITY_ATTRIBUTES; -# ifdef BOOST_NO_ANSI_APIS -# if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA - __declspec(dllimport) void* __stdcall CreateMutexW(_SECURITY_ATTRIBUTES*,int,wchar_t const*); - __declspec(dllimport) void* __stdcall CreateSemaphoreW(_SECURITY_ATTRIBUTES*,long,long,wchar_t const*); - __declspec(dllimport) void* __stdcall CreateEventW(_SECURITY_ATTRIBUTES*,int,int,wchar_t const*); -# else - __declspec(dllimport) void* __stdcall CreateMutexExW(_SECURITY_ATTRIBUTES*,wchar_t const*,unsigned long,unsigned long); - __declspec(dllimport) void* __stdcall CreateEventExW(_SECURITY_ATTRIBUTES*,wchar_t const*,unsigned long,unsigned long); - __declspec(dllimport) void* __stdcall CreateSemaphoreExW(_SECURITY_ATTRIBUTES*,long,long,wchar_t const*,unsigned long,unsigned long); -# endif - __declspec(dllimport) void* __stdcall OpenEventW(unsigned long,int,wchar_t const*); - __declspec(dllimport) void* __stdcall GetModuleHandleW(wchar_t const*); -# else - __declspec(dllimport) void* __stdcall CreateMutexA(_SECURITY_ATTRIBUTES*,int,char const*); - __declspec(dllimport) void* __stdcall CreateSemaphoreA(_SECURITY_ATTRIBUTES*,long,long,char const*); - __declspec(dllimport) void* __stdcall CreateEventA(_SECURITY_ATTRIBUTES*,int,int,char const*); - __declspec(dllimport) void* __stdcall OpenEventA(unsigned long,int,char const*); - __declspec(dllimport) void* __stdcall GetModuleHandleA(char const*); -# endif -#if BOOST_PLAT_WINDOWS_RUNTIME - __declspec(dllimport) void __stdcall GetNativeSystemInfo(_SYSTEM_INFO*); - __declspec(dllimport) ticks_type __stdcall GetTickCount64(); -#else - __declspec(dllimport) void __stdcall GetSystemInfo(_SYSTEM_INFO*); - __declspec(dllimport) unsigned long __stdcall GetTickCount(); -#endif - __declspec(dllimport) int __stdcall CloseHandle(void*); - __declspec(dllimport) int __stdcall ReleaseMutex(void*); - __declspec(dllimport) unsigned long __stdcall WaitForSingleObjectEx(void*,unsigned long,int); - __declspec(dllimport) unsigned long __stdcall WaitForMultipleObjectsEx(unsigned long nCount,void* const * lpHandles,int bWaitAll,unsigned long dwMilliseconds,int bAlertable); - __declspec(dllimport) int __stdcall ReleaseSemaphore(void*,long,long*); - __declspec(dllimport) int __stdcall DuplicateHandle(void*,void*,void*,void**,unsigned long,int,unsigned long); -#if !BOOST_PLAT_WINDOWS_RUNTIME - __declspec(dllimport) unsigned long __stdcall SleepEx(unsigned long,int); - __declspec(dllimport) void __stdcall Sleep(unsigned long); - typedef void (__stdcall *queue_user_apc_callback_function)(ulong_ptr); - __declspec(dllimport) unsigned long __stdcall QueueUserAPC(queue_user_apc_callback_function,void*,ulong_ptr); - __declspec(dllimport) farproc_t __stdcall GetProcAddress(void *, const char *); -#endif - -# ifndef UNDER_CE - __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId(); - __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(); - __declspec(dllimport) void* __stdcall GetCurrentThread(); - __declspec(dllimport) void* __stdcall GetCurrentProcess(); - __declspec(dllimport) int __stdcall SetEvent(void*); - __declspec(dllimport) int __stdcall ResetEvent(void*); -# else - using ::GetCurrentProcessId; - using ::GetCurrentThreadId; - using ::GetCurrentThread; - using ::GetCurrentProcess; - using ::SetEvent; - using ::ResetEvent; -# endif - } + unsigned const event_all_access = ::boost::detail::winapi::EVENT_ALL_ACCESS_; + unsigned const semaphore_all_access = boost::detail::winapi::SEMAPHORE_ALL_ACCESS_; } } } -#else -# error "Win32 functions not available" -#endif #include <boost/config/abi_prefix.hpp> @@ -250,7 +94,7 @@ namespace boost ticks_type current_tick64; previous_count = (unsigned long) boost::detail::interlocked_read_acquire(&count); - current_tick32 = GetTickCount(); + current_tick32 = ::boost::detail::winapi::GetTickCount(); if(previous_count == (unsigned long)-1l) { @@ -302,13 +146,13 @@ namespace boost // GetTickCount and GetModuleHandle are not allowed in the Windows Runtime, // and kernel32 isn't used in Windows Phone. #if BOOST_PLAT_WINDOWS_RUNTIME - gettickcount64impl = &GetTickCount64; + gettickcount64impl = &::boost::detail::winapi::GetTickCount64; #else farproc_t addr=GetProcAddress( #if !defined(BOOST_NO_ANSI_APIS) - GetModuleHandleA("KERNEL32.DLL"), + ::boost::detail::winapi::GetModuleHandleA("KERNEL32.DLL"), #else - GetModuleHandleW(L"KERNEL32.DLL"), + ::boost::detail::winapi::GetModuleHandleW(L"KERNEL32.DLL"), #endif "GetTickCount64"); if(addr) @@ -341,11 +185,11 @@ namespace boost initial_event_state state) { #if !defined(BOOST_NO_ANSI_APIS) - handle const res = win32::CreateEventA(0, type, state, mutex_name); + handle const res = ::boost::detail::winapi::CreateEventA(0, type, state, mutex_name); #elif BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA - handle const res = win32::CreateEventW(0, type, state, mutex_name); + handle const res = ::boost::detail::winapi::CreateEventW(0, type, state, mutex_name); #else - handle const res = win32::CreateEventExW( + handle const res = ::boost::detail::winapi::CreateEventExW( 0, mutex_name, type ? create_event_manual_reset : 0 | state ? create_event_initial_set : 0, @@ -367,12 +211,12 @@ namespace boost inline handle create_anonymous_semaphore_nothrow(long initial_count,long max_count) { #if !defined(BOOST_NO_ANSI_APIS) - handle const res=win32::CreateSemaphoreA(0,initial_count,max_count,0); + handle const res=::boost::detail::winapi::CreateSemaphoreA(0,initial_count,max_count,0); #else #if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA - handle const res=win32::CreateSemaphoreEx(0,initial_count,max_count,0,0); + handle const res=::boost::detail::winapi::CreateSemaphoreEx(0,initial_count,max_count,0,0); #else - handle const res=win32::CreateSemaphoreExW(0,initial_count,max_count,0,0,semaphore_all_access); + handle const res=::boost::detail::winapi::CreateSemaphoreExW(0,initial_count,max_count,0,0,semaphore_all_access); #endif #endif return res; @@ -390,10 +234,10 @@ namespace boost inline handle duplicate_handle(handle source) { - handle const current_process=GetCurrentProcess(); + handle const current_process=::boost::detail::winapi::GetCurrentProcess(); long const same_access_flag=2; handle new_handle=0; - bool const success=DuplicateHandle(current_process,source,current_process,&new_handle,0,false,same_access_flag)!=0; + bool const success=::boost::detail::winapi::DuplicateHandle(current_process,source,current_process,&new_handle,0,false,same_access_flag)!=0; if(!success) { boost::throw_exception(thread_resource_error()); @@ -403,15 +247,15 @@ namespace boost inline void release_semaphore(handle semaphore,long count) { - BOOST_VERIFY(ReleaseSemaphore(semaphore,count,0)!=0); + BOOST_VERIFY(::boost::detail::winapi::ReleaseSemaphore(semaphore,count,0)!=0); } inline void get_system_info(system_info *info) { #if BOOST_PLAT_WINDOWS_RUNTIME - win32::GetNativeSystemInfo(info); + ::boost::detail::winapi::GetNativeSystemInfo(info); #else - win32::GetSystemInfo(info); + ::boost::detail::winapi::GetSystemInfo(info); #endif } @@ -422,15 +266,15 @@ namespace boost #if BOOST_PLAT_WINDOWS_RUNTIME std::this_thread::yield(); #else - ::boost::detail::win32::Sleep(0); + ::boost::detail::winapi::Sleep(0); #endif } else { #if BOOST_PLAT_WINDOWS_RUNTIME - ::boost::detail::win32::WaitForSingleObjectEx(::boost::detail::win32::GetCurrentThread(), milliseconds, 0); + ::boost::detail::winapi::WaitForSingleObjectEx(::boost::detail::winapi::GetCurrentThread(), milliseconds, 0); #else - ::boost::detail::win32::Sleep(milliseconds); + ::boost::detail::winapi::Sleep(milliseconds); #endif } } @@ -446,7 +290,7 @@ namespace boost { if (m_completionHandle != ::boost::detail::win32::invalid_handle_value) { - CloseHandle(m_completionHandle); + ::boost::detail::winapi::CloseHandle(m_completionHandle); } } @@ -474,7 +318,7 @@ namespace boost { if(handle_to_manage && handle_to_manage!=invalid_handle_value) { - BOOST_VERIFY(CloseHandle(handle_to_manage)); + BOOST_VERIFY(::boost::detail::winapi::CloseHandle(handle_to_manage)); } } |