From 89348a9569c3d98f4bec899e024c771705fd439d Mon Sep 17 00:00:00 2001 From: Anthony Williams Date: Fri, 17 Nov 2006 10:45:27 +0000 Subject: [PATCH] basic timed mutex uses an Auto-Reset Event rather than a semaphore; changed thread_primitives to avoid use of macros [SVN r36067] --- include/boost/thread/win32/basic_mutex.hpp | 104 ---------- .../thread/win32/basic_recursive_mutex.hpp | 18 +- .../boost/thread/win32/basic_timed_mutex.hpp | 36 ++-- include/boost/thread/win32/condition.hpp | 15 +- include/boost/thread/win32/mutex.hpp | 10 - include/boost/thread/win32/once.hpp | 10 +- .../boost/thread/win32/read_write_mutex.hpp | 26 +-- .../boost/thread/win32/thread_primitives.hpp | 193 ++++++++---------- include/boost/thread/win32/xtime_utils.hpp | 10 +- 9 files changed, 136 insertions(+), 286 deletions(-) delete mode 100644 include/boost/thread/win32/basic_mutex.hpp diff --git a/include/boost/thread/win32/basic_mutex.hpp b/include/boost/thread/win32/basic_mutex.hpp deleted file mode 100644 index 38307990..00000000 --- a/include/boost/thread/win32/basic_mutex.hpp +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef BOOST_BASIC_MUTEX_WIN32_HPP -#define BOOST_BASIC_MUTEX_WIN32_HPP - -// basic_mutex_win32.hpp -// -// (C) Copyright 2006 Anthony Williams -// -// 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 -#include - -namespace boost -{ - namespace detail - { - struct basic_mutex - { - long lock_flag; - void* semaphore; - - BOOST_STATIC_CONSTANT(long, unlocked = 0); - BOOST_STATIC_CONSTANT(long, just_me = 1); - BOOST_STATIC_CONSTANT(long, waiting_threads = 2); - - void initialize() - { - lock_flag=unlocked; - semaphore=0; - get_semaphore(); - } - - void destroy() - { - void* const old_semaphore=BOOST_INTERLOCKED_EXCHANGE_POINTER(&semaphore,0); - if(old_semaphore) - { - BOOST_CLOSE_HANDLE(old_semaphore); - } - } - - - bool try_lock() - { - return BOOST_INTERLOCKED_COMPARE_EXCHANGE(&lock_flag,just_me,unlocked)==unlocked; - } - - void lock() - { - if(!try_lock()) - { - while(BOOST_INTERLOCKED_EXCHANGE(&lock_flag,waiting_threads)!=unlocked) - { - BOOST_WAIT_FOR_SINGLE_OBJECT(get_semaphore(),BOOST_INFINITE); - } - } - } - - void unlock() - { - if(BOOST_INTERLOCKED_EXCHANGE(&lock_flag,unlocked)==waiting_threads) - { - BOOST_RELEASE_SEMAPHORE(get_semaphore(),1,0); - } - } - - bool locked() - { - return ::boost::detail::interlocked_read(&lock_flag)!=unlocked; - } - - private: - void* get_semaphore() - { - void* current_semaphore=::boost::detail::interlocked_read(&semaphore); - - if(!current_semaphore) - { - void* const new_semaphore=BOOST_CREATE_SEMAPHORE(0,0,1,0); - void* const old_semaphore=BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(&semaphore,new_semaphore,0); - if(old_semaphore!=0) - { - BOOST_CLOSE_HANDLE(new_semaphore); - return old_semaphore; - } - else - { - return new_semaphore; - } - } - return current_semaphore; - } - - }; - - } -} - -#define BOOST_BASIC_MUTEX_INITIALIZER {0} - -#endif diff --git a/include/boost/thread/win32/basic_recursive_mutex.hpp b/include/boost/thread/win32/basic_recursive_mutex.hpp index 4039940f..2f0c9a4e 100644 --- a/include/boost/thread/win32/basic_recursive_mutex.hpp +++ b/include/boost/thread/win32/basic_recursive_mutex.hpp @@ -12,11 +12,6 @@ #include #include #include -#ifdef BOOST_USE_CHECKED_MUTEX -#include -#else -#include -#endif #include #include @@ -45,13 +40,13 @@ namespace boost bool try_lock() { - long const current_thread_id=BOOST_GET_CURRENT_THREAD_ID(); + long const current_thread_id=win32::GetCurrentThreadId(); return try_recursive_lock(current_thread_id) || try_basic_lock(current_thread_id); } void lock() { - long const current_thread_id=BOOST_GET_CURRENT_THREAD_ID(); + long const current_thread_id=win32::GetCurrentThreadId(); if(!try_recursive_lock(current_thread_id)) { mutex.lock(); @@ -61,7 +56,7 @@ namespace boost } bool timed_lock(::boost::xtime const& target) { - long const current_thread_id=BOOST_GET_CURRENT_THREAD_ID(); + long const current_thread_id=win32::GetCurrentThreadId(); return try_recursive_lock(current_thread_id) || try_timed_lock(current_thread_id,target); } long get_active_count() @@ -118,12 +113,7 @@ namespace boost }; -#ifdef BOOST_USE_CHECKED_MUTEX - typedef basic_recursive_mutex_impl basic_recursive_mutex; -#else - typedef basic_recursive_mutex_impl basic_recursive_mutex; -#endif - + typedef basic_recursive_mutex_impl basic_recursive_mutex; typedef basic_recursive_mutex_impl basic_recursive_timed_mutex; } } diff --git a/include/boost/thread/win32/basic_timed_mutex.hpp b/include/boost/thread/win32/basic_timed_mutex.hpp index 5a7a0cb8..78c4ac48 100644 --- a/include/boost/thread/win32/basic_timed_mutex.hpp +++ b/include/boost/thread/win32/basic_timed_mutex.hpp @@ -24,20 +24,20 @@ namespace boost { BOOST_STATIC_CONSTANT(long,lock_flag_value=0x10000); long active_count; - void* semaphore; + void* event; void initialize() { active_count=0; - semaphore=0; + event=0; } void destroy() { - void* const old_semaphore=BOOST_INTERLOCKED_EXCHANGE_POINTER(&semaphore,0); - if(old_semaphore) + void* const old_event=BOOST_INTERLOCKED_EXCHANGE_POINTER(&event,0); + if(old_event) { - BOOST_CLOSE_HANDLE(old_semaphore); + win32::CloseHandle(old_event); } } @@ -78,12 +78,12 @@ namespace boost if(old_count&lock_flag_value) { bool lock_acquired=false; - void* const sem=get_semaphore(); + void* const sem=get_event(); ++old_count; // we're waiting, too do { old_count-=(lock_flag_value+1); // there will be one less active thread on this mutex when it gets unlocked - if(BOOST_WAIT_FOR_SINGLE_OBJECT(sem,::boost::detail::get_milliseconds_until_time(target_time))!=0) + if(win32::WaitForSingleObject(sem,::boost::detail::get_milliseconds_until_time(target_time))!=0) { BOOST_INTERLOCKED_DECREMENT(&active_count); return false; @@ -117,7 +117,7 @@ namespace boost if(old_count>offset) { - BOOST_RELEASE_SEMAPHORE(get_semaphore(),1,0); + win32::SetEvent(get_event()); } } @@ -127,25 +127,25 @@ namespace boost } private: - void* get_semaphore() + void* get_event() { - void* current_semaphore=::boost::detail::interlocked_read(&semaphore); + void* current_event=::boost::detail::interlocked_read(&event); - if(!current_semaphore) + if(!current_event) { - void* const new_semaphore=BOOST_CREATE_SEMAPHORE(0,0,1,0); - void* const old_semaphore=BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(&semaphore,new_semaphore,0); - if(old_semaphore!=0) + void* const new_event=win32::create_anonymous_event(win32::auto_reset_event,win32::event_initially_reset); + void* const old_event=BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(&event,new_event,0); + if(old_event!=0) { - BOOST_CLOSE_HANDLE(new_semaphore); - return old_semaphore; + win32::CloseHandle(new_event); + return old_event; } else { - return new_semaphore; + return new_event; } } - return current_semaphore; + return current_event; } }; diff --git a/include/boost/thread/win32/condition.hpp b/include/boost/thread/win32/condition.hpp index 4760fb9c..199236c4 100644 --- a/include/boost/thread/win32/condition.hpp +++ b/include/boost/thread/win32/condition.hpp @@ -3,9 +3,6 @@ // 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) -// -// This work is a reimplementation along the design and ideas -// of William E. Kempf. #ifndef BOOST_THREAD_RS06041001_HPP #define BOOST_THREAD_RS06041001_HPP @@ -78,7 +75,7 @@ namespace boost entry.unlink(); } } - BOOST_CLOSE_HANDLE(entry.waiting_thread_handle); + detail::win32::CloseHandle(entry.waiting_thread_handle); m.lock(); } }; @@ -87,10 +84,10 @@ namespace boost bool do_wait(lockable_type& m,boost::xtime const& target=::boost::detail::get_xtime_sentinel()) { waiting_list_entry entry={0}; - void* const currentProcess=BOOST_GET_CURRENT_PROCESS(); + void* const currentProcess=detail::win32::GetCurrentProcess(); long const same_access_flag=2; - bool const success=BOOST_DUPLICATE_HANDLE(currentProcess,BOOST_GET_CURRENT_THREAD(),currentProcess,&entry.waiting_thread_handle,0,false,same_access_flag)!=0; + bool const success=detail::win32::DuplicateHandle(currentProcess,detail::win32::GetCurrentThread(),currentProcess,&entry.waiting_thread_handle,0,false,same_access_flag)!=0; BOOST_ASSERT(success); { @@ -98,13 +95,13 @@ namespace boost unsigned const woken_due_to_apc=0xc0; while(!::boost::detail::interlocked_read(&entry.notified) && - BOOST_SLEEP_EX(::boost::detail::get_milliseconds_until_time(target),true)==woken_due_to_apc); + detail::win32::SleepEx(::boost::detail::get_milliseconds_until_time(target),true)==woken_due_to_apc); } return ::boost::detail::interlocked_read(&entry.notified)!=0; } - static void __stdcall notify_function(::boost::detail::ulong_ptr) + static void __stdcall notify_function(detail::win32::ulong_ptr) { } @@ -113,7 +110,7 @@ namespace boost BOOST_INTERLOCKED_EXCHANGE(&entry->notified,true); if(entry->waiting_thread_handle) { - BOOST_QUEUE_USER_APC(notify_function,entry->waiting_thread_handle,0); + detail::win32::QueueUserAPC(notify_function,entry->waiting_thread_handle,0); } } diff --git a/include/boost/thread/win32/mutex.hpp b/include/boost/thread/win32/mutex.hpp index 1951d907..18417c3b 100644 --- a/include/boost/thread/win32/mutex.hpp +++ b/include/boost/thread/win32/mutex.hpp @@ -12,11 +12,6 @@ #include -#ifdef BOOST_USE_CHECKED_MUTEX -#include -#else -#include -#endif #include #include #include @@ -27,11 +22,6 @@ namespace boost { namespace detail { -// #ifdef BOOST_USE_CHECKED_MUTEX -// typedef ::boost::detail::basic_checked_mutex underlying_mutex; -// #else -// typedef ::boost::detail::basic_mutex underlying_mutex; -// #endif typedef ::boost::detail::basic_timed_mutex underlying_mutex; } diff --git a/include/boost/thread/win32/once.hpp b/include/boost/thread/win32/once.hpp index 0f6a29d3..c21e187e 100644 --- a/include/boost/thread/win32/once.hpp +++ b/include/boost/thread/win32/once.hpp @@ -43,7 +43,7 @@ namespace boost {} ~handle_closer() { - BOOST_CLOSE_HANDLE(handle_to_close); + win32::CloseHandle(handle_to_close); } }; @@ -53,11 +53,11 @@ namespace boost win32_mutex_scoped_lock(void* mutex_handle_): mutex_handle(mutex_handle_) { - BOOST_WAIT_FOR_SINGLE_OBJECT(mutex_handle,BOOST_INFINITE); + win32::WaitForSingleObject(mutex_handle,win32::infinite); } ~win32_mutex_scoped_lock() { - BOOST_RELEASE_MUTEX(mutex_handle); + win32::ReleaseMutex(mutex_handle); } }; @@ -88,10 +88,10 @@ namespace boost BOOST_STATIC_ASSERT(sizeof(void*) == sizeof(std::ptrdiff_t)); detail::int_to_string(reinterpret_cast(flag_address), mutex_name + once_mutex_name_fixed_length); - detail::int_to_string(BOOST_GET_PROCESS_ID(), mutex_name + once_mutex_name_fixed_length + sizeof(void*)*2); + detail::int_to_string(win32::GetCurrentProcessId(), mutex_name + once_mutex_name_fixed_length + sizeof(void*)*2); BOOST_ASSERT(sizeof(mutex_name) == std::strlen(mutex_name) + 1); - return BOOST_CREATE_MUTEX(NULL, 0, mutex_name); + return win32::CreateMutexA(NULL, 0, mutex_name); } } diff --git a/include/boost/thread/win32/read_write_mutex.hpp b/include/boost/thread/win32/read_write_mutex.hpp index 3ffdd2b6..96a094a5 100644 --- a/include/boost/thread/win32/read_write_mutex.hpp +++ b/include/boost/thread/win32/read_write_mutex.hpp @@ -55,13 +55,13 @@ namespace boost { if(old_state.exclusive_waiting) { - bool const success=::boost::detail::ReleaseSemaphore(exclusive_sem,1,NULL)!=0; + bool const success=detail::win32::ReleaseSemaphore(exclusive_sem,1,NULL)!=0; BOOST_ASSERT(success); } if(old_state.shared_waiting || old_state.exclusive_waiting) { - bool const success=::boost::detail::ReleaseSemaphore(unlock_sem,old_state.shared_waiting + (old_state.exclusive_waiting?1:0),NULL)!=0; + bool const success=detail::win32::ReleaseSemaphore(unlock_sem,old_state.shared_waiting + (old_state.exclusive_waiting?1:0),NULL)!=0; BOOST_ASSERT(success); } } @@ -72,18 +72,18 @@ namespace boost unlock_sem(semaphores[0]), exclusive_sem(semaphores[1]) { - unlock_sem=::boost::detail::CreateSemaphoreA(NULL,0,LONG_MAX,NULL); - exclusive_sem=::boost::detail::CreateSemaphoreA(NULL,0,LONG_MAX,NULL); - upgradeable_sem=::boost::detail::CreateSemaphoreA(NULL,0,LONG_MAX,NULL); + unlock_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX); + exclusive_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX); + upgradeable_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX); state_data state_={0}; state=state_; } ~read_write_mutex() { - ::boost::detail::CloseHandle(upgradeable_sem); - ::boost::detail::CloseHandle(unlock_sem); - ::boost::detail::CloseHandle(exclusive_sem); + detail::win32::CloseHandle(upgradeable_sem); + detail::win32::CloseHandle(unlock_sem); + detail::win32::CloseHandle(exclusive_sem); } bool try_lock_shareable() @@ -139,7 +139,7 @@ namespace boost return; } - unsigned long const res=::boost::detail::WaitForSingleObject(unlock_sem,BOOST_INFINITE); + unsigned long const res=detail::win32::WaitForSingleObject(unlock_sem,detail::win32::infinite); BOOST_ASSERT(res==0); } } @@ -177,7 +177,7 @@ namespace boost { if(old_state.upgradeable) { - bool const success=::boost::detail::ReleaseSemaphore(upgradeable_sem,1,NULL)!=0; + bool const success=detail::win32::ReleaseSemaphore(upgradeable_sem,1,NULL)!=0; BOOST_ASSERT(success); } else @@ -224,7 +224,7 @@ namespace boost { break; } - bool const success2=::boost::detail::WaitForMultipleObjects(2,semaphores,true,BOOST_INFINITE)<2; + bool const success2=detail::win32::WaitForMultipleObjects(2,semaphores,true,detail::win32::infinite)<2; BOOST_ASSERT(success2); } } @@ -286,7 +286,7 @@ namespace boost return; } - unsigned long const res=::boost::detail::WaitForSingleObject(unlock_sem,BOOST_INFINITE); + unsigned long const res=detail::win32::WaitForSingleObject(unlock_sem,detail::win32::infinite); BOOST_ASSERT(res==0); } } @@ -343,7 +343,7 @@ namespace boost { if(!last_reader) { - unsigned long const res=::boost::detail::WaitForSingleObject(upgradeable_sem,BOOST_INFINITE); + unsigned long const res=detail::win32::WaitForSingleObject(upgradeable_sem,detail::win32::infinite); BOOST_ASSERT(res==0); } break; diff --git a/include/boost/thread/win32/thread_primitives.hpp b/include/boost/thread/win32/thread_primitives.hpp index f7597f3a..76fe13c5 100644 --- a/include/boost/thread/win32/thread_primitives.hpp +++ b/include/boost/thread/win32/thread_primitives.hpp @@ -3,7 +3,7 @@ // win32_thread_primitives.hpp // -// (C) Copyright 2005 Anthony Williams +// (C) Copyright 2005-6 Anthony Williams // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -13,79 +13,33 @@ #if defined( BOOST_USE_WINDOWS_H ) # include -# define BOOST_CLOSE_HANDLE ::CloseHandle -# define BOOST_RELEASE_MUTEX ::ReleaseMutex -# define BOOST_CREATE_MUTEX ::CreateMutexA -# define BOOST_GET_PROCESS_ID ::GetCurrentProcessId -# define BOOST_GET_CURRENT_THREAD_ID ::GetCurrentThreadId -# define BOOST_WAIT_FOR_SINGLE_OBJECT ::WaitForSingleObject -# define BOOST_CREATE_SEMAPHORE ::CreateSemaphoreA -# define BOOST_RELEASE_SEMAPHORE ::ReleaseSemaphore -# define BOOST_GET_CURRENT_THREAD ::GetCurrentThread -# define BOOST_GET_CURRENT_PROCESS ::GetCurrentProcess -# define BOOST_DUPLICATE_HANDLE ::DuplicateHandle -# define BOOST_SLEEP_EX ::SleepEx -# define BOOST_QUEUE_USER_APC ::QueueUserAPC -# define BOOST_INFINITE INFINITE namespace boost { namespace detail { - typedef ULONG_PTR ulong_ptr; - - extern "C" + namespace win32 { - inline BOOL CloseHandle(HANDLE h) - { - return ::CloseHandle(h); - } - inline int ReleaseMutex(HANDLE h) - { - return ::ReleaseMutex(h); - } - inline HANDLE CreateMutexA(::_SECURITY_ATTRIBUTES* sa,BOOL owner,char const* name) - { - return ::CreateMutexA(sa,owner,name); - } - inline HANDLE CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes,BOOL bManualReset, - BOOL bInitialState,LPCSTR lpName) - { - return ::CreateEventA(lpEventAttributes,bManualReset,bInitialState,lpName); - } + typedef ULONG_PTR ulong_ptr; + typedef HANDLE handle; + unsigned const infinite=INFINITE; - inline BOOL ReleaseSemaphore(HANDLE hSemaphore,LONG lReleaseCount,LPLONG lpPreviousCount) - { - return ::ReleaseSemaphore(hSemaphore,lReleaseCount,lpPreviousCount); - } - - inline HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,LONG lInitialCount, - LONG lMaximumCount,LPCSTR lpName) - { - return ::CreateSemaphoreA(lpSemaphoreAttributes,lInitialCount,lMaximumCount,lpName); - } - inline BOOL SetEvent(HANDLE hEvent) - { - return ::SetEvent(hEvent); - } - inline BOOL ResetEvent(HANDLE hEvent) - { - return ::ResetEvent(hEvent); - } - inline DWORD WaitForMultipleObjects(DWORD nCount,const HANDLE* lpHandles,BOOL bWaitAll,DWORD dwMilliseconds) - { - return ::WaitForMultipleObjects(nCount,lpHandles,bWaitAll,dwMilliseconds); - } - - -// inline unsigned long GetCurrentProcessId(); -// inline unsigned long GetCurrentThreadId(); -// inline unsigned long WaitForSingleObject(HANDLE,unsigned long); -// inline HANDLE GetCurrentThread(); -// inline HANDLE GetCurrentProcess(); -// inline int DuplicateHandle(HANDLE,HANDLE,HANDLE,HANDLE*,unsigned long,int,unsigned long); -// inline unsigned long SleepEx(unsigned long,int); -// typedef void (*queue_user_apc_callback_function)(ulong_ptr); -// inline unsigned long QueueUserAPC(queue_user_apc_callback_function,HANDLE,ulong_ptr); + using ::CreateMutexA; + using ::CreateEventA; + using ::CreateSemaphoreA; + using ::CloseHandle; + using ::ReleaseMutex; + using ::ReleaseSemaphore; + using ::SetEvent; + using ::ResetEvent; + using ::WaitForMultipleObjects; + using ::WaitForSingleObject; + using ::GetCurrentProcessId; + using ::GetCurrentThreadId; + using ::GetCurrentThread; + using ::GetCurrentProcess; + using ::DuplicateHandle; + using ::SleepEx; + using ::QueueUserAPC; } } } @@ -94,53 +48,76 @@ namespace boost { namespace detail { -# ifdef _WIN64 - typedef unsigned __int64 ulong_ptr; -# else - typedef unsigned long ulong_ptr; -# endif - - extern "C" + namespace win32 { - __declspec(dllimport) int __stdcall CloseHandle(void*); - __declspec(dllimport) int __stdcall ReleaseMutex(void*); - struct _SECURITY_ATTRIBUTES; - __declspec(dllimport) void* __stdcall CreateMutexA(_SECURITY_ATTRIBUTES*,int,char const*); - __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId(); - __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(); - __declspec(dllimport) unsigned long __stdcall WaitForSingleObject(void*,unsigned long); - __declspec(dllimport) int __stdcall ReleaseSemaphore(void*,long,long*); - __declspec(dllimport) void* __stdcall CreateSemaphoreA(_SECURITY_ATTRIBUTES*,long,long,char const*); - __declspec(dllimport) void* __stdcall GetCurrentThread(); - __declspec(dllimport) void* __stdcall GetCurrentProcess(); - __declspec(dllimport) int __stdcall DuplicateHandle(void*,void*,void*,void**,unsigned long,int,unsigned long); - __declspec(dllimport) unsigned long __stdcall SleepEx(unsigned long,int); - 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) void* __stdcall CreateEventA(_SECURITY_ATTRIBUTES*,int,int,char const*); - __declspec(dllimport) int __stdcall SetEvent(void*); - __declspec(dllimport) int __stdcall ResetEvent(void*); - __declspec(dllimport) unsigned long __stdcall WaitForMultipleObjects(unsigned long nCount,void* const * lpHandles,int bWaitAll,unsigned long dwMilliseconds); + +# ifdef _WIN64 + typedef unsigned __int64 ulong_ptr; +# else + typedef unsigned long ulong_ptr; +# endif + typedef void* handle; + unsigned const infinite=~0U; + + extern "C" + { + struct _SECURITY_ATTRIBUTES; + __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) int __stdcall CloseHandle(void*); + __declspec(dllimport) int __stdcall ReleaseMutex(void*); + __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId(); + __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(); + __declspec(dllimport) unsigned long __stdcall WaitForSingleObject(void*,unsigned long); + __declspec(dllimport) int __stdcall ReleaseSemaphore(void*,long,long*); + __declspec(dllimport) void* __stdcall GetCurrentThread(); + __declspec(dllimport) void* __stdcall GetCurrentProcess(); + __declspec(dllimport) int __stdcall DuplicateHandle(void*,void*,void*,void**,unsigned long,int,unsigned long); + __declspec(dllimport) unsigned long __stdcall SleepEx(unsigned long,int); + 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) int __stdcall SetEvent(void*); + __declspec(dllimport) int __stdcall ResetEvent(void*); + __declspec(dllimport) unsigned long __stdcall WaitForMultipleObjects(unsigned long nCount,void* const * lpHandles,int bWaitAll,unsigned long dwMilliseconds); + } } } } -# define BOOST_CLOSE_HANDLE ::boost::detail::CloseHandle -# define BOOST_RELEASE_MUTEX ::boost::detail::ReleaseMutex -# define BOOST_CREATE_MUTEX ::boost::detail::CreateMutexA -# define BOOST_GET_PROCESS_ID ::boost::detail::GetCurrentProcessId -# define BOOST_GET_CURRENT_THREAD_ID ::boost::detail::GetCurrentThreadId -# define BOOST_WAIT_FOR_SINGLE_OBJECT ::boost::detail::WaitForSingleObject -# define BOOST_CREATE_SEMAPHORE ::boost::detail::CreateSemaphoreA -# define BOOST_RELEASE_SEMAPHORE ::boost::detail::ReleaseSemaphore -# define BOOST_GET_CURRENT_THREAD ::boost::detail::GetCurrentThread -# define BOOST_GET_CURRENT_PROCESS ::boost::detail::GetCurrentProcess -# define BOOST_DUPLICATE_HANDLE ::boost::detail::DuplicateHandle -# define BOOST_SLEEP_EX ::boost::detail::SleepEx -# define BOOST_QUEUE_USER_APC ::boost::detail::QueueUserAPC -# define BOOST_INFINITE 0xffffffff #else # error "Win32 functions not available" #endif +namespace boost +{ + namespace detail + { + namespace win32 + { + enum event_type + { + auto_reset_event=false, + manual_reset_event=true + }; + + enum initial_event_state + { + event_initially_reset=false, + event_initially_set=true + }; + + inline handle create_anonymous_event(event_type type,initial_event_state state) + { + return CreateEventA(0,type,state,0); + } + + inline handle create_anonymous_semaphore(long initial_count,long max_count) + { + return CreateSemaphoreA(NULL,initial_count,max_count,NULL); + } + } + } +} + #endif diff --git a/include/boost/thread/win32/xtime_utils.hpp b/include/boost/thread/win32/xtime_utils.hpp index 52e72a8d..eb0523f7 100644 --- a/include/boost/thread/win32/xtime_utils.hpp +++ b/include/boost/thread/win32/xtime_utils.hpp @@ -19,8 +19,8 @@ namespace boost inline ::boost::xtime get_xtime_sentinel() { boost::xtime const sentinel={ - std::numeric_limits::max(), - std::numeric_limits::max() + (std::numeric_limits::max)(), + (std::numeric_limits::max)() }; return sentinel; @@ -35,7 +35,7 @@ namespace boost { if(!boost::xtime_cmp(target,get_xtime_sentinel())) { - return std::numeric_limits::max(); + return (std::numeric_limits::max)(); } boost::xtime now; @@ -66,7 +66,7 @@ namespace boost } // we are throwing away some bits, but one second after having // waited for 49 years does not really matter ... - if (target.sec < std::numeric_limits::max()/milliseconds_per_second) + if (target.sec < (std::numeric_limits::max)()/milliseconds_per_second) { return static_cast( target.sec*milliseconds_per_second + @@ -74,7 +74,7 @@ namespace boost } else { - return std::numeric_limits::max(); + return (std::numeric_limits::max)(); } } }