mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 00:56:44 +01:00
clean up locking in file allocator; unlike in doc example, lock may be held when notification sent
This commit is contained in:
parent
7dd4ce5501
commit
9adf110885
@ -37,7 +37,6 @@ namespace mongo {
|
||||
// May be called if file exists. If file exists, or its allocation has
|
||||
// been requested, size is updated to match existing file size.
|
||||
void requestAllocation( const string &name, int &size ) {
|
||||
{
|
||||
boostlock lk( pendingMutex_ );
|
||||
int oldSize = prevSize( name );
|
||||
if ( oldSize != -1 ) {
|
||||
@ -46,13 +45,11 @@ namespace mongo {
|
||||
}
|
||||
pending_.push_back( name );
|
||||
pendingSize_[ name ] = size;
|
||||
}
|
||||
pendingUpdated_.notify_all();
|
||||
}
|
||||
// Returns when file has been allocated. If file exists, size is
|
||||
// updated to match existing file size.
|
||||
void allocateAsap( const string &name, int &size ) {
|
||||
{
|
||||
boostlock lk( pendingMutex_ );
|
||||
int oldSize = prevSize( name );
|
||||
if ( oldSize != -1 ) {
|
||||
@ -69,25 +66,16 @@ namespace mongo {
|
||||
++i;
|
||||
pending_.insert( i, name );
|
||||
}
|
||||
}
|
||||
pendingUpdated_.notify_all();
|
||||
boostlock lk( pendingMutex_ );
|
||||
while( 1 ) {
|
||||
if ( !inProgress( name ) ) {
|
||||
return;
|
||||
}
|
||||
while( inProgress( name ) )
|
||||
pendingUpdated_.wait( lk );
|
||||
}
|
||||
}
|
||||
|
||||
void waitUntilFinished() const {
|
||||
boostlock lk( pendingMutex_ );
|
||||
while( 1 ) {
|
||||
if ( pending_.size() == 0 )
|
||||
return;
|
||||
while( pending_.size() != 0 )
|
||||
pendingUpdated_.wait( lk );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// caller must hold pendingMutex_ lock. Returns size if allocated or
|
||||
@ -178,11 +166,11 @@ namespace mongo {
|
||||
boostlock lk( a_.pendingMutex_ );
|
||||
a_.pendingSize_.erase( name );
|
||||
a_.pending_.pop_front();
|
||||
}
|
||||
a_.pendingUpdated_.notify_all();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user