$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r86201 - in trunk/boost/sync: detail detail/condition_variables detail/event detail/mutexes detail/semaphore locks
From: andrey.semashev_at_[hidden]
Date: 2013-10-08 13:05:55
Author: andysem
Date: 2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)
New Revision: 86201
URL: http://svn.boost.org/trac/boost/changeset/86201
Log:
Optimized exception throwing and other code to help inlining. Windows mutex implementation now throws in case of errors.
Added:
   trunk/boost/sync/detail/throw_exception.hpp   (contents, props changed)
Text files modified: 
   trunk/boost/sync/detail/auto_handle.hpp                                          |     4                                         
   trunk/boost/sync/detail/condition_variables/basic_condition_variable_windows.hpp |    38 ++++++-                                 
   trunk/boost/sync/detail/condition_variables/condition_variable_posix.hpp         |     8                                         
   trunk/boost/sync/detail/condition_variables/condition_variable_windows.hpp       |     8                                         
   trunk/boost/sync/detail/event/event_windows.hpp                                  |    12 +-                                      
   trunk/boost/sync/detail/mutexes/basic_mutex_windows.hpp                          |    75 ++++++++++-----                         
   trunk/boost/sync/detail/mutexes/mutex_posix.hpp                                  |    10 +-                                      
   trunk/boost/sync/detail/mutexes/timed_mutex_posix.hpp                            |    14 +-                                      
   trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp                          |   157 +++++++++++++++++----------------       
   trunk/boost/sync/detail/semaphore/semaphore_dispatch.hpp                         |     4                                         
   trunk/boost/sync/detail/semaphore/semaphore_mach.hpp                             |     4                                         
   trunk/boost/sync/detail/semaphore/semaphore_posix.hpp                            |     6                                         
   trunk/boost/sync/detail/semaphore/semaphore_windows.hpp                          |    13 +-                                      
   trunk/boost/sync/detail/throw_exception.hpp                                      |   187 ++++++++++++++++++++++++++++++++++++++++
   trunk/boost/sync/detail/waitable_timer.hpp                                       |    10 +-                                      
   trunk/boost/sync/locks/shared_lock.hpp                                           |    26 ++--                                    
   trunk/boost/sync/locks/unique_lock.hpp                                           |    26 ++--                                    
   trunk/boost/sync/locks/upgrade_lock.hpp                                          |    26 ++--                                    
   18 files changed, 428 insertions(+), 200 deletions(-)
Modified: trunk/boost/sync/detail/auto_handle.hpp
==============================================================================
--- trunk/boost/sync/detail/auto_handle.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/auto_handle.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -21,11 +21,11 @@
 
 #include <cstddef>
 #include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/detail/winapi/handles.hpp>
 #include <boost/detail/winapi/GetLastError.hpp>
 #include <boost/detail/winapi/GetCurrentProcess.hpp>
 #include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
 #include <boost/sync/detail/header.hpp>
 
@@ -94,7 +94,7 @@
         if (boost::detail::winapi::DuplicateHandle(current_process, m_handle, current_process, &new_handle, 0, false, boost::detail::winapi::duplicate_same_access) == 0)
         {
             const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
-            BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync: failed to duplicate a handle"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync: failed to duplicate a handle"));
         }
         return new_handle;
     }
Modified: trunk/boost/sync/detail/condition_variables/basic_condition_variable_windows.hpp
==============================================================================
--- trunk/boost/sync/detail/condition_variables/basic_condition_variable_windows.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/condition_variables/basic_condition_variable_windows.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -22,7 +22,6 @@
 #include <vector>
 #include <algorithm>
 #include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/smart_ptr/intrusive_ptr.hpp>
 #include <boost/smart_ptr/intrusive_ref_counter.hpp>
 #include <boost/detail/winapi/synchronization.hpp>
@@ -30,6 +29,7 @@
 #include <boost/sync/locks/unique_lock_fwd.hpp>
 #include <boost/sync/exceptions/runtime_exception.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/detail/time_traits.hpp>
 #include <boost/sync/detail/time_units.hpp>
 #include <boost/sync/detail/interlocked.hpp>
@@ -63,13 +63,22 @@
 
 public:
     explicit cv_list_entry(auto_handle const& wake_sem):
-        m_semaphore(boost::detail::winapi::create_anonymous_semaphore(0, LONG_MAX)),
-        m_wake_sem(wake_sem.duplicate()),
         m_waiters(1),
         m_notified(false)
     {
+        m_semaphore.reset(boost::detail::winapi::create_anonymous_semaphore(0, LONG_MAX));
         if (!m_semaphore)
-            BOOST_THROW_EXCEPTION(resource_error("boost::sync::condition_variable: failed to create a semaphore"));
+        {
+            const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::condition_variable: failed to create a semaphore"));
+        }
+
+        m_wake_sem.reset(wake_sem.duplicate());
+        if (!m_wake_sem)
+        {
+            const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::condition_variable: failed to duplicate a semaphore handle"));
+        }
     }
 
     static bool no_waiters(intrusive_ptr< cv_list_entry > const& entry)
@@ -107,16 +116,24 @@
     {
         const boost::detail::winapi::DWORD_ res = boost::detail::winapi::WaitForSingleObject(m_semaphore, boost::detail::winapi::infinite);
         if (res != boost::detail::winapi::wait_object_0)
-            BOOST_THROW_EXCEPTION(runtime_exception(res, "boost::sync::condition_variable wait failed in WaitForSingleObject"));
+        {
+            const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
+            BOOST_SYNC_DETAIL_THROW(runtime_exception, (err)("boost::sync::condition_variable wait failed in WaitForSingleObject"));
+        }
+    }
+
+    bool timed_wait(sync::detail::system_time_point const& t)
+    {
+
     }
 
