本文整理汇总了C++中Milliseconds函数的典型用法代码示例。如果您正苦于以下问题:C++ Milliseconds函数的具体用法?C++ Milliseconds怎么用?C++ Milliseconds使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Milliseconds函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST_F
/**
* Test that client cursors which have been marked as killed but are still pinned *do not* time out.
*/
TEST_F(CursorManagerTest, InactiveKilledCursorsThatAreStillPinnedShouldNotTimeout) {
CursorManager* cursorManager = useCursorManager();
auto clock = useClock();
// Make a cursor from the plan executor, and immediately kill it.
auto cursorPin = cursorManager->registerCursor(
_opCtx.get(),
{makeFakePlanExecutor(), NamespaceString{"test.collection"}, {}, false, BSONObj()});
const bool collectionGoingAway = false;
cursorManager->invalidateAll(
_opCtx.get(), collectionGoingAway, "KilledCursorsShouldTimeoutTest");
// Advance the clock to simulate time passing.
clock->advance(Milliseconds(CursorManager::kDefaultCursorTimeoutMinutes));
// The pin is still in scope, so it should not time out.
ASSERT_EQ(0UL, cursorManager->timeoutCursors(_opCtx.get(), clock->now()));
}
示例2: Milliseconds
void FrameHistory::record(const TimePoint& now, float zoom, const Duration& duration) {
int16_t zoomIndex = std::floor(zoom * 10.0);
if (firstFrame) {
changeTimes.fill(now);
for (int16_t z = 0; z <= zoomIndex; z++) {
opacities[z] = 255u;
}
firstFrame = false;
}
if (zoomIndex < previousZoomIndex) {
for (int16_t z = zoomIndex + 1; z <= previousZoomIndex; z++) {
changeTimes[z] = now;
changeOpacities[z] = opacities[z];
}
} else {
for (int16_t z = zoomIndex; z > previousZoomIndex; z--) {
changeTimes[z] = now;
changeOpacities[z] = opacities[z];
}
}
for (int16_t z = 0; z <= 255; z++) {
std::chrono::duration<float> timeDiff = now - changeTimes[z];
int32_t opacityChange = (duration == Milliseconds(0) ? 1 : (timeDiff / duration)) * 255;
if (z <= zoomIndex) {
opacities[z] = util::min(255, changeOpacities[z] + opacityChange);
} else {
opacities[z] = util::max(0, changeOpacities[z] - opacityChange);
}
}
changed = true;
if (zoomIndex != previousZoomIndex) {
previousZoomIndex = zoomIndex;
previousTime = now;
}
time = now;
}
示例3: Milliseconds
namespace mongo {
const WriteConcernOptions DistLockCatalog::kLocalWriteConcern(1,
WriteConcernOptions::SyncMode::UNSET,
Milliseconds(0));
const WriteConcernOptions DistLockCatalog::kMajorityWriteConcern(
WriteConcernOptions::kMajority,
// Note: Even though we're setting UNSET here, kMajority implies JOURNAL if journaling is
// supported by this mongod.
WriteConcernOptions::SyncMode::UNSET,
WriteConcernOptions::kWriteConcernTimeoutSystem);
DistLockCatalog::DistLockCatalog() = default;
DistLockCatalog::ServerInfo::ServerInfo(Date_t time, OID _electionId)
: serverTime(std::move(time)), electionId(std::move(_electionId)) {}
} // namespace mongo
示例4: lock
void NoopWriter::_writeNoop(OperationContext* opCtx) {
// Use GlobalLock + lockMMAPV1Flush instead of DBLock to allow return when the lock is not
// available. It may happen when the primary steps down and a shared global lock is acquired.
Lock::GlobalLock lock(
opCtx, MODE_IX, Date_t::now() + Milliseconds(1), Lock::InterruptBehavior::kLeaveUnlocked);
if (!lock.isLocked()) {
LOG(1) << "Global lock is not available skipping noopWrite";
return;
}
opCtx->lockState()->lockMMAPV1Flush();
auto replCoord = ReplicationCoordinator::get(opCtx);
// Its a proxy for being a primary
if (!replCoord->canAcceptWritesForDatabase(opCtx, "admin")) {
LOG(1) << "Not a primary, skipping the noop write";
return;
}
auto lastAppliedOpTime = replCoord->getMyLastAppliedOpTime();
// _lastKnownOpTime is not protected by lock as its used only by one thread.
if (lastAppliedOpTime != _lastKnownOpTime) {
LOG(1) << "Not scheduling a noop write. Last known OpTime: " << _lastKnownOpTime
<< " != last primary OpTime: " << lastAppliedOpTime;
} else {
if (writePeriodicNoops.load()) {
const auto logLevel = getTestCommandsEnabled() ? 0 : 1;
LOG(logLevel)
<< "Writing noop to oplog as there has been no writes to this replica set in over "
<< _writeInterval;
writeConflictRetry(
opCtx, "writeNoop", NamespaceString::kRsOplogNamespace.ns(), [&opCtx] {
WriteUnitOfWork uow(opCtx);
opCtx->getClient()->getServiceContext()->getOpObserver()->onOpMessage(opCtx,
kMsgObj);
uow.commit();
});
}
}
_lastKnownOpTime = replCoord->getMyLastAppliedOpTime();
LOG(1) << "Set last known op time to " << _lastKnownOpTime;
}
示例5: TEST
TEST(AsyncTimerMock, Cancel) {
AsyncTimerFactoryMock factory;
// Set a timer
bool fired = false;
auto timer = factory.make(Milliseconds(100));
timer->asyncWait([&fired](std::error_code ec) {
// This timer should have been canceled
ASSERT(ec);
ASSERT(ec == asio::error::operation_aborted);
fired = true;
});
// Cancel timer
timer->cancel();
// Ensure that its handler was called
ASSERT(fired);
}
示例6: ScheduleTasks
void ScheduleTasks() override
{
scheduler.Schedule(Seconds(8), Seconds(10), [this](TaskContext task)
{
DoCastAOE(SPELL_ARCANE_BARRAGE_VOLLEY);
task.Repeat(Seconds(8), Seconds(10));
});
scheduler.Schedule(Seconds(10), Seconds(11), [this](TaskContext task)
{
if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 45.0f, true))
DoCast(target, SPELL_ARCANE_BUFFET);
task.Repeat(Seconds(15), Seconds(20));
});
scheduler.Schedule(Seconds(5), [this](TaskContext task)
{
Talk(SAY_REPEAT_SUMMON);
std::list<uint8> summonSpells = { 0, 1, 2 };
uint8 spell = Trinity::Containers::SelectRandomContainerElement(summonSpells);
DoCast(me, EtherealSphereSummonSpells[spell]);
summonSpells.remove(spell);
if (IsHeroic())
{
spell = Trinity::Containers::SelectRandomContainerElement(summonSpells);
task.Schedule(Milliseconds(2500), [this, spell](TaskContext /*task*/)
{
DoCast(me, EtherealSphereHeroicSummonSpells[spell]);
});
}
task.Schedule(Seconds(33), Seconds(35), [this](TaskContext /*task*/)
{
DummyEntryCheckPredicate pred;
summons.DoAction(ACTION_SUMMON, pred);
});
task.Repeat(Seconds(45), Seconds(47));
});
}
示例7: invariant
void NetworkInterfaceMock::_enqueueOperation_inlock(
mongo::executor::NetworkInterfaceMock::NetworkOperation&& op) {
auto insertBefore =
std::upper_bound(std::begin(_unscheduled),
std::end(_unscheduled),
op,
[](const NetworkOperation& a, const NetworkOperation& b) {
return a.getNextConsiderationDate() < b.getNextConsiderationDate();
});
_unscheduled.emplace(insertBefore, std::move(op));
if (op.getRequest().timeout != RemoteCommandRequest::kNoTimeout) {
invariant(op.getRequest().timeout >= Milliseconds(0));
ResponseStatus response(ErrorCodes::NetworkTimeout, "Network timeout");
auto action = stdx::bind(
&NetworkInterfaceMock::_cancelCommand_inlock, this, op.getCallbackHandle(), response);
_alarms.emplace(_now_inlock() + op.getRequest().timeout, action);
}
}
示例8: Milliseconds
namespace util {
constexpr float tileSize = 512;
/*
* The maximum extent of a feature that can be safely stored in the buffer.
* In practice, all features are converted to this extent before being added.
*
* Positions are stored as signed 16bit integers.
* One bit is lost for signedness to support features extending past the left edge of the tile.
* One bit is lost because the line vertex buffer packs 1 bit of other data into the int.
* One bit is lost to support features extending past the extent on the right edge of the tile.
* This leaves us with 2^13 = 8192
*/
constexpr int32_t EXTENT = 8192;
constexpr double DEG2RAD = M_PI / 180.0;
constexpr double RAD2DEG = 180.0 / M_PI;
constexpr double M2PI = M_PI * 2;
constexpr double EARTH_RADIUS_M = 6378137;
constexpr double LATITUDE_MAX = 85.051128779806604;
constexpr double LONGITUDE_MAX = 180;
constexpr double DEGREES_MAX = 360;
constexpr double PITCH_MAX = M_PI / 3;
constexpr double MIN_ZOOM = 0.0;
constexpr double MAX_ZOOM = 25.5;
constexpr float MIN_ZOOM_F = MIN_ZOOM;
constexpr float MAX_ZOOM_F = MAX_ZOOM;
constexpr uint64_t DEFAULT_MAX_CACHE_SIZE = 50 * 1024 * 1024;
constexpr Duration DEFAULT_FADE_DURATION = Milliseconds(300);
constexpr Seconds CLOCK_SKEW_RETRY_TIMEOUT { 30 };
constexpr UnitBezier DEFAULT_TRANSITION_EASE = { 0, 0, 0.25, 1 };
constexpr int DEFAULT_RATE_LIMIT_TIMEOUT = 5;
constexpr const char* API_BASE_URL = "https://api.mapbox.com";
} // namespace util
示例9: TEST_F
TEST_F(TransactionCoordinatorServiceTest,
CoordinatorIsNotCanceledIfDeadlinePassesButHasReceivedParticipantList) {
auto coordinatorService = TransactionCoordinatorService::get(operationContext());
const auto deadline = executor()->now() + Milliseconds(1000 * 60 * 10 /* 10 hours */);
coordinatorService->createCoordinator(operationContext(), _lsid, _txnNumber, deadline);
// Deliver the participant list before the deadline.
ASSERT(boost::none !=
coordinatorService->coordinateCommit(
operationContext(), _lsid, _txnNumber, kTwoShardIdSet));
// Reach the deadline.
network()->enterNetwork();
network()->advanceTime(deadline);
network()->exitNetwork();
// The coordinator should still exist.
ASSERT(boost::none !=
coordinatorService->coordinateCommit(
operationContext(), _lsid, _txnNumber, kTwoShardIdSet));
}
示例10: Reset
void Reset() override
{
me->SetReactState(REACT_PASSIVE);
me->SetDisplayId(me->GetCreatureTemplate()->Modelid2);
DoCastSelf(SPELL_PUTRID_MUSHROOM);
DoCastSelf(SPELL_SHRINK, true);
DoCastSelf(SPELL_GROW, true);
if (me->GetEntry() == NPC_HEALTHY_MUSHROOM)
{
DoCastSelf(SPELL_POWER_MUSHROOM_VISUAL_AURA);
_active = true;
}
else
DoCastSelf(SPELL_POISONOUS_MUSHROOM_VISUAL_AURA);
_scheduler.Schedule(Milliseconds(800), [this](TaskContext /*context*/)
{
DoCastSelf(SPELL_GROW, true);
});
}
示例11: tick
void tick( Milliseconds current_time_in_milliseconds )
{
if ( m_last_flush_time == Milliseconds( 0 ) )
{
// initialize last_flush_time
m_last_flush_time = current_time_in_milliseconds;
}
else
{
// is it time to check?
if ( ( current_time_in_milliseconds - m_last_flush_time ) > m_flush_period_in_milliseconds )
{
// yes, remember when we did
m_last_flush_time = current_time_in_milliseconds;
// flush any expired addresses
flushKnownAddressesFromMap(
m_known_entity_addresses, m_expiry_time_in_milliseconds, current_time_in_milliseconds );
}
}
}
示例12: _viewMode
AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
const NamespaceString& nss,
LockMode modeDB,
LockMode modeColl,
ViewMode viewMode)
: _viewMode(viewMode),
_autoDb(opCtx, nss.db(), modeDB),
_collLock(opCtx->lockState(), nss.ns(), modeColl),
_coll(_autoDb.getDb() ? _autoDb.getDb()->getCollection(opCtx, nss) : nullptr) {
Database* db = _autoDb.getDb();
// If the database exists, but not the collection, check for views.
if (_viewMode == ViewMode::kViewsForbidden && db && !_coll &&
db->getViewCatalog()->lookup(opCtx, nss.ns()))
uasserted(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "Namespace " << nss.ns() << " is a view, not a collection");
// Wait for a configured amount of time after acquiring locks if the failpoint is enabled.
MONGO_FAIL_POINT_BLOCK(setAutoGetCollectionWait, customWait) {
const BSONObj& data = customWait.getData();
sleepFor(Milliseconds(data["waitForMillis"].numberInt()));
}
}
示例13: UpdateAI
void UpdateAI(uint32 diff) override
{
if (!UpdateVictim())
return;
events.Update(diff);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
while (uint32 eventId = events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_POISON:
if (!me->HasAura(SPELL_WIDOWS_EMBRACE_HELPER))
DoCastAOE(SPELL_POISON_BOLT_VOLLEY);
events.Repeat(randtime(Seconds(8), Seconds(15)));
break;
case EVENT_FIRE:
if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0))
DoCast(target, SPELL_RAIN_OF_FIRE);
events.Repeat(randtime(Seconds(6), Seconds(18)));
break;
case EVENT_FRENZY:
if (Aura* widowsEmbrace = me->GetAura(SPELL_WIDOWS_EMBRACE_HELPER))
events.ScheduleEvent(EVENT_FRENZY, Milliseconds(widowsEmbrace->GetDuration()+1));
else
{
DoCast(SPELL_FRENZY);
Talk(EMOTE_FRENZY);
events.Repeat(Minutes(1) + randtime(Seconds(0), Seconds(20)));
}
break;
}
}
DoMeleeAttackIfReady();
}
示例14: ProcessJoystickEvents
bool WindowImpl::PopEvent(Event& event, bool block)
{
// If the event queue is empty, let's first check if new events are available from the OS
if (myEvents.empty())
{
if (!block)
{
// Non-blocking mode: process events and continue
ProcessJoystickEvents();
ProcessEvents();
}
else
{
// Blocking mode: process events until one is triggered
// Here we use a manual wait loop instead of the optimized
// wait-event provided by the OS, so that we don't skip joystick
// events (which require polling)
while (myEvents.empty())
{
ProcessJoystickEvents();
ProcessEvents();
Sleep(Milliseconds(10));
}
}
}
// Pop the first event of the queue, if it is not empty
if (!myEvents.empty())
{
event = myEvents.front();
myEvents.pop();
return true;
}
return false;
}
示例15: lock
Status SyncSourceFeedback::_updateUpstream(OperationContext* txn, BackgroundSync* bgsync) {
Reporter* reporter;
{
stdx::lock_guard<stdx::mutex> lock(_mtx);
reporter = _reporter;
}
auto syncTarget = reporter->getTarget();
auto triggerStatus = reporter->trigger();
if (!triggerStatus.isOK()) {
warning() << "unable to schedule reporter to update replication progress on " << syncTarget
<< ": " << triggerStatus;
return triggerStatus;
}
auto status = reporter->join();
if (!status.isOK()) {
log() << "SyncSourceFeedback error sending update to " << syncTarget << ": " << status;
// Some errors should not cause result in blacklisting the sync source.
if (status != ErrorCodes::InvalidSyncSource) {
// The command could not be created because the node is now primary.
} else if (status != ErrorCodes::NodeNotFound) {
// The command could not be created, likely because this node was removed from the set.
} else {
// Blacklist sync target for .5 seconds and find a new one.
stdx::lock_guard<stdx::mutex> lock(_mtx);
auto replCoord = repl::ReplicationCoordinator::get(txn);
replCoord->blacklistSyncSource(syncTarget, Date_t::now() + Milliseconds(500));
bgsync->clearSyncTarget();
}
}
return status;
}