Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57889 - trunk/boost/thread/win32
From: anthony_at_[hidden]
Date: 2009-11-24 06:52:09


Author: anthonyw
Date: 2009-11-24 06:52:09 EST (Tue, 24 Nov 2009)
New Revision: 57889
URL: http://svn.boost.org/trac/boost/changeset/57889

Log:
Ensure call_once event is correctly cleaned up
Text files modified:
   trunk/boost/thread/win32/once.hpp | 33 +++++++++++++++++++++++++++++++--
   1 files changed, 31 insertions(+), 2 deletions(-)

Modified: trunk/boost/thread/win32/once.hpp
==============================================================================
--- trunk/boost/thread/win32/once.hpp (original)
+++ trunk/boost/thread/win32/once.hpp 2009-11-24 06:52:09 EST (Tue, 24 Nov 2009)
@@ -36,6 +36,20 @@
         long count;
         long throw_count;
         void* event_handle;
+
+ ~once_flag()
+ {
+ if(count)
+ {
+ BOOST_ASSERT(count==throw_count);
+ }
+
+ void* const old_event=BOOST_INTERLOCKED_EXCHANGE_POINTER(&event_handle,0);
+ if(old_event)
+ {
+ ::boost::detail::win32::CloseHandle(old_event);
+ }
+ }
     };
 
 #define BOOST_ONCE_INIT {0,0,0,0}
@@ -80,6 +94,14 @@
             {
                 try
                 {
+ if(!event_handle)
+ {
+ event_handle=::boost::detail::interlocked_read_acquire(&flag.event_handle);
+ }
+ if(event_handle)
+ {
+ ::boost::detail::win32::ResetEvent(event_handle);
+ }
                     f();
                     if(!counted)
                     {
@@ -106,6 +128,14 @@
                         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);
+ }
+ if(event_handle)
+ {
+ ::boost::detail::win32::SetEvent(event_handle);
+ }
                     throw;
                 }
             }
@@ -130,7 +160,7 @@
         }
         if(counted || throw_count)
         {
- if(!BOOST_INTERLOCKED_EXCHANGE_ADD(&flag.count,(counted?1:0)+throw_count))
+ if(!BOOST_INTERLOCKED_EXCHANGE_ADD(&flag.count,(counted?-1:0)-throw_count))
             {
                 if(!event_handle)
                 {
@@ -143,7 +173,6 @@
                 }
             }
         }
-
     }
 }
 


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