-    bool timed_wait(system_duration t)
+    bool timed_wait(sync::detail::system_duration t)
     {
         sync::detail::system_duration::native_type time_left = t.get();
         while (time_left > 0)
         {
-            const unsigned int dur = time_left > static_cast< unsigned int >(boost::detail::winapi::max_non_infinite_wait) ?
-                static_cast< unsigned int >(boost::detail::winapi::max_non_infinite_wait) : static_cast< unsigned int >(time_left);
+            const boost::detail::winapi::DWORD_ dur = time_left > boost::detail::winapi::max_non_infinite_wait ?
+                boost::detail::winapi::max_non_infinite_wait : static_cast< boost::detail::winapi::DWORD_ >(time_left);
             const boost::detail::winapi::DWORD_ res = boost::detail::winapi::WaitForSingleObject(m_semaphore, dur);
             switch (res)
             {
@@ -128,7 +145,10 @@
                 break;
 
             default:
-                BOOST_THROW_EXCEPTION(runtime_exception(res, "boost::sync::condition_variable timed_wait failed in WaitForSingleObject"));
+                {
+                    const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
+                    BOOST_SYNC_DETAIL_THROW(runtime_exception, (res)("boost::sync::condition_variable timed_wait failed in WaitForSingleObject"));
+                }
             }
         }
         return false;
Modified: trunk/boost/sync/detail/condition_variables/condition_variable_posix.hpp
==============================================================================
--- trunk/boost/sync/detail/condition_variables/condition_variable_posix.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/condition_variables/condition_variable_posix.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -19,7 +19,6 @@
 
 #include <cstddef>
 #include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/mpl/and.hpp>
 #include <boost/sync/detail/config.hpp>
@@ -30,6 +29,7 @@
 #include <boost/sync/detail/pthread.hpp>
 #include <boost/sync/detail/time_traits.hpp>
 #include <boost/sync/detail/time_units.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/condition_variables/cv_status.hpp>
 #include <boost/sync/detail/header.hpp>
 
@@ -75,7 +75,7 @@
     {
         int const res = pthread_cond_init(&m_cond, NULL);
         if (res)
-            BOOST_THROW_EXCEPTION(resource_error(res, "boost::sync::condition_variable constructor failed in pthread_cond_init"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (res)("boost::sync::condition_variable constructor failed in pthread_cond_init"));
     }
 #endif // defined(PTHREAD_COND_INITIALIZER)
 
@@ -100,7 +100,7 @@
         BOOST_ASSERT(lock.owns_lock());
         int const res = sync::detail::posix::pthread_cond_wait(&m_cond, lock.mutex()->native_handle());
         if (res != 0)
-            BOOST_THROW_EXCEPTION(runtime_exception(res, "boost::sync::condition_variable::wait failed in pthread_cond_wait"));
+            BOOST_SYNC_DETAIL_THROW(runtime_exception, (res)("boost::sync::condition_variable::wait failed in pthread_cond_wait"));
     }
 
     template< typename Mutex, typename Predicate >
@@ -214,7 +214,7 @@
         if (res == ETIMEDOUT)
             return cv_status::timeout;
         else if (res != 0)
-            BOOST_THROW_EXCEPTION(runtime_exception(res, "boost::sync::condition_variable timedwait failed in pthread_cond_timedwait"));
+            BOOST_SYNC_DETAIL_THROW(runtime_exception, (res)("boost::sync::condition_variable timedwait failed in pthread_cond_timedwait"));
         return cv_status::no_timeout;
     }
 
Modified: trunk/boost/sync/detail/condition_variables/condition_variable_windows.hpp
==============================================================================
--- trunk/boost/sync/detail/condition_variables/condition_variable_windows.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/condition_variables/condition_variable_windows.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -19,7 +19,6 @@
 
 #include <cstddef>
 #include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/mpl/and.hpp>
 #include <boost/sync/detail/config.hpp>
@@ -29,6 +28,7 @@
 #include <boost/sync/traits/is_condition_variable_compatible.hpp>
 #include <boost/sync/detail/time_traits.hpp>
 #include <boost/sync/detail/time_units.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/condition_variables/cv_status.hpp>
 #include <boost/sync/detail/header.hpp>
 
@@ -69,7 +69,7 @@
     {
         int const res = pthread_cond_init(&m_cond, NULL);
         if (res)
-            BOOST_THROW_EXCEPTION(resource_error(res, "boost::sync::condition_variable constructor failed in pthread_cond_init"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (res)("boost::sync::condition_variable constructor failed in pthread_cond_init"));
     }
 #endif // defined(PTHREAD_COND_INITIALIZER)
 
@@ -94,7 +94,7 @@
         BOOST_ASSERT(lock.owns_lock());
         int const res = sync::detail::posix::pthread_cond_wait(&m_cond, lock.mutex()->native_handle());
         if (res != 0)
-            BOOST_THROW_EXCEPTION(runtime_exception(res, "boost::sync::condition_variable::wait failed in pthread_cond_wait"));
+            BOOST_SYNC_DETAIL_THROW(runtime_exception, (res)("boost::sync::condition_variable::wait failed in pthread_cond_wait"));
     }
 
     template< typename Mutex, typename Predicate >
@@ -208,7 +208,7 @@
         if (res == ETIMEDOUT)
             return cv_status::timeout;
         else if (res != 0)
-            BOOST_THROW_EXCEPTION(runtime_exception(res, "boost::sync::condition_variable timedwait failed in pthread_cond_timedwait"));
+            BOOST_SYNC_DETAIL_THROW(runtime_exception, (res)("boost::sync::condition_variable timedwait failed in pthread_cond_timedwait"));
         return cv_status::no_timeout;
     }
 
Modified: trunk/boost/sync/detail/event/event_windows.hpp
==============================================================================
--- trunk/boost/sync/detail/event/event_windows.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/event/event_windows.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -11,12 +11,12 @@
 
 #include <cstddef>
 #include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/detail/winapi/GetLastError.hpp>
 #include <boost/detail/winapi/synchronization.hpp>
 #include <boost/detail/winapi/handles.hpp>
 
 #include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
 #include <boost/sync/detail/header.hpp>
 
@@ -42,7 +42,7 @@
         if (!handle_)
         {
             const DWORD_ err = boost::detail::winapi::GetLastError();
-            BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::event constructor failed in CreateEvent"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::event constructor failed in CreateEvent"));
         }
     }
 
@@ -57,7 +57,7 @@
         if (status == 0)
         {
             const DWORD_ err = boost::detail::winapi::GetLastError();
-            BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::event::post failed in ReleaseEvent"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::event::post failed in ReleaseEvent"));
         }
     }
 
@@ -67,7 +67,7 @@
         if (status == 0)
         {
             const DWORD_ err = boost::detail::winapi::GetLastError();
-            BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::event::reset failed in ResetEvent"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::event::reset failed in ResetEvent"));
         }
     }
 
@@ -83,7 +83,7 @@
         case wait_failed:
             {
                 const DWORD_ err = boost::detail::winapi::GetLastError();
-                BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::event::wait failed in WaitForSingleObject"));
+                BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::event::wait failed in WaitForSingleObject"));
             }
 
         default:
@@ -126,7 +126,7 @@
         case wait_failed:
             {
                 const DWORD_ err = boost::detail::winapi::GetLastError();
-                BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::event::do_try_wait_for failed in WaitForSingleObject"));
+                BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::event::do_try_wait_for failed in WaitForSingleObject"));
             }
 
         default:
