void CappedInsertNotifier::_wait(stdx::unique_lock<stdx::mutex>& lk, uint64_t prevVersion, Microseconds timeout) const { while (!_dead && prevVersion == _version) { if (timeout == Microseconds::max()) { _notifier.wait(lk); } else if (stdx::cv_status::timeout == _notifier.wait_for(lk, timeout.toSystemDuration())) { return; } } }
Status ShardingState::_waitForInitialization(OperationContext* txn) { if (enabled()) return Status::OK(); stdx::unique_lock<stdx::mutex> lk(_mutex); { const Microseconds timeRemaining(txn->getRemainingMaxTimeMicros()); while (_getInitializationState() == InitializationState::kInitializing || _getInitializationState() == InitializationState::kNew) { if (timeRemaining.count()) { const auto deadline = stdx::chrono::system_clock::now() + timeRemaining; if (stdx::cv_status::timeout == _initializationFinishedCondition.wait_until(lk, deadline)) { return Status(ErrorCodes::ExceededTimeLimit, "Initializing sharding state exceeded time limit"); } } else { _initializationFinishedCondition.wait(lk); } } } auto initializationState = _getInitializationState(); if (initializationState == InitializationState::kInitialized) { fassertStatusOK(34349, _initializationStatus); return Status::OK(); } if (initializationState == InitializationState::kError) { return Status(ErrorCodes::ManualInterventionRequired, str::stream() << "Server's sharding metadata manager failed to initialize and will " "remain in this state until the instance is manually reset" << causedBy(_initializationStatus)); } MONGO_UNREACHABLE; }
int main(){ std::cout << "0\t"; for(int p = 0; p < NUM_CORES; ++p){ std::cout << EXTRA_THREADS[p] + 1 << '\t'; } std::cout << std::endl; for(int n = 0; n < N; ++n){ Clock::time_point t0 = Clock::now(); iteration(); Clock::time_point t1 = Clock::now(); Microseconds ms = std::chrono::duration_cast<Microseconds>(t1 - t0); std::cout << ms.count() << '\t'; for(int p = 0; p < NUM_CORES; ++p){ std::vector<std::thread> threads; t0 = Clock::now(); for(int i = 0; i < EXTRA_THREADS[p]; ++i){ threads.push_back(std::thread(lock)); } lock(); for(auto& thread : threads){ thread.join(); } t1 = Clock::now(); ms = std::chrono::duration_cast<Microseconds>(t1 - t0); std::cout << ms.count() << '\t'; } std::cout << std::endl; } return 0; }
inline void setValue(tinyxml2::XMLElement& elt, const Microseconds& microseconds) { elt.DeleteChildren(); setChildAttribute(elt, "Microseconds", microseconds.count()); setChildAttribute(elt, "Milliseconds", us2ms(microseconds)); setChildAttribute(elt, "Seconds", us2sec(microseconds)); }
inline void Formatter(FormatData& formatData, const Microseconds& microseconds) { Formatter(formatData, microseconds.count()); formatData.string.append(U"us", 2); }