Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75860 - trunk/libs/thread/src/win32
From: vicente.botet_at_[hidden]
Date: 2011-12-07 18:15:21


Author: viboes
Date: 2011-12-07 18:15:20 EST (Wed, 07 Dec 2011)
New Revision: 75860
URL: http://svn.boost.org/trac/boost/changeset/75860

Log:
Thread: #6200-mutex error better handle EINTR
Text files modified:
   trunk/libs/thread/src/win32/thread.cpp | 64 +++++++++++++++++++++------------------
   1 files changed, 34 insertions(+), 30 deletions(-)

Modified: trunk/libs/thread/src/win32/thread.cpp
==============================================================================
--- trunk/libs/thread/src/win32/thread.cpp (original)
+++ trunk/libs/thread/src/win32/thread.cpp 2011-12-07 18:15:20 EST (Wed, 07 Dec 2011)
@@ -20,6 +20,7 @@
 #include <boost/thread/detail/tss_hooks.hpp>
 #include <boost/date_time/posix_time/conversion.hpp>
 #include <windows.h>
+#include <memory>
 
 namespace boost
 {
@@ -80,22 +81,25 @@
 
         DWORD WINAPI ThreadProxy(LPVOID args)
         {
- ThreadProxyData* data=reinterpret_cast<ThreadProxyData*>(args);
+ autp_ptr<ThreadProxyData> data=reinterpret_cast<ThreadProxyData*>(args);
             DWORD ret=data->start_address_(data->arglist_);
- delete data;
             return ret;
         }
-
+
         typedef void* uintptr_t;
 
         inline uintptr_t const _beginthreadex(void* security, unsigned stack_size, unsigned (__stdcall* start_address)(void*),
                                               void* arglist, unsigned initflag, unsigned* thrdaddr)
         {
             DWORD threadID;
+ ThreadProxyData* data = new ThreadProxyData(start_address,arglist);
             HANDLE hthread=CreateThread(static_cast<LPSECURITY_ATTRIBUTES>(security),stack_size,ThreadProxy,
- new ThreadProxyData(start_address,arglist),initflag,&threadID);
- if (hthread!=0)
- *thrdaddr=threadID;
+ data,initflag,&threadID);
+ if (hthread==0) {
+ delete data;
+ return 0;
+ }
+ *thrdaddr=threadID;
             return reinterpret_cast<uintptr_t const>(hthread);
         }
 
@@ -162,11 +166,11 @@
                         boost::detail::heap_delete(current_node);
                     }
                 }
-
+
                 set_current_thread_data(0);
             }
         }
-
+
         unsigned __stdcall thread_start_function(void* param)
         {
             detail::thread_data_base* const thread_info(reinterpret_cast<detail::thread_data_base*>(param));
@@ -218,7 +222,7 @@
                 ++count;
                 interruption_enabled=false;
             }
-
+
             void run()
             {}
         private:
@@ -250,14 +254,14 @@
             }
             return current_thread_data;
         }
-
+
     }
 
     thread::~thread()
     {
         detach();
     }
-
+
     thread::id thread::get_id() const
     {
         return thread::id((get_thread_info)());
@@ -291,7 +295,7 @@
         }
         return true;
     }
-
+
     void thread::detach()
     {
         release_handle();
@@ -301,7 +305,7 @@
     {
         thread_info=0;
     }
-
+
     void thread::interrupt()
     {
         detail::thread_data_ptr local_thread_info=(get_thread_info)();
@@ -310,20 +314,20 @@
             local_thread_info->interrupt();
         }
     }
-
+
     bool thread::interruption_requested() const
     {
         detail::thread_data_ptr local_thread_info=(get_thread_info)();
         return local_thread_info.get() && (detail::win32::WaitForSingleObject(local_thread_info->interruption_handle,0)==0);
     }
-
+
     unsigned thread::hardware_concurrency()
     {
         SYSTEM_INFO info={{0}};
         GetSystemInfo(&info);
         return info.dwNumberOfProcessors;
     }
-
+
     thread::native_handle_type thread::native_handle()
     {
         detail::thread_data_ptr local_thread_info=(get_thread_info)();
@@ -374,7 +378,7 @@
                             target_time.abs_time.time_of_day().ticks_per_second();
                         if(ticks_per_second>hundred_nanoseconds_in_one_second)
                         {
- posix_time::time_duration::tick_type const
+ posix_time::time_duration::tick_type const
                                 ticks_per_hundred_nanoseconds=
                                 ticks_per_second/hundred_nanoseconds_in_one_second;
                             due_time.QuadPart+=
@@ -392,7 +396,7 @@
                 return due_time;
             }
         }
-
+
 
         bool interruptible_wait(detail::win32::handle handle_to_wait_for,detail::timeout target_time)
         {
@@ -413,10 +417,10 @@
             }
 
             detail::win32::handle_manager timer_handle;
-
+
 #ifndef UNDER_CE
             unsigned const min_timer_wait_period=20;
-
+
             if(!target_time.is_sentinel())
             {
                 detail::timeout::remaining_time const time_left=target_time.remaining_milliseconds();
@@ -427,7 +431,7 @@
                     if(timer_handle!=0)
                     {
                         LARGE_INTEGER due_time=get_due_time(target_time);
-
+
                         bool const set_time_succeeded=SetWaitableTimer(timer_handle,&due_time,0,0,0,false)!=0;
                         if(set_time_succeeded)
                         {
@@ -443,17 +447,17 @@
                 }
             }
 #endif
-
+
             bool const using_timer=timeout_index!=~0u;
             detail::timeout::remaining_time time_left(0);
-
+
             do
             {
                 if(!using_timer)
                 {
                     time_left=target_time.remaining_milliseconds();
                 }
-
+
                 if(handle_count)
                 {
                     unsigned long const notified_index=detail::win32::WaitForMultipleObjects(handle_count,handles,false,using_timer?INFINITE:time_left.milliseconds);
@@ -500,12 +504,12 @@
                 throw thread_interrupted();
             }
         }
-
+
         bool interruption_enabled()
         {
             return get_current_thread_data() && get_current_thread_data()->interruption_enabled;
         }
-
+
         bool interruption_requested()
         {
             return get_current_thread_data() && (detail::win32::WaitForSingleObject(get_current_thread_data()->interruption_handle,0)==0);
@@ -515,7 +519,7 @@
         {
             detail::win32::Sleep(0);
         }
-
+
         disable_interruption::disable_interruption():
             interruption_was_enabled(interruption_enabled())
         {
@@ -524,7 +528,7 @@
                 get_current_thread_data()->interruption_enabled=false;
             }
         }
-
+
         disable_interruption::~disable_interruption()
         {
             if(get_current_thread_data())
@@ -540,7 +544,7 @@
                 get_current_thread_data()->interruption_enabled=true;
             }
         }
-
+
         restore_interruption::~restore_interruption()
         {
             if(get_current_thread_data())
@@ -587,7 +591,7 @@
             }
             return NULL;
         }
-
+
         void set_tss_data(void const* key,boost::shared_ptr<tss_cleanup_function> func,void* tss_data,bool cleanup_existing)
         {
             if(tss_data_node* const current_node=find_tss_data(key))


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