Modified: trunk/boost/sync/detail/mutexes/basic_mutex_windows.hpp
==============================================================================
--- trunk/boost/sync/detail/mutexes/basic_mutex_windows.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/mutexes/basic_mutex_windows.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -19,12 +19,13 @@
 
 #include <cstddef>
 #include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/detail/winapi/handles.hpp>
 #include <boost/detail/winapi/synchronization.hpp>
+#include <boost/detail/winapi/GetLastError.hpp>
+#include <boost/sync/detail/config.hpp>
 #include <boost/sync/exceptions/lock_error.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
-#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/detail/interlocked.hpp>
 
 #include <boost/sync/detail/header.hpp>
@@ -69,26 +70,8 @@
 
     void lock()
     {
-        if (try_lock())
-            return;
-
-        long old_count = m_active_count;
-        mark_waiting_and_try_lock(old_count);
-
-        if (old_count & lock_flag_value)
-        {
-            bool lock_acquired = false;
-            boost::detail::winapi::HANDLE_ const sem = get_event();
-
-            do
-            {
-                const boost::detail::winapi::DWORD_ retval = boost::detail::winapi::WaitForSingleObject(sem, boost::detail::winapi::infinite);
-                BOOST_ASSERT(0 == retval || boost::detail::winapi::wait_abandoned == retval);
-                clear_waiting_and_try_lock(old_count);
-                lock_acquired = (old_count & lock_flag_value) == 0;
-            }
-            while (!lock_acquired);
-        }
+        if (!try_lock())
+            priv_lock();
     }
 
     void unlock() BOOST_NOEXCEPT
@@ -115,20 +98,28 @@
 
         if (!event)
         {
-            event = boost::detail::winapi::CreateEventA(NULL, false, false, NULL);
+            event = boost::detail::winapi::create_anonymous_event(NULL, false, false);
+            if (event)
+            {
 #ifdef BOOST_MSVC
 #pragma warning(push)
 #pragma warning(disable:4311)
 #pragma warning(disable:4312)
 #endif
-            boost::detail::winapi::HANDLE_ const old_event = BOOST_ATOMIC_INTERLOCKED_COMPARE_EXCHANGE_POINTER(&m_event, event, NULL);
+                boost::detail::winapi::HANDLE_ const old_event = BOOST_ATOMIC_INTERLOCKED_COMPARE_EXCHANGE_POINTER(&m_event, event, NULL);
 #ifdef BOOST_MSVC
 #pragma warning(pop)
 #endif
-            if (old_event != NULL)
+                if (old_event != NULL)
+                {
+                    boost::detail::winapi::CloseHandle(event);
+                    return old_event;
+                }
+            }
+            else
             {
-                boost::detail::winapi::CloseHandle(event);
-                return old_event;
+                const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
+                BOOST_SYNC_DETAIL_THROW(resource_error, (err)("failed to create an event object"));
             }
         }
 
@@ -139,7 +130,7 @@
     {
         while (true)
         {
-            bool const was_locked = (old_count & lock_flag_value) ? true : false;
+            long const was_locked = (old_count & lock_flag_value);
             long const new_count = was_locked ? (old_count + 1) : (old_count | lock_flag_value);
             long const current = BOOST_ATOMIC_INTERLOCKED_COMPARE_EXCHANGE(&m_active_count, new_count, old_count);
             if (current == old_count)
@@ -169,6 +160,34 @@
 
     BOOST_DELETED_FUNCTION(basic_mutex(basic_mutex const&))
     BOOST_DELETED_FUNCTION(basic_mutex& operator= (basic_mutex const&))
+
+private:
+    void priv_lock()
+    {
+        long old_count = m_active_count;
+        mark_waiting_and_try_lock(old_count);
+
+        if (old_count & lock_flag_value) try
+        {
+            boost::detail::winapi::HANDLE_ const evt = get_event();
+            do
+            {
+                const boost::detail::winapi::DWORD_ retval = boost::detail::winapi::WaitForSingleObject(evt, boost::detail::winapi::infinite);
+                if (retval != boost::detail::winapi::wait_object_0)
+                {
+                    const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
+                    BOOST_SYNC_DETAIL_THROW(lock_error, (err)("failed to wait on the event object"));
+                }
+                clear_waiting_and_try_lock(old_count);
+            }
+            while (old_count & lock_flag_value);
+        }
+        catch (...)
+        {
+            BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_active_count, -1);
+            throw;
+        }
+    }
 };
 
 } // namespace windows
Modified: trunk/boost/sync/detail/mutexes/mutex_posix.hpp
==============================================================================
--- trunk/boost/sync/detail/mutexes/mutex_posix.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/mutexes/mutex_posix.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -19,10 +19,10 @@
 
 #include <cstddef>
 #include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
+#include <boost/sync/detail/config.hpp>
 #include <boost/sync/exceptions/lock_error.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
-#include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/detail/pthread.hpp>
 
 #include <boost/sync/detail/header.hpp>
@@ -72,7 +72,7 @@
         int const res = pthread_mutex_init(&m_mutex, NULL);
         if (res)
         {
-            BOOST_THROW_EXCEPTION(resource_error(res, "boost:: mutex constructor failed in pthread_mutex_init"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (res)("boost:: mutex constructor failed in pthread_mutex_init"));
         }
     }
 #endif // defined(PTHREAD_MUTEX_INITIALIZER)
@@ -87,7 +87,7 @@
         int const res = sync::detail::posix::pthread_mutex_lock(&m_mutex);
         if (res)
         {
-            BOOST_THROW_EXCEPTION(lock_error(res, "boost: mutex lock failed in pthread_mutex_lock"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (res)("boost: mutex lock failed in pthread_mutex_lock"));
         }
     }
 
@@ -103,7 +103,7 @@
         if (res == 0)
             return true;
         else if (res != EBUSY)
-            BOOST_THROW_EXCEPTION(lock_error(res, "boost: mutex trylock failed in pthread_mutex_trylock"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (res)("boost: mutex trylock failed in pthread_mutex_trylock"));
         return false;
     }
 
Modified: trunk/boost/sync/detail/mutexes/timed_mutex_posix.hpp
==============================================================================
--- trunk/boost/sync/detail/mutexes/timed_mutex_posix.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/mutexes/timed_mutex_posix.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -19,7 +19,6 @@
 
 #include <cstddef>
 #include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/sync/exceptions/lock_error.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
