本文整理汇总了C++中sleepmillis函数的典型用法代码示例。如果您正苦于以下问题:C++ sleepmillis函数的具体用法?C++ sleepmillis怎么用?C++ sleepmillis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sleepmillis函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
void ChunkManager::loadExistingRanges(const ChunkManager* oldManager) {
int tries = 3;
while (tries--) {
ChunkMap chunkMap;
set<Shard> shards;
ShardVersionMap shardVersions;
Timer t;
bool success = _load(chunkMap, shards, &shardVersions, oldManager);
if (success) {
log() << "ChunkManager: time to load chunks for " << _ns << ": "
<< t.millis() << "ms"
<< " sequenceNumber: " << _sequenceNumber
<< " version: " << _version.toString()
<< " based on: "
<< (oldManager ? oldManager->getVersion().toString() : "(empty)");
// TODO: Merge into diff code above, so we validate in one place
if (isChunkMapValid(chunkMap)) {
_chunkMap.swap(chunkMap);
_shards.swap(shards);
_shardVersions.swap(shardVersions);
_chunkRanges.reloadAll(_chunkMap);
return;
}
}
if (_chunkMap.size() < 10) {
_printChunks();
}
warning() << "ChunkManager loaded an invalid config for " << _ns << ", trying again";
sleepmillis(10 * (3 - tries));
}
// This will abort construction so we should never have a reference to an invalid config
msgasserted(13282, str::stream() << "Couldn't load a valid config for " << _ns
<< " after 3 attempts. Please try again.");
}
示例2: waitForSyncToFinish
bool waitForSyncToFinish(OperationContext* txn, string &errmsg) const {
// Wait for slave thread to finish syncing, so sources will be be
// reloaded with new saved state on next pass.
Timer t;
while ( 1 ) {
if ( syncing == 0 || t.millis() > 30000 )
break;
{
Lock::TempRelease t(txn->lockState());
relinquishSyncingSome = 1;
sleepmillis(1);
}
}
if ( syncing ) {
errmsg = "timeout waiting for sync() to finish";
return false;
}
return true;
}
示例3: while
void MiniWebServer::run() {
SockAddr from;
while ( 1 ) {
int s = accept(sock, from.getSockAddr(), &from.addressSize);
if ( s < 0 ) {
if ( errno == ECONNABORTED ) {
log() << "Listener on port " << port << " aborted." << endl;
return;
}
log() << "MiniWebServer: accept() returns " << s << " errno:" << errno << endl;
sleepmillis(200);
continue;
}
disableNagle(s);
RARELY log() << "MiniWebServer: connection accepted from " << from.toString() << endl;
accepted( s, from );
closesocket(s);
}
}
示例4: while
void WiredTigerSessionCache::shuttingDown() {
uint32_t actual = _shuttingDown.load();
uint32_t expected;
// Try to atomically set _shuttingDown flag, but just return if another thread was first.
do {
expected = actual;
actual = _shuttingDown.compareAndSwap(expected, expected | kShuttingDownMask);
if (actual & kShuttingDownMask)
return;
} while (actual != expected);
// Spin as long as there are threads in releaseSession
while (_shuttingDown.load() != kShuttingDownMask) {
sleepmillis(1);
}
closeAll();
}
示例5: while
/* static */
BSONObj WriteBackListener::waitFor( const ConnectionIdent& ident, const OID& oid ) {
Timer t;
Timer lastMessageTimer;
while ( t.minutes() < 60 ) {
{
scoped_lock lk( _seenWritebacksLock );
WBStatus s = _seenWritebacks[ident];
if ( oid < s.id ) {
// this means we're waiting for a GLE that already passed.
// it should be impossible because once we call GLE, no other
// writebacks should happen with that connection id
msgasserted( 14041 , str::stream() << "got writeback waitfor for older id " <<
" oid: " << oid << " s.id: " << s.id << " ident: " << ident.toString() );
}
else if ( oid == s.id ) {
return s.gle;
}
// Stay in lock so we can use the status
if( lastMessageTimer.seconds() > 10 ){
warning() << "waiting for writeback " << oid
<< " from connection " << ident.toString()
<< " for " << t.seconds() << " secs"
<< ", currently at id " << s.id << endl;
lastMessageTimer.reset();
}
}
sleepmillis( 10 );
}
uasserted( 13403 , str::stream() << "didn't get writeback for: " << oid
<< " after: " << t.millis() << " ms"
<< " from connection " << ident.toString() );
throw 1; // never gets here
}
示例6: while
void BackgroundSync::_run() {
Client::initThread("rsBackgroundSync");
AuthorizationSession::get(cc())->grantInternalAuthorization();
while (!inShutdown()) {
try {
_runProducer();
} catch (const DBException& e) {
std::string msg(str::stream() << "sync producer problem: " << redact(e));
error() << msg;
_replCoord->setMyHeartbeatMessage(msg);
sleepmillis(100); // sleep a bit to keep from hammering this thread with temp. errors.
} catch (const std::exception& e2) {
// redact(std::exception&) doesn't work
severe() << "sync producer exception: " << redact(e2.what());
fassertFailed(28546);
}
}
stop();
}
示例7: t
void t() {
for( int i = 0; i < 20; i++ ) {
sleepmillis(21);
string fn = "/tmp/t1";
MongoMMF f;
unsigned long long len = 1 * 1024 * 1024;
assert( f.create(fn, len, /*sequential*/rand()%2==0) );
{
char *p = (char *) f.getView();
assert(p);
// write something to the private view as a test
strcpy(p, "hello");
}
if( cmdLine.dur ) {
char *w = (char *) f.view_write();
strcpy(w + 6, "world");
}
MongoFileFinder ff;
ASSERT( ff.findByPath(fn) );
}
}
示例8: durThread
static void durThread() {
Client::initThread("dur");
const int HowOftenToGroupCommitMs = 100;
while( 1 ) {
try {
int millis = HowOftenToGroupCommitMs;
{
Timer t;
journalRotate(); // note we do this part outside of mongomutex
millis -= t.millis();
if( millis < 5 || millis > HowOftenToGroupCommitMs )
millis = 5;
}
sleepmillis(millis);
go();
}
catch(std::exception& e) {
log() << "exception in durThread " << e.what() << endl;
}
}
}
示例9: runThread
static void runThread() {
while (keepGoing) {
try {
if (current->lock_try( "test" )) {
int before = count.addAndFetch(1);
sleepmillis(3);
int after = count.loadRelaxed();
if (after != before) {
error() << " before: " << before << " after: " << after
<< endl;
}
current->unlock();
}
}
catch ( const DBException& ex ) {
log() << "*** !Could not try distributed lock." << causedBy( ex ) << endl;
}
}
}
示例10: name
void DataFileSync::run() {
Client::initThread( name().c_str() );
if (mmapv1GlobalOptions.syncdelay == 0) {
log() << "warning: --syncdelay 0 is not recommended and can have strange performance" << endl;
}
else if (mmapv1GlobalOptions.syncdelay == 1) {
log() << "--syncdelay 1" << endl;
}
else if (mmapv1GlobalOptions.syncdelay != 60) {
LOG(1) << "--syncdelay " << mmapv1GlobalOptions.syncdelay << endl;
}
int time_flushing = 0;
while ( ! inShutdown() ) {
_diaglog.flush();
if (mmapv1GlobalOptions.syncdelay == 0) {
// in case at some point we add an option to change at runtime
sleepsecs(5);
continue;
}
sleepmillis((long long) std::max(0.0, (mmapv1GlobalOptions.syncdelay * 1000) - time_flushing));
if ( inShutdown() ) {
// occasional issue trying to flush during shutdown when sleep interrupted
break;
}
Date_t start = jsTime();
StorageEngine* storageEngine = getGlobalEnvironment()->getGlobalStorageEngine();
int numFiles = storageEngine->flushAllFiles( true );
time_flushing = (int) (jsTime() - start);
_flushed(time_flushing);
if( logger::globalLogDomain()->shouldLog(logger::LogSeverity::Debug(1)) || time_flushing >= 10000 ) {
log() << "flushing mmaps took " << time_flushing << "ms " << " for " << numFiles << " files" << endl;
}
}
}
示例11: dassert
void BackgroundSync::handleSlaveDelay(uint64_t opTimestamp) {
dassert(_opSyncRunning);
uint64_t slaveDelayMillis = theReplSet->myConfig().slaveDelay * 1000;
uint64_t currTime = curTimeMillis64();
uint64_t timeOpShouldBeApplied = opTimestamp + slaveDelayMillis;
while (currTime < timeOpShouldBeApplied) {
uint64_t sleepTime = (timeOpShouldBeApplied - currTime);
// let's sleep for at most one second
sleepmillis((sleepTime < 1000) ? sleepTime : 1000);
// check if we should bail out, as we don't want to
// sleep the whole time possibly long delay time
// if we see we should be stopping
{
boost::unique_lock<boost::mutex> lck(_mutex);
if (!_opSyncShouldRun) {
break;
}
}
// reset currTime
currTime = curTimeMillis64();
}
}
示例12: run
bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
cc().curop()->suppressFromCurop();
cc().curop()->setExpectedLatencyMs( 30000 );
BSONElement e = cmdObj.firstElement();
if ( e.type() != jstOID ) {
errmsg = "need oid as first value";
return 0;
}
// get the command issuer's (a mongos) serverID
const OID id = e.__oid();
// the command issuer is blocked awaiting a response
// we want to do return at least at every 5 minutes so sockets don't timeout
BSONObj z;
if ( writeBackManager.getWritebackQueue(id.str())->queue.blockingPop( z, 5 * 60 /* 5 minutes */ ) ) {
LOG(1) << "WriteBackCommand got : " << z << endl;
result.append( "data" , z );
}
else {
result.appendBool( "noop" , true );
}
#ifdef _DEBUG
PseudoRandom r(static_cast<int64_t>(time(0)));
// Sleep a short amount of time usually
int sleepFor = r.nextInt32( 10 );
sleepmillis( sleepFor );
// Sleep a longer amount of time every once and awhile
int sleepLong = r.nextInt32( 50 );
if( sleepLong == 0 ) sleepsecs( 2 );
#endif
return true;
}
示例13: syncRollback
void BackgroundSync::_rollback(OperationContext* txn,
const HostAndPort& source,
stdx::function<DBClientBase*()> getConnection) {
// Abort only when syncRollback detects we are in a unrecoverable state.
// In other cases, we log the message contained in the error status and retry later.
auto status = syncRollback(txn,
OplogInterfaceLocal(txn, rsOplogName),
RollbackSourceImpl(getConnection, source, rsOplogName),
_replCoord);
if (status.isOK()) {
// When the syncTail thread sees there is no new data by adding something to the buffer.
_signalNoNewDataForApplier();
// Wait until the buffer is empty.
// This is an indication that syncTail has removed the sentinal marker from the buffer
// and reset its local lastAppliedOpTime via the replCoord.
while (!_buffer.empty()) {
sleepmillis(10);
if (inShutdown()) {
return;
}
}
// It is now safe to clear the ROLLBACK state, which may result in the applier thread
// transitioning to SECONDARY. This is safe because the applier thread has now reloaded
// the new rollback minValid from the database.
if (!_replCoord->setFollowerMode(MemberState::RS_RECOVERING)) {
warning() << "Failed to transition into " << MemberState(MemberState::RS_RECOVERING)
<< "; expected to be in state " << MemberState(MemberState::RS_ROLLBACK)
<< " but found self in " << _replCoord->getMemberState();
}
return;
}
if (ErrorCodes::UnrecoverableRollbackError == status.code()) {
fassertNoTrace(28723, status);
}
warning() << "rollback cannot proceed at this time (retrying later): " << status;
}
示例14: LOG
void BackgroundSync::markOplog() {
LOG(3) << "replset markOplog: " << _consumedOpTime << " "
<< theReplSet->lastOpTimeWritten << rsLog;
if (theReplSet->syncSourceFeedback.supportsUpdater()) {
_consumedOpTime = theReplSet->lastOpTimeWritten;
theReplSet->syncSourceFeedback.updateSelfInMap(theReplSet->lastOpTimeWritten);
}
else {
boost::unique_lock<boost::mutex> oplogLockSSF(theReplSet->syncSourceFeedback.oplock);
if (!hasCursor()) {
oplogLockSSF.unlock();
sleepmillis(500);
return;
}
if (!theReplSet->syncSourceFeedback.moreInCurrentBatch()) {
theReplSet->syncSourceFeedback.more();
}
if (!theReplSet->syncSourceFeedback.more()) {
theReplSet->syncSourceFeedback.tailCheck();
return;
}
// if this member has written the op at optime T
// we want to nextSafe up to and including T
while (_consumedOpTime < theReplSet->lastOpTimeWritten
&& theReplSet->syncSourceFeedback.more()) {
BSONObj temp = theReplSet->syncSourceFeedback.nextSafe();
_consumedOpTime = temp["ts"]._opTime();
}
// call more() to signal the sync target that we've synced T
theReplSet->syncSourceFeedback.more();
}
}
示例15: run
void run() {
Client::initThread("fsyncjob");
Client& c = cc();
{
scoped_lock lk(lockedForWritingMutex);
lockedForWriting++;
}
readlock lk("");
MemoryMappedFile::flushAll(true);
log() << "db is now locked for snapshotting, no writes allowed. use db.$cmd.sys.unlock.findOne() to unlock" << endl;
_ready = true;
while( 1 ) {
if( unlockRequested ) {
unlockRequested = false;
break;
}
sleepmillis(20);
}
{
scoped_lock lk(lockedForWritingMutex);
lockedForWriting--;
}
c.shutdown();
}