本文整理汇总了C++中MongoFile::prepareFlush方法的典型用法代码示例。如果您正苦于以下问题:C++ MongoFile::prepareFlush方法的具体用法?C++ MongoFile::prepareFlush怎么用?C++ MongoFile::prepareFlush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoFile
的用法示例。
在下文中一共展示了MongoFile::prepareFlush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lk
/*static*/ int MongoFile::_flushAll( bool sync ){
if ( ! sync ){
int num = 0;
rwlock lk( mmmutex , false );
for ( set<MongoFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ){
num++;
MongoFile * mmf = *i;
if ( ! mmf )
continue;
mmf->flush( sync );
}
return num;
}
// want to do it sync
set<MongoFile*> seen;
while ( true ){
auto_ptr<Flushable> f;
{
rwlock lk( mmmutex , false );
for ( set<MongoFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ){
MongoFile * mmf = *i;
if ( ! mmf )
continue;
if ( seen.count( mmf ) )
continue;
f.reset( mmf->prepareFlush() );
seen.insert( mmf );
break;
}
}
if ( ! f.get() )
break;
f->flush();
}
return seen.size();
}
示例2:
/*static*/ int MongoFile::_flushAll(bool sync) {
if (!sync) {
int num = 0;
LockMongoFilesShared lk;
for (set<MongoFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++) {
num++;
MongoFile* mmf = *i;
if (!mmf)
continue;
mmf->flush(sync);
}
return num;
}
// want to do it sync
// get a thread-safe Flushable object for each file first in a single lock
// so that we can iterate and flush without doing any locking here
OwnedPointerVector<Flushable> thingsToFlushWrapper;
vector<Flushable*>& thingsToFlush = thingsToFlushWrapper.mutableVector();
{
LockMongoFilesShared lk;
for (set<MongoFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++) {
MongoFile* mmf = *i;
if (!mmf)
continue;
thingsToFlush.push_back(mmf->prepareFlush());
}
}
for (size_t i = 0; i < thingsToFlush.size(); i++) {
thingsToFlush[i]->flush();
}
return thingsToFlush.size();
}