@@ -27,6 +26,7 @@
 #include <boost/sync/detail/pthread.hpp>
 #include <boost/sync/detail/time_traits.hpp>
 #include <boost/sync/detail/time_units.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #if !defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
 #include <boost/sync/detail/pthread_mutex_locks.hpp>
 #endif
@@ -91,12 +91,12 @@
     {
         int const res = pthread_mutex_init(&m_mutex, NULL);
         if (res)
-            BOOST_THROW_EXCEPTION(resource_error(res, "boost:: timed_mutex constructor failed in pthread_mutex_init"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (res)("boost:: timed_mutex constructor failed in pthread_mutex_init"));
 
 #if !defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
         int const res2 = pthread_cond_init(&m_cond, NULL);
         if (res2)
-            BOOST_THROW_EXCEPTION(resource_error(res2, "boost:: timed_mutex constructor failed in pthread_cond_init"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (res2)("boost:: timed_mutex constructor failed in pthread_cond_init"));
         m_is_locked = false;
 #endif
     }
@@ -116,7 +116,7 @@
     {
         int const res = sync::detail::posix::pthread_mutex_lock(&m_mutex);
         if (res)
-            BOOST_THROW_EXCEPTION(lock_error(res, "boost: timed_mutex lock failed in pthread_mutex_lock"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (res)("boost: timed_mutex lock failed in pthread_mutex_lock"));
     }
 
     void unlock() BOOST_NOEXCEPT
@@ -131,7 +131,7 @@
         if (res == 0)
             return true;
         else if (res != EBUSY)
-            BOOST_THROW_EXCEPTION(lock_error(res, "boost: timed_mutex trylock failed in pthread_mutex_trylock"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (res)("boost: timed_mutex trylock failed in pthread_mutex_trylock"));
         return false;
     }
 
@@ -206,7 +206,7 @@
         if (res == 0)
             return true;
         else if (res != ETIMEDOUT)
-            BOOST_THROW_EXCEPTION(lock_error(res, "boost: timed_mutex timedlock failed in pthread_mutex_timedlock"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (res)("boost: timed_mutex timedlock failed in pthread_mutex_timedlock"));
         return false;
 
 #else // defined(BOOST_SYNC_DETAIL_PTHREAD_HAS_TIMEDLOCK)
@@ -218,7 +218,7 @@
             if (cond_res == ETIMEDOUT)
                 return false;
             else if (cond_res != 0)
-                BOOST_THROW_EXCEPTION(lock_error(cond_res, "boost: timed_mutex timedlock failed in pthread_cond_timedwait"));
+                BOOST_SYNC_DETAIL_THROW(lock_error, (cond_res)("boost: timed_mutex timedlock failed in pthread_cond_timedwait"));
         }
         m_is_locked = true;
         return true;
Modified: trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp
==============================================================================
--- trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -20,11 +20,11 @@
 #include <cstddef>
 #include <boost/cstdint.hpp>
 #include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/detail/winapi/synchronization.hpp>
 #include <boost/sync/exceptions/lock_error.hpp>
 #include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/detail/interlocked.hpp>
 #include <boost/sync/detail/time_traits.hpp>
 #include <boost/sync/detail/time_units.hpp>
@@ -78,18 +78,27 @@
     template< typename Time >
     typename enable_if_c< sync::detail::time_traits< Time >::is_specialized, bool >::type timed_lock(Time const& t)
     {
+        if (m_mutex.try_lock())
+            return true;
+
         return priv_timed_lock(sync::detail::time_traits< Time >::to_sync_unit(t));
     }
 
     template< typename Duration >
     typename detail::enable_if_tag< Duration, detail::time_duration_tag, bool >::type try_lock_for(Duration const& rel_time)
     {
+        if (m_mutex.try_lock())
+            return true;
+
         return priv_timed_lock(sync::detail::time_traits< Duration >::to_sync_unit(rel_time));
     }
 
     template< typename TimePoint >
     typename detail::enable_if_tag< TimePoint, detail::time_point_tag, bool >::type try_lock_until(TimePoint const& abs_time)
     {
+        if (m_mutex.try_lock())
+            return true;
+
         return priv_timed_lock(sync::detail::time_traits< TimePoint >::to_sync_unit(abs_time));
     }
 
@@ -99,90 +108,106 @@
 private:
     bool priv_timed_lock(sync::detail::system_time_point const& t)
     {
-        if (m_mutex.try_lock())
-            return true;
-
         long old_count = m_mutex.m_active_count;
         m_mutex.mark_waiting_and_try_lock(old_count);
         if ((old_count & sync::detail::windows::basic_mutex::lock_flag_value) == 0)
             return true;
 
-        boost::detail::winapi::HANDLE_ handles[2];
-        handles[0] = m_mutex.get_event();
-        handles[1] = sync::detail::windows::get_waitable_timer();
-
-        if (!boost::detail::winapi::SetWaitableTimer(handles[1], reinterpret_cast< const boost::detail::winapi::LARGE_INTEGER_* >(&t.get()), 0, NULL, NULL, false))
-            abort_lock_and_throw("boost: timed_mutex timedlock failed to set a timeout", __LINE__);
-
-        while (true)
+        try
         {
-            const boost::detail::winapi::DWORD_ res = boost::detail::winapi::WaitForMultipleObjects(sizeof(handles) / sizeof(*handles), handles, false, boost::detail::winapi::infinite);
-            if (res == boost::detail::winapi::wait_failed)
-                abort_lock_and_throw("boost: timed_mutex timedlock failed in WaitForMultipleObjects", __LINE__);
+            boost::detail::winapi::HANDLE_ handles[2];
+            handles[0] = m_mutex.get_event();
+            handles[1] = sync::detail::windows::get_waitable_timer();
 
-            switch (res)
+            if (!boost::detail::winapi::SetWaitableTimer(handles[1], reinterpret_cast< const boost::detail::winapi::LARGE_INTEGER_* >(&t.get()), 0, NULL, NULL, false))
             {
-            case boost::detail::winapi::wait_object_0:
-                m_mutex.clear_waiting_and_try_lock(old_count);
-                if ((old_count & sync::detail::windows::basic_mutex::lock_flag_value) == 0)
-                    return true;
-                break;
-
-            case boost::detail::winapi::wait_object_0 + 1:
-                BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
-                return false;
+                const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
+                BOOST_SYNC_DETAIL_THROW(lock_error, (err)("timed_mutex::timedlock failed to set a timeout"));
+            }
 
-            default:
-                BOOST_ASSERT(false);
+            while (true)
+            {
+                const boost::detail::winapi::DWORD_ res = boost::detail::winapi::WaitForMultipleObjects(sizeof(handles) / sizeof(*handles), handles, false, boost::detail::winapi::infinite);
+                if (res == boost::detail::winapi::wait_failed)
+                {
+                    const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
+                    BOOST_SYNC_DETAIL_THROW(lock_error, (err)("timed_mutex::timedlock failed in WaitForMultipleObjects"));
+                }
+
+                switch (res)
+                {
+                case boost::detail::winapi::wait_object_0:
+                    m_mutex.clear_waiting_and_try_lock(old_count);
+                    if ((old_count & sync::detail::windows::basic_mutex::lock_flag_value) == 0)
+                        return true;
+                    break;
+
+                case boost::detail::winapi::wait_object_0 + 1:
+                    BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
+                    return false;
+
+                default:
+                    BOOST_ASSERT(false);
+                }
             }
         }
+        catch (...)
+        {
+            BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
+            throw;
+        }
     }
 
     bool priv_timed_lock(sync::detail::system_duration const& t)
     {
-        if (m_mutex.try_lock())
-            return true;
-
         long old_count = m_mutex.m_active_count;
         m_mutex.mark_waiting_and_try_lock(old_count);
         if ((old_count & sync::detail::windows::basic_mutex::lock_flag_value) == 0)
             return true;
 
-        const boost::detail::winapi::HANDLE_ evt = m_mutex.get_event();
-        sync::detail::system_duration::native_type time_left = t.get();
-        while (time_left > 0)
+        try
         {
-            const unsigned int dur = time_left > static_cast< unsigned int >(boost::detail::winapi::max_non_infinite_wait) ?
-                static_cast< unsigned int >(boost::detail::winapi::max_non_infinite_wait) : static_cast< unsigned int >(time_left);
-            const boost::detail::winapi::DWORD_ res = boost::detail::winapi::WaitForSingleObject(evt, dur);
-            switch (res)
+            const boost::detail::winapi::HANDLE_ evt = m_mutex.get_event();
+            sync::detail::system_duration::native_type time_left = t.get();
+            while (time_left > 0)
             {
-            case boost::detail::winapi::wait_object_0:
-                m_mutex.clear_waiting_and_try_lock(old_count);
-                if ((old_count & sync::detail::windows::basic_mutex::lock_flag_value) == 0)
-                    return true;
-                break;
-
-            case boost::detail::winapi::wait_timeout:
-                time_left -= dur;
-                break;
-
-            default:
-                abort_lock_and_throw("boost: timed_mutex timedlock failed in WaitForSingleObject", __LINE__);
+                const boost::detail::winapi::DWORD_ dur = time_left > boost::detail::winapi::max_non_infinite_wait ?
+                    boost::detail::winapi::max_non_infinite_wait : static_cast< boost::detail::winapi::DWORD_ >(time_left);
+                const boost::detail::winapi::DWORD_ res = boost::detail::winapi::WaitForSingleObject(evt, dur);
+                switch (res)
+                {
+                case boost::detail::winapi::wait_object_0:
+                    m_mutex.clear_waiting_and_try_lock(old_count);
+                    if ((old_count & sync::detail::windows::basic_mutex::lock_flag_value) == 0)
+                        return true;
+                    break;
+
+                case boost::detail::winapi::wait_timeout:
+                    time_left -= dur;
+                    break;
+
+                default:
+                    {
+                        const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
+                        BOOST_SYNC_DETAIL_THROW(lock_error, (err)("timed_mutex::timedlock failed in WaitForSingleObject"));
+                    }
+                }
             }
-        }
 
-        BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
+            BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
 
-        return false;
+            return false;
+        }
+        catch (...)
+        {
+            BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
+            throw;
+        }
     }
 
     template< typename TimePoint >
     bool priv_timed_lock(sync::detail::chrono_time_point< TimePoint > const& t)
     {
-        if (m_mutex.try_lock())
-            return true;
-
         typedef TimePoint time_point;
         typedef typename time_point::clock clock;
         typedef typename time_point::duration duration;
@@ -195,28 +220,6 @@
         }
         return false;
     }
-
-    BOOST_NOINLINE BOOST_ATTRIBUTE_NORETURN void abort_lock_and_throw(const char* descr, int line)
-    {
-        const boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
-        BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
-#if !defined(BOOST_EXCEPTION_DISABLE)
-        boost::throw_exception
-        (
-            set_info
-            (
-                set_info
-                (
-                    enable_error_info(lock_error(err, descr)),
-                    throw_file(__FILE__)
-                ),
-                throw_line(line)
-            )
-        );
-#else
-        boost::throw_exception(lock_error(err, descr));
-#endif
-    }
 };
 
 } // namespace winnt
