本文整理汇总了C++中Milliseconds类的典型用法代码示例。如果您正苦于以下问题:C++ Milliseconds类的具体用法?C++ Milliseconds怎么用?C++ Milliseconds使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Milliseconds类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: incrementNow
void NetworkInterfaceMock::incrementNow(Milliseconds inc) {
boost::lock_guard<boost::mutex> lk(_mutex);
invariant(inc.total_milliseconds() > 0);
_now += inc.total_milliseconds();
_executor->signalWorkForTest();
_timeElapsed.notify_all();
}
示例2: randtime
Milliseconds randtime(Milliseconds const& min, Milliseconds const& max)
{
long long diff = max.count() - min.count();
ASSERT(diff >= 0);
ASSERT(diff <= (uint32)-1);
return min + Milliseconds(urand(0, diff));
}
示例3: invariant
Status LegacyReplicationCoordinator::_stepDownHelper(OperationContext* txn,
bool force,
const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime) {
invariant(getReplicationMode() == modeReplSet);
if (!getCurrentMemberState().primary()) {
return Status(ErrorCodes::NotMaster, "not primary so can't step down");
}
if (!force) {
Status status = _waitForSecondary(initialWaitTime, Milliseconds(10 * 1000));
if (!status.isOK()) {
return status;
}
}
// step down
bool worked = repl::theReplSet->stepDown(txn, stepdownTime.total_seconds());
if (!worked) {
return Status(ErrorCodes::NotMaster, "not primary so can't step down");
}
if (postStepdownWaitTime.total_milliseconds() > 0) {
log() << "waiting for secondaries to catch up" << endl;
// The only caller of this with a non-zero postStepdownWaitTime is
// stepDownAndWaitForSecondary, and the only caller of that is the shutdown command
// which doesn't actually care if secondaries failed to catch up here, so we ignore the
// return status of _waitForSecondary
_waitForSecondary(postStepdownWaitTime, Milliseconds(0));
}
return Status::OK();
}
示例4: roundTime
Date_t roundTime(Date_t now, Milliseconds period) {
// Note: auto type deduction is explicitly avoided here to ensure rigid type correctness
long long clock_duration = now.toMillisSinceEpoch();
long long now_next_period = clock_duration + period.count();
long long excess_time(now_next_period % period.count());
long long next_time = now_next_period - excess_time;
return Date_t::fromMillisSinceEpoch(next_time);
}
示例5: lk
void NetworkInterfaceASIO::waitForWorkUntil(Date_t when) {
stdx::unique_lock<stdx::mutex> lk(_executorMutex);
// TODO: This can be restructured with a lambda.
while (!_isExecutorRunnable) {
const Milliseconds waitTime(when - now());
if (waitTime <= Milliseconds(0)) {
break;
}
_isExecutorRunnableCondition.wait_for(lk, waitTime.toSystemDuration());
}
_isExecutorRunnable = false;
}
示例6: wait
LockResult CondVarLockGrantNotification::wait(Milliseconds timeout) {
stdx::unique_lock<stdx::mutex> lock(_mutex);
return _cond.wait_for(
lock, timeout.toSystemDuration(), [this] { return _result != LOCK_INVALID; })
? _result
: LOCK_TIMEOUT;
}
示例7: sentry
bool Timer::update(const Milliseconds& now)
{
if(_active == false)
return false;
bool hasElapsed = now >= _finished;
Timer::Sentry sentry(_sentry);
DateTime ts;
while( _active && now >= _finished )
{
Milliseconds currentTs = _finished;
// We add another interval before sending the signal
// since sending might throw an exception. We would
// skip recalculating the new time then and may loop.
_finished += _interval;
if( ! sentry )
return hasElapsed;
timeout.send();
// We send the signal with datetime only, when someone is
// connected since it will take some time to calculate a
// DateTime object from milliseconds.
if (timeoutts.connectionCount() > 0)
{
struct tm tim;
time_t sec = static_cast<time_t>(currentTs.totalSeconds());
localtime_r(&sec, &tim);
DateTime dueTime(tim.tm_year + 1900, tim.tm_mon + 1, tim.tm_mday,
tim.tm_hour, tim.tm_min, tim.tm_sec,
0, currentTs.totalUSecs() % 1000000);
timeoutts.send(dueTime);
}
if (_once)
stop();
}
return hasElapsed;
}
示例8:
DistLockCatalogImpl::DistLockCatalogImpl(RemoteCommandTargeter* targeter,
ShardRegistry* shardRegistry,
Milliseconds writeConcernTimeout)
: _client(shardRegistry),
_targeter(targeter),
_writeConcern(WriteConcernOptions(WriteConcernOptions::kMajority,
WriteConcernOptions::JOURNAL,
writeConcernTimeout.count())),
_lockPingNS(LockpingsType::ConfigNS),
_locksNS(LocksType::ConfigNS) {}
示例9: sleepTime
void IgmpSender::threadFunction()
{
Milliseconds sleepTime(SLEEP_INTERVAL);
while (!_stopThread) {
Milliseconds before;
_igmpPacket->send();
Milliseconds after;
after = after - before;
int slept = after.getTime();
while (!_stopThread && slept < _interval * 1000) {
sleepTime.sleep();
slept += SLEEP_INTERVAL;
}
}
}
示例10:
DistLockCatalogImpl::DistLockCatalogImpl(RemoteCommandTargeter* targeter,
RemoteCommandRunner* executor,
Milliseconds writeConcernTimeout):
_cmdRunner(executor),
_targeter(targeter),
_writeConcern(WriteConcernOptions(WriteConcernOptions::kMajority,
WriteConcernOptions::JOURNAL,
writeConcernTimeout.count())),
_lockPingNS(LockpingsType::ConfigNS),
_locksNS(LocksType::ConfigNS) {
}
示例11: end
void TimerBase::threadFunction()
{
Milliseconds begin;
Milliseconds end(0), diff(0);
_active = true;
Interval aux;
while (_run) {
aux = _interval - (end - begin);
end.setTimestamp();
if (!_run) break;
Milliseconds(aux).sleep(); // dorme de 5 em 5ms
begin.setTimestamp();
if (!_run) break;
timeout();
if (_singleShot) break;
}
_active = false;
_run = false;
}
示例12: shutdown
Status ServiceExecutorReserved::shutdown(Milliseconds timeout) {
LOG(3) << "Shutting down reserved executor";
stdx::unique_lock<stdx::mutex> lock(_mutex);
_stillRunning.store(false);
_threadWakeup.notify_all();
bool result = _shutdownCondition.wait_for(lock, timeout.toSystemDuration(), [this]() {
return _numRunningWorkerThreads.load() == 0;
});
return result
? Status::OK()
: Status(ErrorCodes::Error::ExceededTimeLimit,
"reserved executor couldn't shutdown all worker threads within time limit.");
}
示例13: SharedRecursiveLock
//-----------------------------------------------------------------------
HTTP::HTTPQuery::HTTPQuery(
const make_private &,
HTTPPtr outer,
IHTTPQueryDelegatePtr delegate,
bool isPost,
const char *userAgent,
const char *url,
const BYTE *postData,
size_t postDataLengthInBytes,
const char *postDataMimeType,
Milliseconds timeout
) :
SharedRecursiveLock(outer ? *outer : SharedRecursiveLock::create()),
MessageQueueAssociator(IHelper::getServiceQueue()),
mOuter(outer),
mDelegate(IHTTPQueryDelegateProxy::create(Helper::getServiceQueue(), delegate)),
mIsPost(isPost),
mUserAgent(userAgent),
mURL(url),
mMimeType(postDataMimeType),
mTimeout(timeout),
mStatusCode(HttpStatusCode::None)
{
ZS_LOG_DEBUG(log("created"))
if (0 != postDataLengthInBytes) {
mPostData.CleanNew(postDataLengthInBytes);
memcpy(mPostData.BytePtr(), postData, postDataLengthInBytes);
}
ZS_EVENTING_8(
x, i, Debug, ServicesHttpQueryCreate, os, Http, Start,
puid, id, mID,
bool, isPost, mIsPost,
string, userAgent, mUserAgent,
string, url, mURL,
buffer, postData, postData,
size, postSize, postDataLengthInBytes,
string, postDataMimeType, postDataMimeType,
duration, timeout, timeout.count()
);
}
示例14: start
void Timer::start(const DateTime& startTime, const Milliseconds& interval)
{
if (interval <= Timespan(0))
throw std::logic_error("cannot run interval timer without interval");
if (_active)
stop();
_active = true;
_interval = interval;
_once = false;
Timespan systemTime = Clock::getSystemTicks();
struct tm tim;
time_t sec = static_cast<time_t>(systemTime.totalSeconds());
localtime_r(&sec, &tim);
DateTime now(tim.tm_year + 1900, tim.tm_mon + 1, tim.tm_mday,
tim.tm_hour, tim.tm_min, tim.tm_sec,
0, systemTime.totalUSecs() % 1000000);
if (startTime > now)
{
_finished = systemTime + (startTime - now);
}
else
{
// startTime =< now
Timespan elapsed = now - startTime;
uint64_t ticksElapsed = elapsed.totalMSecs() / interval.totalMSecs();
DateTime tickTime = startTime + (ticksElapsed + 1) * Timespan(interval);
Timespan delay = tickTime - now;
_finished = systemTime + (tickTime - now);
}
if (_selector)
_selector->onTimerChanged(*this);
}
示例15: Formatter
inline void Formatter(FormatData& formatData, const Milliseconds& milliseconds)
{
Formatter(formatData, milliseconds.count());
formatData.string.append(U"ms", 2);
}