mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
fix startup race condition
This commit is contained in:
parent
24f9d63496
commit
763c49f692
@ -34,19 +34,20 @@ namespace mongo {
|
||||
// global background job responsible for checking every X amount of time
|
||||
class ReplicaSetMonitorWatcher : public BackgroundJob {
|
||||
public:
|
||||
ReplicaSetMonitorWatcher() : _safego("ReplicaSetMonitorWatcher::_safego") {}
|
||||
ReplicaSetMonitorWatcher() : _safego("ReplicaSetMonitorWatcher::_safego") , _started(false) {}
|
||||
|
||||
virtual string name() const { return "ReplicaSetMonitorWatcher"; }
|
||||
|
||||
void safeGo() {
|
||||
// check outside of lock for speed
|
||||
if ( getState() == BackgroundJob::Running )
|
||||
if ( _started )
|
||||
return;
|
||||
|
||||
scoped_lock lk( _safego );
|
||||
if ( getState() == BackgroundJob::Running )
|
||||
if ( _started )
|
||||
return;
|
||||
|
||||
_started = true;
|
||||
|
||||
go();
|
||||
}
|
||||
protected:
|
||||
@ -63,6 +64,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
mongo::mutex _safego;
|
||||
bool _started;
|
||||
|
||||
} replicaSetMonitorWatcher;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user