Modified: trunk/boost/sync/detail/semaphore/semaphore_dispatch.hpp
==============================================================================
--- trunk/boost/sync/detail/semaphore/semaphore_dispatch.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/semaphore/semaphore_dispatch.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -12,8 +12,8 @@
 #include <cstddef>
 #include <dispatch/dispatch.h>
 
-#include <boost/throw_exception.hpp>
 #include <boost/sync/detail/config.hpp>
+#include <boost/sync_detail/throw_exception.hpp>
 #include <boost/sync/detail/system_error.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
 
@@ -44,7 +44,7 @@
     {
         m_sem = dispatch_semaphore_create(i);
         if (m_sem == NULL)
-            BOOST_THROW_EXCEPTION(resource_error(sync::detail::system_ns::errc::not_enough_memory, "boost::sync::semaphore constructor failed in dispatch_semaphore_create"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (sync::detail::system_ns::errc::not_enough_memory)("boost::sync::semaphore constructor failed in dispatch_semaphore_create"));
     }
 
     ~semaphore() BOOST_NOEXCEPT
Modified: trunk/boost/sync/detail/semaphore/semaphore_mach.hpp
==============================================================================
--- trunk/boost/sync/detail/semaphore/semaphore_mach.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/semaphore/semaphore_mach.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -11,8 +11,8 @@
 
 #include <cstddef>
 
-#include <boost/throw_exception.hpp>
 #include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/detail/system_error.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
 
@@ -48,7 +48,7 @@
     {
         kern_return_t result = semaphore_create(mach_task_self(), &m_sem, SYNC_POLICY_FIFO, i);
         if (result != KERN_SUCCESS)
-            BOOST_THROW_EXCEPTION(resource_error(sync::detail::system_ns::errc::not_enough_memory, "boost::sync::semaphore constructor failed in semaphore_create"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (sync::detail::system_ns::errc::not_enough_memory)("boost::sync::semaphore constructor failed in semaphore_create"));
     }
 
     ~semaphore() BOOST_NOEXCEPT
Modified: trunk/boost/sync/detail/semaphore/semaphore_posix.hpp
==============================================================================
--- trunk/boost/sync/detail/semaphore/semaphore_posix.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/semaphore/semaphore_posix.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -14,8 +14,8 @@
 #include <semaphore.h>
 
 #include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
 
 #ifdef BOOST_SYNC_USES_CHRONO
@@ -47,7 +47,7 @@
         if (status)
         {
             const int err = errno;
-            BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::semaphore constructor failed in sem_init"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::semaphore constructor failed in sem_init"));
         }
     }
 
