0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

some ClientCursor helpers and a yield option where you want to run some code

This commit is contained in:
Eliot Horowitz 2010-03-30 11:00:16 -04:00
parent 977765e76d
commit 6b34772e70

View File

@ -143,6 +143,66 @@ namespace mongo {
* in fact, the whole database could be gone.
*/
bool yield();
struct YieldLock {
YieldLock( ClientCursor * cc )
: _cc( cc ) , _id( cc->cursorid ) , _doingDeletes( cc->_doingDeletes ) {
cc->updateLocation();
_unlock = new dbtempreleasecond();
}
~YieldLock(){
assert( ! _unlock );
}
bool stillOk(){
delete _unlock;
_unlock = 0;
if ( ClientCursor::find( _id , false ) == 0 ){
// i was deleted
return false;
}
_cc->_doingDeletes = _doingDeletes;
return true;
}
ClientCursor * _cc;
CursorId _id;
bool _doingDeletes;
dbtempreleasecond * _unlock;
};
YieldLock yieldHold(){
return YieldLock( this );
}
// --- some pass through helpers for Cursor ---
BSONObj indexKeyPattern() {
return c->indexKeyPattern();
}
bool ok(){
return c->ok();
}
bool advance(){
return c->advance();
}
bool currentMatches(){
if ( ! matcher.get() )
return true;
return matcher->matchesCurrent( c.get() );
}
BSONObj current(){
return c->current();
}
private:
void setLastLoc_inlock(DiskLoc);