diff options
author | Aaron <aaron@10gen.com> | 2010-03-10 00:39:26 -0800 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2010-03-10 00:39:26 -0800 |
commit | eb7cde3e751b02eae055a922af8985fe52c807fa (patch) | |
tree | 2e233ffffb850b8cf7d3e6f01bf977fa24146457 /util | |
parent | 26b6ffe30a81e80cafd427ca0c78e072ff918f23 (diff) | |
download | mongo-eb7cde3e751b02eae055a922af8985fe52c807fa.tar.gz |
Revert "SERVER-695 don't destroy static global mutexes"
This reverts commit 714ec2fdc8e9c8dc1c2cdf5486afdbc185beef14.
Diffstat (limited to 'util')
-rw-r--r-- | util/assert_util.cpp | 4 | ||||
-rw-r--r-- | util/assert_util.h | 4 | ||||
-rw-r--r-- | util/background.cpp | 4 | ||||
-rw-r--r-- | util/background.h | 2 | ||||
-rw-r--r-- | util/file_allocator.h | 16 | ||||
-rw-r--r-- | util/goodies.h | 44 | ||||
-rw-r--r-- | util/log.h | 4 | ||||
-rw-r--r-- | util/message.cpp | 11 | ||||
-rw-r--r-- | util/message_server_asio.cpp | 6 | ||||
-rw-r--r-- | util/mmap.cpp | 10 | ||||
-rw-r--r-- | util/queue.h | 10 | ||||
-rw-r--r-- | util/sock.cpp | 4 | ||||
-rw-r--r-- | util/sock.h | 8 | ||||
-rw-r--r-- | util/thread_pool.cpp | 8 | ||||
-rw-r--r-- | util/thread_pool.h | 2 | ||||
-rw-r--r-- | util/util.cpp | 6 |
16 files changed, 57 insertions, 86 deletions
diff --git a/util/assert_util.cpp b/util/assert_util.cpp index 8c8477a0976..6bc902e7635 100644 --- a/util/assert_util.cpp +++ b/util/assert_util.cpp @@ -105,13 +105,13 @@ namespace mongo { } - mongo::mutex *Assertion::_mutex = new mongo::mutex(); + boost::mutex *Assertion::_mutex = new boost::mutex(); string Assertion::toString() { if( _mutex == 0 ) return ""; - scoped_lock lk(*_mutex); + boostlock lk(*_mutex); if ( !isSet() ) return ""; diff --git a/util/assert_util.h b/util/assert_util.h index bae3a55cbf1..81a6b0df20a 100644 --- a/util/assert_util.h +++ b/util/assert_util.h @@ -32,7 +32,7 @@ namespace mongo { when = 0; } private: - static mongo::mutex *_mutex; + static boost::mutex *_mutex; char msg[128]; char context[128]; const char *file; @@ -44,7 +44,7 @@ namespace mongo { /* asserted during global variable initialization */ return; } - scoped_lock lk(*_mutex); + boostlock lk(*_mutex); strncpy(msg, m, 127); strncpy(context, ctxt, 127); file = f; diff --git a/util/background.cpp b/util/background.cpp index 41253153247..ac3a48c8380 100644 --- a/util/background.cpp +++ b/util/background.cpp @@ -22,7 +22,7 @@ namespace mongo { BackgroundJob *BackgroundJob::grab = 0; - mongo::mutex BackgroundJob::mutex; + boost::mutex &BackgroundJob::mutex = *( new boost::mutex ); /* static */ void BackgroundJob::thr() { @@ -38,7 +38,7 @@ namespace mongo { } BackgroundJob& BackgroundJob::go() { - scoped_lock bl(mutex); + boostlock bl(mutex); assert( grab == 0 ); grab = this; boost::thread t(thr); diff --git a/util/background.h b/util/background.h index c95a5bd2c45..53c04887250 100644 --- a/util/background.h +++ b/util/background.h @@ -64,7 +64,7 @@ namespace mongo { private: static BackgroundJob *grab; - static mongo::mutex mutex; + static boost::mutex &mutex; static void thr(); volatile State state; }; diff --git a/util/file_allocator.h b/util/file_allocator.h index e819ba2321c..fa48d22c412 100644 --- a/util/file_allocator.h +++ b/util/file_allocator.h @@ -54,7 +54,7 @@ namespace mongo { on windows anyway as we don't have to pre-zero the file there. */ #if !defined(_WIN32) - scoped_lock lk( pendingMutex_ ); + boostlock lk( pendingMutex_ ); if ( failed_ ) return; long oldSize = prevSize( name ); @@ -71,7 +71,7 @@ namespace mongo { // updated to match existing file size. void allocateAsap( const string &name, long &size ) { #if !defined(_WIN32) - scoped_lock lk( pendingMutex_ ); + boostlock lk( pendingMutex_ ); long oldSize = prevSize( name ); if ( oldSize != -1 ) { size = oldSize; @@ -100,7 +100,7 @@ namespace mongo { #if !defined(_WIN32) if ( failed_ ) return; - scoped_lock lk( pendingMutex_ ); + boostlock lk( pendingMutex_ ); while( pending_.size() != 0 ) pendingUpdated_.wait( lk ); #endif @@ -130,7 +130,7 @@ namespace mongo { return false; } - mutable mongo::mutex pendingMutex_; + mutable boost::mutex pendingMutex_; mutable boost::condition pendingUpdated_; list< string > pending_; mutable map< string, long > pendingSize_; @@ -142,7 +142,7 @@ namespace mongo { void operator()() { while( 1 ) { { - scoped_lock lk( a_.pendingMutex_ ); + boostlock lk( a_.pendingMutex_ ); if ( a_.pending_.size() == 0 ) a_.pendingUpdated_.wait( lk ); } @@ -150,7 +150,7 @@ namespace mongo { string name; long size; { - scoped_lock lk( a_.pendingMutex_ ); + boostlock lk( a_.pendingMutex_ ); if ( a_.pending_.size() == 0 ) break; name = a_.pending_.front(); @@ -206,7 +206,7 @@ namespace mongo { BOOST_CHECK_EXCEPTION( boost::filesystem::remove( name ) ); } catch ( ... ) { } - scoped_lock lk( a_.pendingMutex_ ); + boostlock lk( a_.pendingMutex_ ); a_.failed_ = true; // not erasing from pending a_.pendingUpdated_.notify_all(); @@ -214,7 +214,7 @@ namespace mongo { } { - scoped_lock lk( a_.pendingMutex_ ); + boostlock lk( a_.pendingMutex_ ); a_.pendingSize_.erase( name ); a_.pending_.pop_front(); a_.pendingUpdated_.notify_all(); diff --git a/util/goodies.h b/util/goodies.h index 8bfe7a2b2f6..62ae2a64f1e 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -253,36 +253,8 @@ namespace mongo { return secs*1000000 + t; } using namespace boost; - - extern bool __destroyingStatics; - - // If you create a local static instance of this class, that instance will be destroyed - // before all global static objects are destroyed, so __destroyingStatics will be set - // to true before the global static variables are destroyed. - class StaticObserver : boost::noncopyable { - public: - ~StaticObserver() { __destroyingStatics = true; } - }; - - class mutex : boost::noncopyable { - public: - mutex() { new (_buf) boost::mutex(); } - ~mutex() { - if( !__destroyingStatics ) { - me().boost::mutex::~mutex(); - } - } - void lock() { me().lock(); } - void unlock() { me().unlock(); } - bool try_lock() { return me().try_lock(); } - typedef boost::unique_lock<mongo::mutex> scoped_lock; - private: - boost::mutex &me() { return *( boost::mutex * )( _buf ); } - char _buf[ sizeof( boost::mutex ) ]; - }; - - typedef mongo::mutex::scoped_lock scoped_lock; - typedef boost::recursive_mutex::scoped_lock recursive_scoped_lock; + typedef boost::mutex::scoped_lock boostlock; + typedef boost::recursive_mutex::scoped_lock recursive_boostlock; // simple scoped timer class Timer { @@ -321,7 +293,7 @@ namespace mongo { class DebugMutex : boost::noncopyable { friend class lock; - mongo::mutex m; + boost::mutex m; int locked; public: DebugMutex() : locked(0); { } @@ -330,7 +302,7 @@ namespace mongo { */ -//typedef scoped_lock lock; +//typedef boostlock lock; inline bool startsWith(const char *str, const char *prefix) { size_t l = strlen(prefix); @@ -471,7 +443,7 @@ namespace mongo { } bool tryAcquire(){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); if ( _num <= 0 ){ if ( _num < 0 ){ cerr << "DISASTER! in TicketHolder" << endl; @@ -483,12 +455,12 @@ namespace mongo { } void release(){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); _num++; } void resize( int newSize ){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); int used = _outof - _num; if ( used > newSize ){ cout << "ERROR: can't resize since we're using (" << used << ") more than newSize(" << newSize << ")" << endl; @@ -510,7 +482,7 @@ namespace mongo { private: int _outof; int _num; - mongo::mutex _mutex; + boost::mutex _mutex; }; class TicketHolderReleaser { diff --git a/util/log.h b/util/log.h index 668557a3e5b..bac1156d0f4 100644 --- a/util/log.h +++ b/util/log.h @@ -118,7 +118,7 @@ namespace mongo { #define LOGIT { ss << x; return *this; } class Logstream : public Nullstream { - static mongo::mutex mutex; + static boost::mutex &mutex; static int doneSetup; stringstream ss; public: @@ -128,7 +128,7 @@ namespace mongo { void flush() { // this ensures things are sane if ( doneSetup == 1717 ){ - scoped_lock lk(mutex); + boostlock lk(mutex); cout << ss.str(); cout.flush(); } diff --git a/util/message.cpp b/util/message.cpp index 2c3d0063f34..b61e8944af1 100644 --- a/util/message.cpp +++ b/util/message.cpp @@ -138,22 +138,23 @@ namespace mongo { class Ports { set<MessagingPort*>& ports; - mongo::mutex m; + boost::mutex& m; public: // we "new" this so it is still be around when other automatic global vars // are being destructed during termination. - Ports() : ports( *(new set<MessagingPort*>()) ) {} + Ports() : ports( *(new set<MessagingPort*>()) ), + m( *(new boost::mutex()) ) { } void closeAll() { \ - scoped_lock bl(m); + boostlock bl(m); for ( set<MessagingPort*>::iterator i = ports.begin(); i != ports.end(); i++ ) (*i)->shutdown(); } void insert(MessagingPort* p) { - scoped_lock bl(m); + boostlock bl(m); ports.insert(p); } void erase(MessagingPort* p) { - scoped_lock bl(m); + boostlock bl(m); ports.erase(p); } } ports; diff --git a/util/message_server_asio.cpp b/util/message_server_asio.cpp index 7fca29abd98..f652a340147 100644 --- a/util/message_server_asio.cpp +++ b/util/message_server_asio.cpp @@ -68,7 +68,7 @@ namespace mongo { }; vector<boost::shared_ptr<StickyThread> > thread_pool; - mongo::mutex tp_mutex; // this is only needed if io_service::run() is called from multiple threads + boost::mutex tp_mutex; // this is only needed if io_service::run() is called from multiple threads } class MessageServerSession : public boost::enable_shared_from_this<MessageServerSession> , public AbstractMessagingPort { @@ -117,7 +117,7 @@ namespace mongo { void handleReadBody( const boost::system::error_code& error ){ if (!_myThread){ - mongo::mutex::scoped_lock(tp_mutex); + boost::mutex::scoped_lock(tp_mutex); if (!thread_pool.empty()){ _myThread = thread_pool.back(); thread_pool.pop_back(); @@ -148,7 +148,7 @@ namespace mongo { void handleWriteDone( const boost::system::error_code& error ){ { // return thread to pool after we have sent data to the client - mongo::mutex::scoped_lock(tp_mutex); + boost::mutex::scoped_lock(tp_mutex); assert(_myThread); thread_pool.push_back(_myThread); _myThread.reset(); diff --git a/util/mmap.cpp b/util/mmap.cpp index f6bbc735ec6..536cf85e145 100644 --- a/util/mmap.cpp +++ b/util/mmap.cpp @@ -22,16 +22,16 @@ namespace mongo { set<MemoryMappedFile*> mmfiles; - mongo::mutex mmmutex; + boost::mutex mmmutex; MemoryMappedFile::~MemoryMappedFile() { close(); - scoped_lock lk( mmmutex ); + boostlock lk( mmmutex ); mmfiles.erase(this); } void MemoryMappedFile::created(){ - scoped_lock lk( mmmutex ); + boostlock lk( mmmutex ); mmfiles.insert(this); } @@ -55,7 +55,7 @@ namespace mongo { long long MemoryMappedFile::totalMappedLength(){ unsigned long long total = 0; - scoped_lock lk( mmmutex ); + boostlock lk( mmmutex ); for ( set<MemoryMappedFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ) total += (*i)->length(); @@ -65,7 +65,7 @@ namespace mongo { int MemoryMappedFile::flushAll( bool sync ){ int num = 0; - scoped_lock lk( mmmutex ); + boostlock lk( mmmutex ); for ( set<MemoryMappedFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ){ num++; MemoryMappedFile * mmf = *i; diff --git a/util/queue.h b/util/queue.h index d291cb80c90..8f4fbaf7ac8 100644 --- a/util/queue.h +++ b/util/queue.h @@ -30,18 +30,18 @@ namespace mongo { template<typename T> class BlockingQueue : boost::noncopyable { public: void push(T const& t){ - scoped_lock l( _lock ); + boostlock l( _lock ); _queue.push( t ); _condition.notify_one(); } bool empty() const { - scoped_lock l( _lock ); + boostlock l( _lock ); return _queue.empty(); } bool tryPop( T & t ){ - scoped_lock l( _lock ); + boostlock l( _lock ); if ( _queue.empty() ) return false; @@ -53,7 +53,7 @@ namespace mongo { T blockingPop(){ - scoped_lock l( _lock ); + boostlock l( _lock ); while( _queue.empty() ) _condition.wait( l ); @@ -65,7 +65,7 @@ namespace mongo { private: std::queue<T> _queue; - mutable mongo::mutex _lock; + mutable boost::mutex _lock; boost::condition _condition; }; diff --git a/util/sock.cpp b/util/sock.cpp index 5beac683568..5172692a529 100644 --- a/util/sock.cpp +++ b/util/sock.cpp @@ -20,14 +20,14 @@ namespace mongo { - static mongo::mutex sock_mutex; + static boost::mutex sock_mutex; string hostbyname(const char *hostname) { static string unknown = "0.0.0.0"; if ( unknown == hostname ) return unknown; - scoped_lock lk(sock_mutex); + boostlock lk(sock_mutex); #if defined(_WIN32) if( inet_addr(hostname) != INADDR_NONE ) return hostname; diff --git a/util/sock.h b/util/sock.h index ee7a7aef48f..d1a941692cd 100644 --- a/util/sock.h +++ b/util/sock.h @@ -245,18 +245,18 @@ namespace mongo { } void add( int sock ){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); _sockets->insert( sock ); } void remove( int sock ){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); _sockets->erase( sock ); } void closeAll(){ set<int>* s; { - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); s = _sockets; _sockets = new set<int>(); } @@ -272,7 +272,7 @@ namespace mongo { static ListeningSockets* get(); private: - mongo::mutex _mutex; + boost::mutex _mutex; set<int>* _sockets; static ListeningSockets* _instance; }; diff --git a/util/thread_pool.cpp b/util/thread_pool.cpp index 7c12b87bb65..b95bc1d50cb 100644 --- a/util/thread_pool.cpp +++ b/util/thread_pool.cpp @@ -77,7 +77,7 @@ ThreadPool::ThreadPool(int nThreads) : _tasksRemaining(0) , _nThreads(nThreads) { - scoped_lock lock(_mutex); + boostlock lock(_mutex); while (nThreads-- > 0){ Worker* worker = new Worker(*this); _freeWorkers.push_front(worker); @@ -99,14 +99,14 @@ ThreadPool::~ThreadPool(){ } void ThreadPool::join(){ - scoped_lock lock(_mutex); + boostlock lock(_mutex); while(_tasksRemaining){ _condition.wait(lock); } } void ThreadPool::schedule(Task task){ - scoped_lock lock(_mutex); + boostlock lock(_mutex); _tasksRemaining++; @@ -120,7 +120,7 @@ void ThreadPool::schedule(Task task){ // should only be called by a worker from the worker thread void ThreadPool::task_done(Worker* worker){ - scoped_lock lock(_mutex); + boostlock lock(_mutex); if (!_tasks.empty()){ worker->set_task(_tasks.front()); diff --git a/util/thread_pool.h b/util/thread_pool.h index d891d7daac2..91c2969d559 100644 --- a/util/thread_pool.h +++ b/util/thread_pool.h @@ -62,7 +62,7 @@ namespace threadpool { int tasks_remaining() { return _tasksRemaining; } private: - mongo::mutex _mutex; + boost::mutex _mutex; boost::condition _condition; list<Worker*> _freeWorkers; //used as LIFO stack (always front) diff --git a/util/util.cpp b/util/util.cpp index 8ae00f3e961..c96bef62445 100644 --- a/util/util.cpp +++ b/util/util.cpp @@ -34,7 +34,7 @@ namespace mongo { const char * (*getcurns)() = default_getcurns; int logLevel = 0; - mongo::mutex Logstream::mutex; + boost::mutex &Logstream::mutex = *( new boost::mutex ); int Logstream::doneSetup = Logstream::magicNumber(); bool goingAway = false; @@ -137,7 +137,5 @@ namespace mongo { s << (string)o; return s; } - - bool __destroyingStatics = false; - + } // namespace mongo |