@@ -66,7 +66,7 @@
         switch (err)
         {
         case EOVERFLOW:
-            BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::semaphore post failed: maximum allowable value would be exceeded"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::semaphore post failed: maximum allowable value would be exceeded"));
             break;
 
         case EINVAL:
Modified: trunk/boost/sync/detail/semaphore/semaphore_windows.hpp
==============================================================================
--- trunk/boost/sync/detail/semaphore/semaphore_windows.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/semaphore/semaphore_windows.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -14,8 +14,8 @@
 #include <boost/detail/winapi/GetLastError.hpp>
 #include <boost/detail/winapi/synchronization.hpp>
 #include <boost/detail/winapi/handles.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/sync/detail/config.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
 #include <boost/sync/detail/header.hpp>
 
@@ -46,14 +46,13 @@
         if (!m_sem)
         {
             const DWORD_ err = boost::detail::winapi::GetLastError();
-            BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::semaphore constructor failed in CreateSemaphore"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::semaphore constructor failed in CreateSemaphore"));
         }
     }
 
     ~semaphore() BOOST_NOEXCEPT
     {
-        int status = boost::detail::winapi::CloseHandle(m_sem);
-        BOOST_VERIFY (status != 0);
+        BOOST_VERIFY(boost::detail::winapi::CloseHandle(m_sem) != 0);
     }
 
     void post()
@@ -62,7 +61,7 @@
         if (status == 0)
         {
             const DWORD_ err = boost::detail::winapi::GetLastError();
-            BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::semaphore::post failed in ReleaseSemaphore"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::semaphore::post failed in ReleaseSemaphore"));
         }
     }
 
@@ -77,7 +76,7 @@
         case boost::detail::winapi::wait_failed:
             {
                 const DWORD_ err = boost::detail::winapi::GetLastError();
-                BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::semaphore::wait failed in WaitForSingleObject"));
+                BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::semaphore::wait failed in WaitForSingleObject"));
             }
 
         default:
@@ -122,7 +121,7 @@
         case boost::detail::winapi::wait_failed:
             {
                 const DWORD_ err = boost::detail::winapi::GetLastError();
-                BOOST_THROW_EXCEPTION(resource_error(err, "boost::sync::semaphore::do_try_wait_for failed in WaitForSingleObject"));
+                BOOST_SYNC_DETAIL_THROW(resource_error, (err)("boost::sync::semaphore::do_try_wait_for failed in WaitForSingleObject"));
             }
 
         default:
Added: trunk/boost/sync/detail/throw_exception.hpp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/boost/sync/detail/throw_exception.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -0,0 +1,187 @@
+/*
+ * 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)
+ *
+ * (C) Copyright 2013 Andrey Semashev
+ */
+/*!
+ * \file   detail/throw_exception.hpp
+ *
+ * \brief  This header is the Boost.Sync library implementation, see the library documentation
+ *         at http://www.boost.org/doc/libs/release/libs/sync/doc/html/index.html.
+ */
+
+#ifndef BOOST_SYNC_DETAIL_THROW_EXCEPTION_HPP_INCLUDED_
+#define BOOST_SYNC_DETAIL_THROW_EXCEPTION_HPP_INCLUDED_
+
+#include <boost/throw_exception.hpp>
+#include <boost/preprocessor/seq/enum.hpp>
+#include <boost/sync/detail/config.hpp>
+#if defined(BOOST_EXCEPTION_DISABLE)
+#include <boost/current_function.hpp>
+#endif
+#include <boost/sync/detail/header.hpp>
+
+#ifdef BOOST_HAS_PRAGMA_ONCE
+#pragma once
+#endif
+
+namespace boost {
+
+namespace sync {
+
+namespace detail {
+
+#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+
+template< typename Exception, typename... T >
+BOOST_NOINLINE BOOST_ATTRIBUTE_NORETURN void throw_exception(const char* func, const char* file, int line, T&&... args)
+{
+#if !defined(BOOST_EXCEPTION_DISABLE)
+    boost::throw_exception
+    (
+        set_info
+        (
+            set_info
+            (
+                set_info
+                (
+                    enable_error_info(Exception(static_cast< T&& >(args)...)),
+                    throw_function(func)
+                ),
+                throw_file(file)
+            ),
+            throw_line(line)
+        )
+    );
+#else
+    boost::throw_exception(Exception(static_cast< T&& >(args)...));
+#endif
+}
+
+#else // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+
+template< typename Exception >
+BOOST_NOINLINE BOOST_ATTRIBUTE_NORETURN void throw_exception(const char* func, const char* file, int line)
+{
+#if !defined(BOOST_EXCEPTION_DISABLE)
+    boost::throw_exception
+    (
+        set_info
+        (
+            set_info
+            (
+                set_info
+                (
+                    enable_error_info(Exception()),
+                    throw_function(func)
+                ),
+                throw_file(file)
+            ),
+            throw_line(line)
+        )
+    );
+#else
+    boost::throw_exception(Exception());
+#endif
+}
+
+template< typename Exception, typename T0 >
+BOOST_NOINLINE BOOST_ATTRIBUTE_NORETURN void throw_exception(const char* func, const char* file, int line, T0 const& arg0)
+{
+#if !defined(BOOST_EXCEPTION_DISABLE)
+    boost::throw_exception
+    (
+        set_info
+        (
+            set_info
+            (
+                set_info
+                (
+                    enable_error_info(Exception(arg0)),
+                    throw_function(func)
+                ),
+                throw_file(file)
+            ),
+            throw_line(line)
+        )
+    );
+#else
+    boost::throw_exception(Exception(arg0));
+#endif
+}
+
+template< typename Exception, typename T0, typename T1 >
+BOOST_NOINLINE BOOST_ATTRIBUTE_NORETURN void throw_exception(const char* func, const char* file, int line, T0 const& arg0, T1 const& arg1)
+{
+#if !defined(BOOST_EXCEPTION_DISABLE)
+    boost::throw_exception
+    (
+        set_info
+        (
+            set_info
+            (
+                set_info
+                (
+                    enable_error_info(Exception(arg0, arg1)),
+                    throw_function(func)
+                ),
+                throw_file(file)
+            ),
+            throw_line(line)
+        )
+    );
+#else
+    boost::throw_exception(Exception(arg0, arg1));
+#endif
+}
+
+template< typename Exception, typename T0, typename T1, typename T2 >
+BOOST_NOINLINE BOOST_ATTRIBUTE_NORETURN void throw_exception(const char* func, const char* file, int line, T0 const& arg0, T1 const& arg1, T2 const& arg2)
+{
+#if !defined(BOOST_EXCEPTION_DISABLE)
+    boost::throw_exception
+    (
+        set_info
+        (
+            set_info
+            (
+                set_info
+                (
+                    enable_error_info(Exception(arg0, arg1, arg2)),
+                    throw_function(func)
+                ),
+                throw_file(file)
+            ),
+            throw_line(line)
+        )
+    );
+#else
+    boost::throw_exception(Exception(arg0, arg1, arg2));
+#endif
+}
+
+#endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+
+#if !defined(BOOST_EXCEPTION_DISABLE)
+#define BOOST_SYNC_DETAIL_HERE BOOST_THROW_EXCEPTION_CURRENT_FUNCTION, __FILE__, __LINE__
+#else
+#define BOOST_SYNC_DETAIL_HERE BOOST_CURRENT_FUNCTION, __FILE__, __LINE__
+#endif
+
+#define BOOST_SYNC_DETAIL_THROW_DEFAULT(ex)\
+    boost::sync::detail::throw_exception< ex >(BOOST_SYNC_DETAIL_HERE)
+
+#define BOOST_SYNC_DETAIL_THROW(ex, args_seq)\
+    boost::sync::detail::throw_exception< ex >(BOOST_SYNC_DETAIL_HERE, BOOST_PP_SEQ_ENUM(args_seq))
+
+} // namespace detail
+
+} // namespace sync
+
+} // namespace boost
+
+#include <boost/sync/detail/footer.hpp>
+
+#endif // BOOST_SYNC_DETAIL_THROW_EXCEPTION_HPP_INCLUDED_
Modified: trunk/boost/sync/detail/waitable_timer.hpp
==============================================================================
--- trunk/boost/sync/detail/waitable_timer.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/detail/waitable_timer.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -22,7 +22,6 @@
 #include <stdexcept>
 #include <boost/cstdint.hpp>
 #include <boost/version.hpp>
