diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/goodies.h | 55 | ||||
-rw-r--r-- | util/version.cpp | 2 |
2 files changed, 40 insertions, 17 deletions
diff --git a/util/goodies.h b/util/goodies.h index 65bfbab..735aa8b 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -324,31 +324,41 @@ namespace mongo { bool tryAcquire() { scoped_lock lk( _mutex ); - if ( _num <= 0 ) { - if ( _num < 0 ) { - cerr << "DISASTER! in TicketHolder" << endl; - } - return false; + return _tryAcquire(); + } + + void waitForTicket() { + scoped_lock lk( _mutex ); + + while( ! _tryAcquire() ) { + _newTicket.wait( lk.boost() ); } - _num--; - return true; } void release() { - scoped_lock lk( _mutex ); - _num++; + { + scoped_lock lk( _mutex ); + _num++; + } + _newTicket.notify_one(); } void resize( int newSize ) { - scoped_lock lk( _mutex ); - int used = _outof - _num; - if ( used > newSize ) { - cout << "ERROR: can't resize since we're using (" << used << ") more than newSize(" << newSize << ")" << endl; - return; + { + scoped_lock lk( _mutex ); + + int used = _outof - _num; + if ( used > newSize ) { + cout << "ERROR: can't resize since we're using (" << used << ") more than newSize(" << newSize << ")" << endl; + return; + } + + _outof = newSize; + _num = _outof - used; } - _outof = newSize; - _num = _outof - used; + // Potentially wasteful, but easier to see is correct + _newTicket.notify_all(); } int available() const { @@ -362,9 +372,22 @@ namespace mongo { int outof() const { return _outof; } private: + + bool _tryAcquire(){ + if ( _num <= 0 ) { + if ( _num < 0 ) { + cerr << "DISASTER! in TicketHolder" << endl; + } + return false; + } + _num--; + return true; + } + int _outof; int _num; mongo::mutex _mutex; + boost::condition_variable_any _newTicket; }; class TicketHolderReleaser { diff --git a/util/version.cpp b/util/version.cpp index 883c208..c644e75 100644 --- a/util/version.cpp +++ b/util/version.cpp @@ -38,7 +38,7 @@ namespace mongo { * 1.2.3-rc4-pre- * If you really need to do something else you'll need to fix _versionArray() */ - const char versionString[] = "2.0.3"; + const char versionString[] = "2.0.4"; // See unit test for example outputs static BSONArray _versionArray(const char* version){ |