Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85198 - in trunk: boost/log/detail libs/log/src
From: andrey.semashev_at_[hidden]
Date: 2013-08-03 07:37:08


Author: andysem
Date: 2013-08-03 07:37:08 EDT (Sat, 03 Aug 2013)
New Revision: 85198
URL: http://svn.boost.org/trac/boost/changeset/85198

Log:
GetLastError and errno usage made more reliable. Fixes #8925.

Text files modified:
   trunk/boost/log/detail/event.hpp | 15 ++++++---------
   trunk/libs/log/src/event.cpp | 25 ++++++++++++++++---------
   trunk/libs/log/src/timestamp.cpp | 5 +++--
   3 files changed, 25 insertions(+), 20 deletions(-)

Modified: trunk/boost/log/detail/event.hpp
==============================================================================
--- trunk/boost/log/detail/event.hpp Sat Aug 3 07:08:32 2013 (r85197)
+++ trunk/boost/log/detail/event.hpp 2013-08-03 07:37:08 EDT (Sat, 03 Aug 2013) (r85198)
@@ -67,10 +67,9 @@
     //! Sets the object to a signalled state
     BOOST_LOG_API void set_signalled();
 
-private:
     // Copying prohibited
- sem_based_event(sem_based_event const&);
- sem_based_event& operator= (sem_based_event const&);
+ BOOST_DELETED_FUNCTION(sem_based_event(sem_based_event const&))
+ BOOST_DELETED_FUNCTION(sem_based_event& operator= (sem_based_event const&))
 };
 
 typedef sem_based_event event;
@@ -94,10 +93,9 @@
     //! Sets the object to a signalled state
     BOOST_LOG_API void set_signalled();
 
-private:
     // Copying prohibited
- winapi_based_event(winapi_based_event const&);
- winapi_based_event& operator= (winapi_based_event const&);
+ BOOST_DELETED_FUNCTION(winapi_based_event(winapi_based_event const&))
+ BOOST_DELETED_FUNCTION(winapi_based_event& operator= (winapi_based_event const&))
 };
 
 typedef winapi_based_event event;
@@ -122,10 +120,9 @@
     //! Sets the object to a signalled state
     BOOST_LOG_API void set_signalled();
 
-private:
     // Copying prohibited
- generic_event(generic_event const&);
- generic_event& operator= (generic_event const&);
+ BOOST_DELETED_FUNCTION(generic_event(generic_event const&))
+ BOOST_DELETED_FUNCTION(generic_event& operator= (generic_event const&))
 };
 
 typedef generic_event event;

Modified: trunk/libs/log/src/event.cpp
==============================================================================
--- trunk/libs/log/src/event.cpp Sat Aug 3 07:08:32 2013 (r85197)
+++ trunk/libs/log/src/event.cpp 2013-08-03 07:37:08 EDT (Sat, 03 Aug 2013) (r85198)
@@ -17,6 +17,7 @@
 
 #ifndef BOOST_LOG_NO_THREADS
 
+#include <boost/assert.hpp>
 #include <boost/cstdint.hpp>
 #include <boost/throw_exception.hpp>
 #include <boost/system/error_code.hpp>
@@ -61,15 +62,16 @@
 {
     if (sem_init(&m_semaphore, 0, 0) != 0)
     {
+ const int err = errno;
         BOOST_THROW_EXCEPTION(system::system_error(
- errno, system::system_category(), "Failed to initialize semaphore"));
+ err, system::system_category(), "Failed to initialize semaphore"));
     }
 }
 
 //! Destructor
 BOOST_LOG_API sem_based_event::~sem_based_event()
 {
- sem_destroy(&m_semaphore);
+ BOOST_VERIFY(sem_destroy(&m_semaphore) == 0);
 }
 
 //! Waits for the object to become signalled
@@ -79,10 +81,11 @@
     {
         if (sem_wait(&m_semaphore) != 0)
         {
- if (errno != EINTR)
+ const int err = errno;
+ if (err != EINTR)
             {
                 BOOST_THROW_EXCEPTION(system::system_error(
- errno, system::system_category(), "Failed to block on the semaphore"));
+ err, system::system_category(), "Failed to block on the semaphore"));
             }
         }
         else
@@ -98,9 +101,10 @@
     {
         if (sem_post(&m_semaphore) != 0)
         {
+ const int err = errno;
             BOOST_LOG_EVENT_RESET(m_state);
             BOOST_THROW_EXCEPTION(system::system_error(
- errno, system::system_category(), "Failed to wake the blocked thread"));
+ err, system::system_category(), "Failed to wake the blocked thread"));
         }
     }
 }
@@ -114,15 +118,16 @@
 {
     if (!m_event)
     {
+ const DWORD err = GetLastError();
         BOOST_THROW_EXCEPTION(system::system_error(
- GetLastError(), system::system_category(), "Failed to create Windows event"));
+ err, system::system_category(), "Failed to create Windows event"));
     }
 }
 
 //! Destructor
 BOOST_LOG_API winapi_based_event::~winapi_based_event()
 {
- CloseHandle(m_event);
+ BOOST_VERIFY(CloseHandle(m_event) != 0);
 }
 
 //! Waits for the object to become signalled
@@ -133,8 +138,9 @@
     {
         if (WaitForSingleObject(m_event, INFINITE) != 0)
         {
+ const DWORD err = GetLastError();
             BOOST_THROW_EXCEPTION(system::system_error(
- GetLastError(), system::system_category(), "Failed to block on Windows event"));
+ err, system::system_category(), "Failed to block on Windows event"));
         }
     }
     const_cast< volatile boost::uint32_t& >(m_state) = 0;
@@ -147,9 +153,10 @@
     {
         if (SetEvent(m_event) == 0)
         {
+ const DWORD err = GetLastError();
             const_cast< volatile boost::uint32_t& >(m_state) = 0;
             BOOST_THROW_EXCEPTION(system::system_error(
- GetLastError(), system::system_category(), "Failed to wake the blocked thread"));
+ err, system::system_category(), "Failed to wake the blocked thread"));
         }
     }
 }

Modified: trunk/libs/log/src/timestamp.cpp
==============================================================================
--- trunk/libs/log/src/timestamp.cpp Sat Aug 3 07:08:32 2013 (r85197)
+++ trunk/libs/log/src/timestamp.cpp 2013-08-03 07:37:08 EDT (Sat, 03 Aug 2013) (r85198)
@@ -222,8 +222,9 @@
     timespec ts;
     if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
     {
+ const int err = errno;
         BOOST_THROW_EXCEPTION(boost::system::system_error(
- errno, boost::system::system_category(), "Failed to acquire current time"));
+ err, boost::system::system_category(), "Failed to acquire current time"));
     }
 
     return timestamp(static_cast< uint64_t >(ts.tv_sec) * 1000000000ULL + ts.tv_nsec);
@@ -237,7 +238,7 @@
     timespec ts;
     if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
     {
- int err = errno;
+ const int err = errno;
         if (err == EINVAL)
         {
             // The current platform does not support monotonic timer.


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