-#include <boost/throw_exception.hpp>
 #include <boost/detail/winapi/dll.hpp>
 #include <boost/detail/winapi/tls.hpp>
 #include <boost/detail/winapi/process.hpp>
@@ -35,6 +34,7 @@
 #include <boost/sync/detail/config.hpp>
 #include <boost/sync/detail/interlocked.hpp>
 #include <boost/sync/detail/weak_linkage.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/exceptions/resource_error.hpp>
 #include <boost/sync/detail/header.hpp>
 
@@ -184,7 +184,7 @@
             {
                 boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
                 BOOST_ATOMIC_INTERLOCKED_EXCHANGE(&initialized, st_uninitialized);
-                BOOST_THROW_EXCEPTION(resource_error(err, "Boost.Sync: unable to allocate a TLS slot"));
+                BOOST_SYNC_DETAIL_THROW(resource_error, (err)("Boost.Sync: unable to allocate a TLS slot"));
             }
 
 #ifndef BOOST_NO_ANSI_APIS
@@ -250,7 +250,7 @@
         {
             boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
             BOOST_ATOMIC_INTERLOCKED_EXCHANGE(&initialized, st_uninitialized);
-            BOOST_THROW_EXCEPTION(resource_error(err, "Boost.Sync: unable to allocate a TLS slot"));
+            BOOST_SYNC_DETAIL_THROW(resource_error, (err)("Boost.Sync: unable to allocate a TLS slot"));
         }
 
         tls_key = key;
@@ -297,7 +297,7 @@
 
         boost::detail::winapi::DWORD_ err = boost::detail::winapi::GetLastError();
         delete ctx;
-        BOOST_THROW_EXCEPTION(resource_error(err, "Boost.Sync: failed to initialize a waitable timer"));
+        BOOST_SYNC_DETAIL_THROW(resource_error, (err)("Boost.Sync: failed to initialize a waitable timer"));
         return NULL; // unreachable; to avoid warnings about missing return statement
     }
 
@@ -328,7 +328,7 @@
 
     // Check that the thread local context is ABI-compatible
     if (p->boost_version != BOOST_VERSION)
-        BOOST_THROW_EXCEPTION(std::logic_error("Boost.Sync: different Boost versions are used in the application"));
+        BOOST_SYNC_DETAIL_THROW(std::logic_error, ("Boost.Sync: different Boost versions are used in the application"));
 
     return p->waitable_timer;
 }
Modified: trunk/boost/sync/locks/shared_lock.hpp
==============================================================================
--- trunk/boost/sync/locks/shared_lock.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/locks/shared_lock.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -17,13 +17,13 @@
 #define BOOST_SYNC_LOCKS_SHARED_LOCK_HPP_INCLUDED_
 
 #include <cstddef>
-#include <boost/throw_exception.hpp>
 #include <boost/move/core.hpp>
 #include <boost/move/utility.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/utility/explicit_operator_bool.hpp>
 #include <boost/sync/detail/config.hpp>
 #include <boost/sync/detail/time_traits.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/detail/system_error.hpp>
 #include <boost/sync/exceptions/lock_error.hpp>
 #include <boost/sync/locks/lock_options.hpp>
@@ -148,10 +148,10 @@
     void lock()
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost shared_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost shared_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost shared_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost shared_lock already owns the mutex"));
 
         m_mutex->lock_shared();
         m_is_locked = true;
@@ -160,10 +160,10 @@
     bool try_lock()
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost shared_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost shared_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost shared_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost shared_lock already owns the mutex"));
 
         m_is_locked = m_mutex->try_lock_shared();
 
@@ -174,10 +174,10 @@
     typename enable_if_c< detail::time_traits< Time >::is_specialized, bool >::type timed_lock(Time const& time)
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost shared_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost shared_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost shared_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost shared_lock already owns the mutex"));
 
         m_is_locked = m_mutex->timed_lock_shared(time);
 
