Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63915 - in branches/release: boost boost/thread boost/thread/pthread boost/thread/win32 libs/thread libs/thread/test
From: anthony_at_[hidden]
Date: 2010-07-12 03:47:41


Author: anthonyw
Date: 2010-07-12 03:47:39 EDT (Mon, 12 Jul 2010)
New Revision: 63915
URL: http://svn.boost.org/trac/boost/changeset/63915

Log:
Marged changes to Boost.Thread from trunk
Properties modified:
   branches/release/boost/thread/ (props changed)
   branches/release/boost/thread.hpp (props changed)
   branches/release/libs/thread/ (props changed)
Text files modified:
   branches/release/boost/thread/future.hpp | 3
   branches/release/boost/thread/pthread/recursive_mutex.hpp | 1
   branches/release/boost/thread/win32/once.hpp | 125 +++++++++++++++++++++++----------------
   branches/release/boost/thread/win32/thread_primitives.hpp | 8 ++
   branches/release/libs/thread/test/test_futures.cpp | 2
   5 files changed, 88 insertions(+), 51 deletions(-)

Modified: branches/release/boost/thread/future.hpp
==============================================================================
--- branches/release/boost/thread/future.hpp (original)
+++ branches/release/boost/thread/future.hpp 2010-07-12 03:47:39 EDT (Mon, 12 Jul 2010)
@@ -554,6 +554,9 @@
     template<typename Iterator>
     typename boost::disable_if<is_future_type<Iterator>,Iterator>::type wait_for_any(Iterator begin,Iterator end)
     {
+ if(begin==end)
+ return end;
+
         detail::future_waiter waiter;
         for(Iterator current=begin;current!=end;++current)
         {

Modified: branches/release/boost/thread/pthread/recursive_mutex.hpp
==============================================================================
--- branches/release/boost/thread/pthread/recursive_mutex.hpp (original)
+++ branches/release/boost/thread/pthread/recursive_mutex.hpp 2010-07-12 03:47:39 EDT (Mon, 12 Jul 2010)
@@ -60,6 +60,7 @@
             int const set_attr_res=pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
             if(set_attr_res)
             {
+ BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
                 boost::throw_exception(thread_resource_error());
             }
             

Modified: branches/release/boost/thread/win32/once.hpp
==============================================================================
--- branches/release/boost/thread/win32/once.hpp (original)
+++ branches/release/boost/thread/win32/once.hpp 2010-07-12 03:47:39 EDT (Mon, 12 Jul 2010)
@@ -34,42 +34,85 @@
     {
         long status;
         long count;
- long throw_count;
- void* event_handle;
+ };
+
+#define BOOST_ONCE_INIT {0,0}
+
+ namespace detail
+ {
+#ifdef BOOST_NO_ANSI_APIS
+ typedef wchar_t once_char_type;
+#else
+ typedef char once_char_type;
+#endif
+ unsigned const once_mutex_name_fixed_length=54;
+ unsigned const once_mutex_name_length=once_mutex_name_fixed_length+
+ sizeof(void*)*2+sizeof(unsigned long)*2+1;
 
- ~once_flag()
+ template <class I>
+ void int_to_string(I p, once_char_type* buf)
         {
- if(count)
+ for(unsigned i=0; i < sizeof(I)*2; ++i,++buf)
             {
- BOOST_ASSERT(count==throw_count);
+#ifdef BOOST_NO_ANSI_APIS
+ once_char_type const a=L'A';
+#else
+ once_char_type const a='A';
+#endif
+ *buf = a + static_cast<once_char_type>((p >> (i*4)) & 0x0f);
             }
+ *buf = 0;
+ }
+
+ inline void name_once_mutex(once_char_type* mutex_name,void* flag_address)
+ {
+#ifdef BOOST_NO_ANSI_APIS
+ static const once_char_type fixed_mutex_name[]=L"Local\\{C15730E2-145C-4c5e-B005-3BC753F42475}-once-flag";
+#else
+ static const once_char_type fixed_mutex_name[]="Local\\{C15730E2-145C-4c5e-B005-3BC753F42475}-once-flag";
+#endif
+ BOOST_STATIC_ASSERT(sizeof(fixed_mutex_name) ==
+ (sizeof(once_char_type)*(once_mutex_name_fixed_length+1)));
             
- void* const old_event=BOOST_INTERLOCKED_EXCHANGE_POINTER(&event_handle,0);
- if(old_event)
+ 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(),
+ mutex_name + once_mutex_name_fixed_length + sizeof(void*)*2);
+ }
+
+ inline void* open_once_event(once_char_type* mutex_name,void* flag_address)
+ {
+ if(!*mutex_name)
             {
- ::boost::detail::win32::CloseHandle(old_event);
+ name_once_mutex(mutex_name,flag_address);
             }
+
+#ifdef BOOST_NO_ANSI_APIS
+ return ::boost::detail::win32::OpenEventW(
+#else
+ return ::boost::detail::win32::OpenEventA(
+#endif
+ ::boost::detail::win32::synchronize |
+ ::boost::detail::win32::event_modify_state,
+ false,
+ mutex_name);
         }
- };
 
-#define BOOST_ONCE_INIT {0,0,0,0}
-
- namespace detail
- {
- inline void* allocate_event_handle(void*& handle)
+ inline void* create_once_event(once_char_type* mutex_name,void* flag_address)
         {
- void* const new_handle=::boost::detail::win32::create_anonymous_event(
- ::boost::detail::win32::manual_reset_event,
- ::boost::detail::win32::event_initially_reset);
-
- void* event_handle=BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(&handle,
- new_handle,0);
- if(event_handle)
+ if(!*mutex_name)
             {
- ::boost::detail::win32::CloseHandle(new_handle);
- return event_handle;
+ name_once_mutex(mutex_name,flag_address);
             }
- return new_handle;
+#ifdef BOOST_NO_ANSI_APIS
+ return ::boost::detail::win32::CreateEventW(
+#else
+ return ::boost::detail::win32::CreateEventA(
+#endif
+ 0,::boost::detail::win32::manual_reset_event,
+ ::boost::detail::win32::event_initially_reset,
+ mutex_name);
         }
     }
     
@@ -83,8 +126,9 @@
         long const running_value=0x7f0725e3;
         long status;
         bool counted=false;
- void* event_handle=0;
- long throw_count=0;
+ detail::win32::handle_manager event_handle;
+ detail::once_char_type mutex_name[detail::once_mutex_name_length];
+ mutex_name[0]=0;
 
         while((status=::boost::detail::interlocked_read_acquire(&flag.status))
               !=function_complete_flag_value)
@@ -96,7 +140,7 @@
                 {
                     if(!event_handle)
                     {
- event_handle=::boost::detail::interlocked_read_acquire(&flag.event_handle);
+ event_handle=detail::open_once_event(mutex_name,&flag);
                     }
                     if(event_handle)
                     {
@@ -112,25 +156,20 @@
                     if(!event_handle &&
                        (::boost::detail::interlocked_read_acquire(&flag.count)>1))
                     {
- event_handle=::boost::detail::allocate_event_handle(flag.event_handle);
+ event_handle=detail::create_once_event(mutex_name,&flag);
                     }
                     if(event_handle)
                     {
                         ::boost::detail::win32::SetEvent(event_handle);
                     }
- throw_count=::boost::detail::interlocked_read_acquire(&flag.throw_count);
                     break;
                 }
                 catch(...)
                 {
- if(counted)
- {
- BOOST_INTERLOCKED_INCREMENT(&flag.throw_count);
- }
                     BOOST_INTERLOCKED_EXCHANGE(&flag.status,0);
                     if(!event_handle)
                     {
- event_handle=::boost::detail::interlocked_read_acquire(&flag.event_handle);
+ event_handle=detail::open_once_event(mutex_name,&flag);
                     }
                     if(event_handle)
                     {
@@ -149,31 +188,15 @@
                 {
                     break;
                 }
- event_handle=::boost::detail::interlocked_read_acquire(&flag.event_handle);
                 if(!event_handle)
                 {
- event_handle=::boost::detail::allocate_event_handle(flag.event_handle);
+ event_handle=detail::create_once_event(mutex_name,&flag);
                     continue;
                 }
             }
             BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObject(
                              event_handle,::boost::detail::win32::infinite));
         }
- if(counted || throw_count)
- {
- if(!BOOST_INTERLOCKED_EXCHANGE_ADD(&flag.count,(counted?-1:0)-throw_count))
- {
- if(!event_handle)
- {
- event_handle=::boost::detail::interlocked_read_acquire(&flag.event_handle);
- }
- if(event_handle)
- {
- BOOST_INTERLOCKED_EXCHANGE_POINTER(&flag.event_handle,0);
- ::boost::detail::win32::CloseHandle(event_handle);
- }
- }
- }
     }
 }
 

Modified: branches/release/boost/thread/win32/thread_primitives.hpp
==============================================================================
--- branches/release/boost/thread/win32/thread_primitives.hpp (original)
+++ branches/release/boost/thread/win32/thread_primitives.hpp 2010-07-12 03:47:39 EDT (Mon, 12 Jul 2010)
@@ -31,14 +31,18 @@
             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;
 
 # ifdef BOOST_NO_ANSI_APIS
             using ::CreateMutexW;
             using ::CreateEventW;
+ using ::OpenEventW;
             using ::CreateSemaphoreW;
 # else
             using ::CreateMutexA;
             using ::CreateEventA;
+ using ::OpenEventA;
             using ::CreateSemaphoreA;
 # endif
             using ::CloseHandle;
@@ -100,6 +104,8 @@
             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;
 
             extern "C"
             {
@@ -108,10 +114,12 @@
                 __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*);
+ __declspec(dllimport) void* __stdcall OpenEventW(unsigned long,int,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*);
 # endif
                 __declspec(dllimport) int __stdcall CloseHandle(void*);
                 __declspec(dllimport) int __stdcall ReleaseMutex(void*);

Modified: branches/release/libs/thread/test/test_futures.cpp
==============================================================================
--- branches/release/libs/thread/test/test_futures.cpp (original)
+++ branches/release/libs/thread/test/test_futures.cpp 2010-07-12 03:47:39 EDT (Mon, 12 Jul 2010)
@@ -1041,6 +1041,8 @@
         }
         boost::thread(::cast_to_rval(tasks[i]));
     
+ BOOST_CHECK(boost::wait_for_any(futures,futures)==futures);
+
         boost::unique_future<int>* const future=boost::wait_for_any(futures,futures+count);
     
         BOOST_CHECK(future==(futures+i));


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk