本文整理汇总了C++中std::chrono::milliseconds::count方法的典型用法代码示例。如果您正苦于以下问题:C++ milliseconds::count方法的具体用法?C++ milliseconds::count怎么用?C++ milliseconds::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::chrono::milliseconds
的用法示例。
在下文中一共展示了milliseconds::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scheduleAfterDelay
void GMainLoopSource::scheduleAfterDelay(const char* name, std::function<void ()> function, std::chrono::milliseconds delay, int priority, std::function<void ()> destroyFunction, GMainContext* context)
{
cancel();
ASSERT(!m_context.source);
m_context = {
adoptGRef(g_timeout_source_new(delay.count())),
nullptr, // cancellable
nullptr, // socketCancellable
WTF::move(function),
nullptr, // boolCallback
nullptr, // socketCallback
WTF::move(destroyFunction)
};
scheduleTimeoutSource(name, reinterpret_cast<GSourceFunc>(voidSourceCallback), priority, context);
}
示例2: locker
std::unique_ptr<MessageDecoder> Connection::waitForSyncReply(uint64_t syncRequestID, std::chrono::milliseconds timeout, unsigned syncSendFlags)
{
double absoluteTime = currentTime() + (timeout.count() / 1000.0);
bool timedOut = false;
while (!timedOut) {
// First, check if we have any messages that we need to process.
m_syncMessageState->dispatchMessages(0);
{
MutexLocker locker(m_syncReplyStateMutex);
// Second, check if there is a sync reply at the top of the stack.
ASSERT(!m_pendingSyncReplies.isEmpty());
PendingSyncReply& pendingSyncReply = m_pendingSyncReplies.last();
ASSERT_UNUSED(syncRequestID, pendingSyncReply.syncRequestID == syncRequestID);
// We found the sync reply, or the connection was closed.
if (pendingSyncReply.didReceiveReply || !m_shouldWaitForSyncReplies)
return std::move(pendingSyncReply.replyDecoder);
}
// Processing a sync message could cause the connection to be invalidated.
// (If the handler ends up calling Connection::invalidate).
// If that happens, we need to stop waiting, or we'll hang since we won't get
// any more incoming messages.
if (!isValid())
return nullptr;
// We didn't find a sync reply yet, keep waiting.
// This allows the WebProcess to still serve clients while waiting for the message to return.
// Notably, it can continue to process accessibility requests, which are on the main thread.
if (syncSendFlags & SpinRunLoopWhileWaitingForReply) {
#if PLATFORM(MAC)
// FIXME: Although we run forever, any events incoming will cause us to drop out and exit out. This however doesn't
// account for a timeout value passed in. Timeout is always NoTimeout in these cases, but that could change.
RunLoop::current()->runForDuration(1e10);
timedOut = currentTime() >= absoluteTime;
#endif
} else
timedOut = !m_syncMessageState->wait(absoluteTime);
}
return nullptr;
}
示例3: poll
void Poller::poll(std::chrono::milliseconds const& timeout)
{
size_t begin_seq = event_buffer_.published_sequence() + 1;
epoll_event* free_event_begin = &event_buffer_.raw_event(begin_seq);
size_t next_seq;
while ((next_seq = event_buffer_.max_usable_block_sequence()) < begin_seq)
std::this_thread::yield(); // TODO wait strategy
event_buffer_.claim(next_seq);
int event_num = ::epoll_wait(raw_handle_, free_event_begin, next_seq - begin_seq + 1,
timeout.count());
if (event_num > 0) {
event_buffer_.publish(begin_seq + event_num - 1);
} else if (event_num == -1) { // TODO EINTR
throw std::system_error(util::errc(), "Poller::poll");
}
}
示例4: time_format
//ddd:hh:mm:ss.ccc
std::string time_format(const std::chrono::milliseconds duration)
{
char time[17] = " . "; //ddd:hh:mm:ss.ccc
int char_0 = static_cast<int>('0');
typedef std::chrono::duration<int, std::ratio<24*3600> > days;
long long c = duration.count() % 1000;
long long s = std::chrono::duration_cast<std::chrono::seconds>(duration).count() % 60;
int m = std::chrono::duration_cast<std::chrono::minutes>(duration).count() % 60;
int h = std::chrono::duration_cast<std::chrono::hours>(duration).count() % 24;
int d = std::chrono::duration_cast<days>(duration).count();
if (d/100)
time[0] = char_0 + d/100;
if (d/10)
time[1] = char_0 + (d/10)%10;
if (d)
{
time[2] = char_0 + d%10;
time[3] = ':';
}
if (d || h/10)
time[4] = char_0 + h/10;
if (d || h)
{
time[5] = char_0 + h%10;
time[6] = ':';
}
if (d || h || m/10)
time[7] = char_0 + m/10;
if (d || h || m)
{
time[8] = char_0 + m%10;
time[9] = ':';
}
if (d || h || m || s/10)
time[10] = char_0 + s/10;
time[11] = char_0 + s%10;
time[13] = char_0 + c/100;
time[14] = char_0 + (c/10)%10;
time[15] = char_0 + c%10;
return std::string(time);
}
示例5: Cls_OnInitDialog
BOOL CMultithreadDlg::Cls_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
hList = GetDlgItem(hwnd, IDC_LIST1);
SendMessage(hList, LB_ADDSTRING, 0, LPARAM(std::to_wstring(FindTime().count() * 1.0 / 1000).c_str()));
//InitializeCriticalSection(&CriticalSelection);
HANDLE handle1 = CreateThread(NULL, 0, Thread1, (LPVOID)0, 0, NULL);
HANDLE handle2 = CreateThread(NULL, 0, Thread1, (LPVOID)1, 0, NULL);
HANDLE handle3 = CreateThread(NULL, 0, Thread1, (LPVOID)2, 0, NULL);
WaitForSingleObject(handle1, INFINITE);
WaitForSingleObject(handle2, INFINITE);
WaitForSingleObject(handle3, INFINITE);
//DeleteCriticalSection(&CriticalSelection);
SendMessage(hList, LB_ADDSTRING, 0, LPARAM(std::to_wstring(times.count() * 1.0 / 1000).c_str()));
ofs0.close();
ofs1.close();
ofs.close();
return TRUE;
}
示例6:
std::pair<AlgorithmIdentifier, std::vector<uint8_t>>
pbes2_encrypt_msec(const secure_vector<uint8_t>& key_bits,
const std::string& passphrase,
std::chrono::milliseconds msec,
size_t* out_iterations_if_nonnull,
const std::string& cipher,
const std::string& digest,
RandomNumberGenerator& rng)
{
size_t msec_in_iterations_out = static_cast<size_t>(msec.count());
auto ret = pbes2_encrypt_shared(key_bits, passphrase, &msec_in_iterations_out, 0, cipher, digest, rng);
if(out_iterations_if_nonnull)
*out_iterations_if_nonnull = msec_in_iterations_out;
return ret;
}
示例7: printResult
void CScreen::printResult(const int number, const int depth, const int selectivity, const uint64_t P, const uint64_t O, const int score, const std::chrono::milliseconds duration, const uint64_t NodeCounter, const std::string& PV)
{
positionCounter.fetch_add(1, std::memory_order_relaxed);
if (verbose == 1)
{
if (!flag.test_and_set(std::memory_order_acquire))
{
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - lastPrint).count() > 500)
{
if (positions)
{
std::unique_lock<std::mutex> lock(mtx);
std::cout << "\r" << ThousandsSeparator(positionCounter.load(std::memory_order_acquire)) << " positions solved. " << positionCounter.load(std::memory_order_acquire) * 100 / positions << "% " << ETA();
fflush(stdout);
}
else
{
std::unique_lock<std::mutex> lock(mtx);
std::cout << "\r" << ThousandsSeparator(positionCounter.load(std::memory_order_acquire)) << " positions solved in " << time_format(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime));
fflush(stdout);
}
lastPrint = std::chrono::high_resolution_clock::now();
}
flag.clear(std::memory_order_release);
}
}
else if (verbose == 2)
{
std::unique_lock<std::mutex> lock(mtx);
printf("%*d|%6s| %+2.2d |%16s|%*s|%*s| %s\n", width_number, number, DepthSelectivity(depth, selectivity, P, O).c_str(), score,
time_format(duration).c_str(), width_nodes, ThousandsSeparator(NodeCounter).c_str(),
width_nps, (duration.count() == 0 ? nullptr : ThousandsSeparator(NodeCounter * 1000ULL / duration.count()).c_str()),
PV.c_str());
}
else if (verbose == 3)
{
std::string L1, L2;
GetLines(L1, L2);
std::unique_lock<std::mutex> lock(mtx);
std::cout << L2 << std::endl;
}
}
示例8: if
std::shared_ptr<TcpSocket> TcpSocket::Accept(const std::chrono::milliseconds& timeout)
{
std::unique_ptr<timeval> tv;
if (timeout.count() != 0)
{
std::chrono::seconds timeoutSeconds = std::chrono::duration_cast<std::chrono::seconds>(timeout);
std::chrono::milliseconds timeoutRemainder = timeout - std::chrono::duration_cast<std::chrono::milliseconds>(timeoutSeconds);
std::chrono::microseconds timeoutMicroseconds = std::chrono::duration_cast<std::chrono::microseconds>(timeoutRemainder);
tv.reset(new timeval());
tv->tv_sec = (decltype(tv->tv_sec))timeoutSeconds.count();
tv->tv_usec = (decltype(tv->tv_usec))timeoutMicroseconds.count();
}
// Select the server socket for checking incoming connection.
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(mSocket, &readfds);
// Wait until timeout for incoming connection, tv = NULL for blocking operation.
int32_t result = select((int32_t)mSocket + 1, &readfds, nullptr, nullptr, tv.get());
if (result == SOCKET_ERROR)
{
// select error
int32_t error = GetSocketError();
THROW(SocketException, error);
}
else if (result > 0)
{
// Accept a client socket
SOCKET socket = accept(mSocket, nullptr, nullptr);
if (socket == INVALID_SOCKET)
{
return nullptr;
}
std::shared_ptr<TcpSocket> clientSocket = std::make_shared<TcpSocket>(socket);
clientSocket->SetNonblocking(true);
return clientSocket;
}
return nullptr;
}
示例9: updateWriteTimeout
void AsyncMcClientImpl::updateWriteTimeout(std::chrono::milliseconds timeout) {
if (!timeout.count()) {
return;
}
auto selfWeak = selfPtr_;
eventBase_.runInEventBaseThread([selfWeak, timeout]() {
if (auto self = selfWeak.lock()) {
if (!self->connectionOptions_.writeTimeout.count() ||
self->connectionOptions_.writeTimeout > timeout) {
self->connectionOptions_.writeTimeout = timeout;
}
if (self->socket_) {
self->socket_->setSendTimeout(
self->connectionOptions_.writeTimeout.count());
}
}
});
}
示例10: syncToNow
/* Ensure that we're synchronized with the state of the
* filesystem at the current time.
* We do this by touching a cookie file and waiting to
* observe it via inotify. When we see it we know that
* we've seen everything up to the point in time at which
* we're asking questions.
* Returns true if we observe the change within the requested
* time, false otherwise.
* Must be called with the root UNLOCKED. This function
* will acquire and release the root lock.
*/
bool watchman_root::syncToNow(std::chrono::milliseconds timeout) {
w_perf_t sample("sync_to_now");
auto res = cookies.syncToNow(timeout);
// We want to know about all timeouts
if (!res) {
sample.force_log();
}
if (sample.finish()) {
sample.add_root_meta(shared_from_this());
sample.add_meta(
"sync_to_now",
json_object({{"success", json_boolean(res)},
{"timeoutms", json_integer(timeout.count())}}));
sample.log();
}
return res;
}
示例11: lockAndWait
PendingCollection::LockedPtr PendingCollection::lockAndWait(
std::chrono::milliseconds timeoutms,
bool& pinged) {
auto lock = wlock();
if (lock->checkAndResetPinged()) {
pinged = true;
return lock;
}
if (timeoutms.count() == -1) {
cond_.wait(lock.getUniqueLock());
} else {
cond_.wait_for(lock.getUniqueLock(), timeoutms);
}
pinged = lock->checkAndResetPinged();
return lock;
}
示例12: ReportTimedFunction
/// Used to report the time taken by a timed function, called by
/// the TIME_FUNCTION macro
void
ReportTimedFunction(const char* fnName,
const std::chrono::milliseconds duration)
{
switch (mode_)
{
case Mode::None:
break;
case Mode::StdOut:
{
LOG("Function %s, took %s ms", fnName,
std::to_string(duration.count()).c_str());
} break;
case Mode::JSONStdOut:
{
stream_->EnqueueFunctionTimeData(fnName, duration);
}
}
}
示例13: lk
HttpRequest::Impl::Impl(std::chrono::milliseconds timeout_ms, ProgressCallback callback)
: m_callback(callback)
{
{
std::lock_guard<std::mutex> lk(s_curl_was_inited_mutex);
if (!s_curl_was_inited)
{
curl_global_init(CURL_GLOBAL_DEFAULT);
s_curl_was_inited = true;
}
}
m_curl.reset(curl_easy_init());
if (!m_curl)
return;
curl_easy_setopt(m_curl.get(), CURLOPT_NOPROGRESS, m_callback == nullptr);
if (m_callback)
{
curl_easy_setopt(m_curl.get(), CURLOPT_PROGRESSDATA, this);
curl_easy_setopt(m_curl.get(), CURLOPT_PROGRESSFUNCTION, CurlProgressCallback);
}
// libcurl may not have been built with async DNS support, so we disable
// signal handlers to avoid a possible and likely crash if a resolve times out.
curl_easy_setopt(m_curl.get(), CURLOPT_NOSIGNAL, true);
curl_easy_setopt(m_curl.get(), CURLOPT_CONNECTTIMEOUT_MS, static_cast<long>(timeout_ms.count()));
// Sadly CURLOPT_LOW_SPEED_TIME doesn't have a millisecond variant so we have to use seconds
curl_easy_setopt(
m_curl.get(), CURLOPT_LOW_SPEED_TIME,
static_cast<long>(std::chrono::duration_cast<std::chrono::seconds>(timeout_ms).count()));
curl_easy_setopt(m_curl.get(), CURLOPT_LOW_SPEED_LIMIT, 1);
#ifdef _WIN32
// ALPN support is enabled by default but requires Windows >= 8.1.
curl_easy_setopt(m_curl.get(), CURLOPT_SSL_ENABLE_ALPN, false);
#endif
}
示例14: setBusyTimeout
void Database::setBusyTimeout(std::chrono::milliseconds timeout) {
assert(impl);
// std::chrono::milliseconds.count() is a long and Qt will cast
// internally to int, so we need to make sure the limits apply.
std::string timeoutStr = mbgl::util::toString(timeout.count() & INT_MAX);
auto db = QSqlDatabase::database(impl->connectionName);
QString connectOptions = db.connectOptions();
if (connectOptions.isEmpty()) {
if (!connectOptions.isEmpty()) connectOptions.append(';');
connectOptions.append("QSQLITE_BUSY_TIMEOUT=").append(QString::fromStdString(timeoutStr));
}
if (db.isOpen()) {
db.close();
}
db.setConnectOptions(connectOptions);
if (!db.open()) {
// Assume every error when opening the data as CANTOPEN. Qt
// always returns -1 for `nativeErrorCode()` on database errors.
throw Exception { ResultCode::CantOpen, "Error opening the database." };
}
}
示例15: heat
static Float heat(std::chrono::milliseconds t, Float heatCapacity, Float heatGeneration) {
return heatCapacity - std::exp(-t.count() / 1000.0 * heatGeneration);
}