@@ -188,10 +188,10 @@
     typename detail::enable_if_tag< Duration, detail::time_duration_tag, bool >::type try_lock_for(Duration const& rel_time)
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost shared_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost shared_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost shared_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost shared_lock already owns the mutex"));
 
         m_is_locked = m_mutex->try_lock_shared_for(rel_time);
 
@@ -202,10 +202,10 @@
     typename detail::enable_if_tag< TimePoint, detail::time_point_tag, bool >::type try_lock_until(TimePoint const& abs_time)
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost shared_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost shared_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost shared_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost shared_lock already owns the mutex"));
 
         m_is_locked = m_mutex->try_lock_shared_until(abs_time);
 
@@ -215,10 +215,10 @@
     void unlock()
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost shared_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost shared_lock has no mutex"));
 
         if (!m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost shared_lock doesn't own the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost shared_lock doesn't own the mutex"));
 
         m_mutex->unlock_shared();
         m_is_locked = false;
Modified: trunk/boost/sync/locks/unique_lock.hpp
==============================================================================
--- trunk/boost/sync/locks/unique_lock.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/locks/unique_lock.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -17,13 +17,13 @@
 #define BOOST_SYNC_LOCKS_UNIQUE_LOCK_HPP_INCLUDED_
 
 #include <cstddef>
-#include <boost/throw_exception.hpp>
 #include <boost/move/core.hpp>
 #include <boost/move/utility.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/utility/explicit_operator_bool.hpp>
 #include <boost/sync/detail/config.hpp>
 #include <boost/sync/detail/time_traits.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/detail/system_error.hpp>
 #include <boost/sync/exceptions/lock_error.hpp>
 #include <boost/sync/locks/lock_options.hpp>
@@ -186,10 +186,10 @@
     void lock()
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost unique_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost unique_lock already owns the mutex"));
 
         m_mutex->lock();
         m_is_locked = true;
@@ -198,10 +198,10 @@
     bool try_lock()
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost unique_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost unique_lock already owns the mutex"));
 
         m_is_locked = m_mutex->try_lock();
 
@@ -212,10 +212,10 @@
     typename enable_if_c< detail::time_traits< Time >::is_specialized, bool >::type timed_lock(Time const& time)
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost unique_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost unique_lock already owns the mutex"));
 
         m_is_locked = m_mutex->timed_lock(time);
 
@@ -226,10 +226,10 @@
     typename detail::enable_if_tag< Duration, detail::time_duration_tag, bool >::type try_lock_for(Duration const& rel_time)
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost unique_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost unique_lock already owns the mutex"));
 
         m_is_locked = m_mutex->try_lock_for(rel_time);
 
@@ -240,10 +240,10 @@
     typename detail::enable_if_tag< TimePoint, detail::time_point_tag, bool >::type try_lock_until(TimePoint const& abs_time)
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost unique_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost unique_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost unique_lock already owns the mutex"));
 
         m_is_locked = m_mutex->try_lock_until(abs_time);
 
@@ -253,10 +253,10 @@
     void unlock()
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost unique_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost unique_lock has no mutex"));
 
         if (!m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost unique_lock doesn't own the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost unique_lock doesn't own the mutex"));
 
         m_mutex->unlock();
         m_is_locked = false;
Modified: trunk/boost/sync/locks/upgrade_lock.hpp
==============================================================================
--- trunk/boost/sync/locks/upgrade_lock.hpp	Tue Oct  8 11:31:14 2013	(r86200)
+++ trunk/boost/sync/locks/upgrade_lock.hpp	2013-10-08 13:05:55 EDT (Tue, 08 Oct 2013)	(r86201)
@@ -17,13 +17,13 @@
 #define BOOST_SYNC_LOCKS_UPGRADE_LOCK_HPP_INCLUDED_
 
 #include <cstddef>
-#include <boost/throw_exception.hpp>
 #include <boost/move/core.hpp>
 #include <boost/move/utility.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/utility/explicit_operator_bool.hpp>
 #include <boost/sync/detail/config.hpp>
 #include <boost/sync/detail/time_traits.hpp>
+#include <boost/sync/detail/throw_exception.hpp>
 #include <boost/sync/detail/system_error.hpp>
 #include <boost/sync/exceptions/lock_error.hpp>
 #include <boost/sync/locks/lock_options.hpp>
@@ -168,10 +168,10 @@
     void lock()
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost upgrade_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost upgrade_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost upgrade_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost upgrade_lock already owns the mutex"));
 
         m_mutex->lock_upgrade();
         m_is_locked = true;
@@ -180,10 +180,10 @@
     bool try_lock()
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost upgrade_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost upgrade_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost upgrade_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost upgrade_lock already owns the mutex"));
 
         m_is_locked = m_mutex->try_lock_upgrade();
 
@@ -194,10 +194,10 @@
     typename enable_if_c< detail::time_traits< Time >::is_specialized, bool >::type timed_lock(Time const& time)
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost upgrade_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost upgrade_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost upgrade_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost upgrade_lock already owns the mutex"));
 
         m_is_locked = m_mutex->timed_lock_upgrade(time);
 
@@ -208,10 +208,10 @@
     typename detail::enable_if_tag< Duration, detail::time_duration_tag, bool >::type try_lock_for(Duration const& rel_time)
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost upgrade_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost upgrade_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost upgrade_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost upgrade_lock already owns the mutex"));
 
         m_is_locked = m_mutex->try_lock_upgrade_for(rel_time);
 
@@ -222,10 +222,10 @@
     typename detail::enable_if_tag< TimePoint, detail::time_point_tag, bool >::type try_lock_until(TimePoint const& abs_time)
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost upgrade_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost upgrade_lock has no mutex"));
 
         if (m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::resource_deadlock_would_occur, "boost upgrade_lock already owns the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::resource_deadlock_would_occur)("boost upgrade_lock already owns the mutex"));
 
         m_is_locked = m_mutex->try_lock_upgrade_until(abs_time);
 
@@ -235,10 +235,10 @@
     void unlock()
     {
         if (!m_mutex)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost upgrade_lock has no mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost upgrade_lock has no mutex"));
 
         if (!m_is_locked)
-            BOOST_THROW_EXCEPTION(lock_error(detail::system_ns::errc::operation_not_permitted, "boost upgrade_lock doesn't own the mutex"));
+            BOOST_SYNC_DETAIL_THROW(lock_error, (detail::system_ns::errc::operation_not_permitted)("boost upgrade_lock doesn't own the mutex"));
 
         m_mutex->unlock_upgrade();
         m_is_locked = false;