From c457973dc696823afbdd4ab19d49c3995d98f04e Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 15 Mar 2010 09:56:10 -0700 Subject: [PATCH] SERVER-695 expose boost object to work better with older boost versions --- util/file_allocator.h | 6 +++--- util/goodies.h | 18 ++++++++++++------ util/queue.h | 2 +- util/thread_pool.cpp | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/util/file_allocator.h b/util/file_allocator.h index e819ba2321c..93b2b1c582b 100644 --- a/util/file_allocator.h +++ b/util/file_allocator.h @@ -91,7 +91,7 @@ namespace mongo { pendingUpdated_.notify_all(); while( inProgress( name ) ) { checkFailure(); - pendingUpdated_.wait( lk ); + pendingUpdated_.wait( lk.boost() ); } #endif } @@ -102,7 +102,7 @@ namespace mongo { return; scoped_lock lk( pendingMutex_ ); while( pending_.size() != 0 ) - pendingUpdated_.wait( lk ); + pendingUpdated_.wait( lk.boost() ); #endif } @@ -144,7 +144,7 @@ namespace mongo { { scoped_lock lk( a_.pendingMutex_ ); if ( a_.pending_.size() == 0 ) - a_.pendingUpdated_.wait( lk ); + a_.pendingUpdated_.wait( lk.boost() ); } while( 1 ) { string name; diff --git a/util/goodies.h b/util/goodies.h index 7c78f68ccc4..0ccef30d73f 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -281,20 +281,26 @@ namespace mongo { ~StaticObserver() { __destroyingStatics = true; } }; + // On pthread systems, it is an error to destroy a mutex while held. Static global + // mutexes may be held upon shutdown in our implementation, and this way we avoid + // destroying them. class mutex : boost::noncopyable { public: mutex() { new (_buf) boost::mutex(); } ~mutex() { if( !__destroyingStatics ) { - me().boost::mutex::~mutex(); + boost().boost::mutex::~mutex(); } } - void lock() { me().lock(); } - void unlock() { me().unlock(); } - bool try_lock() { return me().try_lock(); } - typedef boost::unique_lock scoped_lock; + class scoped_lock : boost::noncopyable { + public: + scoped_lock( mongo::mutex &m ) : _l( m.boost() ) {} + boost::mutex::scoped_lock &boost() { return _l; } + private: + boost::mutex::scoped_lock _l; + }; private: - boost::mutex &me() { return *( boost::mutex * )( _buf ); } + boost::mutex &boost() { return *( boost::mutex * )( _buf ); } char _buf[ sizeof( boost::mutex ) ]; }; diff --git a/util/queue.h b/util/queue.h index d291cb80c90..d48e0126a0e 100644 --- a/util/queue.h +++ b/util/queue.h @@ -55,7 +55,7 @@ namespace mongo { scoped_lock l( _lock ); while( _queue.empty() ) - _condition.wait( l ); + _condition.wait( l.boost() ); T t = _queue.front(); _queue.pop(); diff --git a/util/thread_pool.cpp b/util/thread_pool.cpp index 7c12b87bb65..77d0d051afd 100644 --- a/util/thread_pool.cpp +++ b/util/thread_pool.cpp @@ -101,7 +101,7 @@ ThreadPool::~ThreadPool(){ void ThreadPool::join(){ scoped_lock lock(_mutex); while(_tasksRemaining){ - _condition.wait(lock); + _condition.wait(lock.boost()); } }