Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84492 - in trunk/boost/asio/detail: . impl
From: chris_at_[hidden]
Date: 2013-05-25 08:35:44


Author: chris_kohlhoff
Date: 2013-05-25 08:35:43 EDT (Sat, 25 May 2013)
New Revision: 84492
URL: http://svn.boost.org/trac/boost/changeset/84492

Log:
Fix potential data race due to reading the reactor pointer outside the lock.

Text files modified:
   trunk/boost/asio/detail/impl/epoll_reactor.ipp | 3 ++-
   trunk/boost/asio/detail/scoped_lock.hpp | 12 +++++++++++-
   2 files changed, 13 insertions(+), 2 deletions(-)

Modified: trunk/boost/asio/detail/impl/epoll_reactor.ipp
==============================================================================
--- trunk/boost/asio/detail/impl/epoll_reactor.ipp (original)
+++ trunk/boost/asio/detail/impl/epoll_reactor.ipp 2013-05-25 08:35:43 EDT (Sat, 25 May 2013)
@@ -607,8 +607,9 @@
 
 operation* epoll_reactor::descriptor_state::perform_io(uint32_t events)
 {
+ mutex_.lock();
   perform_io_cleanup_on_block_exit io_cleanup(reactor_);
- mutex::scoped_lock descriptor_lock(mutex_);
+ mutex::scoped_lock descriptor_lock(mutex_, mutex::scoped_lock::adopt_lock);
 
   // Exception operations must be processed first to ensure that any
   // out-of-band data is read before normal data.

Modified: trunk/boost/asio/detail/scoped_lock.hpp
==============================================================================
--- trunk/boost/asio/detail/scoped_lock.hpp (original)
+++ trunk/boost/asio/detail/scoped_lock.hpp 2013-05-25 08:35:43 EDT (Sat, 25 May 2013)
@@ -29,8 +29,18 @@
   : private noncopyable
 {
 public:
+ // Tag type used to distinguish constructors.
+ enum adopt_lock_t { adopt_lock };
+
+ // Constructor adopts a lock that is already held.
+ scoped_lock(Mutex& m, adopt_lock_t)
+ : mutex_(m),
+ locked_(true)
+ {
+ }
+
   // Constructor acquires the lock.
- scoped_lock(Mutex& m)
+ explicit scoped_lock(Mutex& m)
     : mutex_(m)
   {
     mutex_.lock();


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