本文整理汇总了C++中std::chrono::microseconds::count方法的典型用法代码示例。如果您正苦于以下问题:C++ microseconds::count方法的具体用法?C++ microseconds::count怎么用?C++ microseconds::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::chrono::microseconds
的用法示例。
在下文中一共展示了microseconds::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Select
bool TSerialPort::Select(const std::chrono::microseconds& us)
{
fd_set rfds;
struct timeval tv, *tvp = 0;
#if 0
// too verbose
if (Dbg)
std::cerr << "Select on " << Settings.Device << ": " << ms.count() << " us" << std::endl;
#endif
FD_ZERO(&rfds);
FD_SET(Fd, &rfds);
if (us.count() > 0) {
tv.tv_sec = us.count() / 1000000;
tv.tv_usec = us.count();
tvp = &tv;
}
int r = select(Fd + 1, &rfds, NULL, NULL, tvp);
if (r < 0)
throw TSerialDeviceException("select() failed");
return r > 0;
}
示例2: targetTimeForDelay
gint64 GSourceWrap::targetTimeForDelay(std::chrono::microseconds delay)
{
if (!delay.count())
return 0;
gint64 currentTime = g_get_monotonic_time();
gint64 targetTime = currentTime + std::min<gint64>(G_MAXINT64 - currentTime, delay.count());
ASSERT(targetTime >= currentTime);
return targetTime;
}
示例3: Poll
bool SocketImpl::Poll(const std::chrono::microseconds& timeout, int mode)
{
assert(INVALID_SOCKET != m_sockfd);
fd_set fdRead;
fd_set fdWrite;
fd_set fdExcept;
FD_ZERO(&fdRead);
FD_ZERO(&fdWrite);
FD_ZERO(&fdExcept);
if (mode & SELECT_READ)
{
FD_SET(m_sockfd, &fdRead);
}
if (mode & SELECT_WRITE)
{
FD_SET(m_sockfd, &fdWrite);
}
if (mode & SELECT_ERROR)
{
FD_SET(m_sockfd, &fdExcept);
}
struct timeval tv;
tv.tv_sec = (long)std::chrono::duration_cast<std::chrono::seconds>(timeout).count();
tv.tv_usec = (long)(timeout.count() % 1000000);
return select(int(m_sockfd) + 1, &fdRead, &fdWrite, &fdExcept, &tv) > 0;
}
示例4:
void
UnitTestClock<BaseClock>::setNow(const nanoseconds& timeSinceEpoch)
{
BOOST_ASSERT(boost::posix_time::microseconds(SLEEP_AFTER_TIME_CHANGE.count()) >
boost::asio::time_traits<steady_clock>::to_posix_duration(timeSinceEpoch -
m_currentTime));
m_currentTime = timeSinceEpoch;
std::this_thread::sleep_for(SLEEP_AFTER_TIME_CHANGE);
}
示例5: update
void tcapplication::update(std::chrono::microseconds delta)
{
double const count = static_cast<double>(delta.count());
double constexpr timestep = 16000;
g_xrot += 0.3 * count / timestep;
g_yrot += 0.2 * count / timestep;
g_zrot += 0.4 * count / timestep;
}
示例6: cbPing
void cbPing(const vssp::header &header, const std::chrono::microseconds &delayRead)
{
ros::Time now = ros::Time::now() - ros::Duration(delayRead.count() * 0.001 * 0.001);
ros::Duration delay = ((now - timePing)
- ros::Duration(header.send_time_ms * 0.001 - header.received_time_ms * 0.001)) * 0.5;
ros::Time base = timePing + delay - ros::Duration(header.received_time_ms * 0.001);
if(timestampBase == ros::Time(0)) timestampBase = base;
else timestampBase += (base - timestampBase) * 0.01;
}
示例7: SYNCHRONISED
std::chrono::microseconds SYNCHRONISED(
const std::chrono::microseconds data) {
#if defined(SUPPORT_MPI)
unsigned int synchronisedData = static_cast<unsigned int>(data.count());
MPI_Bcast(&synchronisedData, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD);
return std::chrono::microseconds(synchronisedData);
#else
return data;
#endif
}
示例8: update
void Matrix::update(Input *input, std::chrono::microseconds delta)
{
if (getParent()->getComponent<Menu>()->getTime() < 0)
return;
m_timeToGlobalRun -= delta.count()/1000000.0;
if (m_timeToGlobalRun < 0) {
if (solve())
m_timeToGlobalRun = 0.5;
else
m_timeToGlobalRun = FLT_MAX;
}
}
示例9: startTimer
void Watchdog::startTimer(std::chrono::microseconds limit)
{
JSC_GETJAVAENV_CHKRET(env);
static jmethodID mid = env->GetMethodID(
GetWatchdogTimerClass(env),
"fwkStart",
"(D)V");
ASSERT(mid);
env->CallVoidMethod(m_timer, mid, (jdouble) (limit.count() / (1000.0 * 1000.0)));
CheckAndClearException(env);
}
示例10: main
int main()
{
{
std::chrono::milliseconds ms(1);
std::chrono::microseconds us = ms;
assert(us.count() == 1000);
}
#if TEST_STD_VER >= 11
{
constexpr std::chrono::milliseconds ms(1);
constexpr std::chrono::microseconds us = ms;
static_assert(us.count() == 1000, "");
}
#endif
}
示例11: oneshot
void APIC_Timer::oneshot(std::chrono::microseconds micros) noexcept
{
// prevent overflow
uint64_t ticks = micros.count() * ticks_per_micro;
if (ticks > 0xFFFFFFFF) ticks = 0xFFFFFFFF;
// set initial counter
auto& lapic = APIC::get();
lapic.timer_begin(ticks);
// re-enable interrupts if disabled
if (GET_TIMER().intr_enabled == false) {
GET_TIMER().intr_enabled = true;
lapic.timer_interrupt(true);
}
}
示例12: scheduleAfterDelay
void GMainLoopSource::scheduleAfterDelay(const char* name, std::function<bool ()> function, std::chrono::microseconds delay, int priority, std::function<void ()> destroyFunction, GMainContext* context)
{
cancel();
ASSERT(!m_context.source);
m_context = {
adoptGRef(createMicrosecondsTimeoutSource(delay.count())),
nullptr, // cancellable
nullptr, // socketCancellable
nullptr, // voidCallback
WTF::move(function),
nullptr, // socketCallback
WTF::move(destroyFunction)
};
scheduleTimeoutSource(name, reinterpret_cast<GSourceFunc>(boolSourceCallback), priority, context);
}
示例13: ReadWithTimeout
Status PipeWindows::ReadWithTimeout(void *buf, size_t size,
const std::chrono::microseconds &duration,
size_t &bytes_read) {
if (!CanRead())
return Status(ERROR_INVALID_HANDLE, eErrorTypeWin32);
bytes_read = 0;
DWORD sys_bytes_read = size;
BOOL result = ::ReadFile(m_read, buf, sys_bytes_read, &sys_bytes_read,
&m_read_overlapped);
if (!result && GetLastError() != ERROR_IO_PENDING)
return Status(::GetLastError(), eErrorTypeWin32);
DWORD timeout = (duration == std::chrono::microseconds::zero())
? INFINITE
: duration.count() * 1000;
DWORD wait_result = ::WaitForSingleObject(m_read_overlapped.hEvent, timeout);
if (wait_result != WAIT_OBJECT_0) {
// The operation probably failed. However, if it timed out, we need to
// cancel the I/O.
// Between the time we returned from WaitForSingleObject and the time we
// call CancelIoEx,
// the operation may complete. If that hapens, CancelIoEx will fail and
// return ERROR_NOT_FOUND.
// If that happens, the original operation should be considered to have been
// successful.
bool failed = true;
DWORD failure_error = ::GetLastError();
if (wait_result == WAIT_TIMEOUT) {
BOOL cancel_result = CancelIoEx(m_read, &m_read_overlapped);
if (!cancel_result && GetLastError() == ERROR_NOT_FOUND)
failed = false;
}
if (failed)
return Status(failure_error, eErrorTypeWin32);
}
// Now we call GetOverlappedResult setting bWait to false, since we've already
// waited
// as long as we're willing to.
if (!GetOverlappedResult(m_read, &m_read_overlapped, &sys_bytes_read, FALSE))
return Status(::GetLastError(), eErrorTypeWin32);
bytes_read = sys_bytes_read;
return Status();
}
示例14: socket_send
ssize_t socket_send(int sock, uint8_t *buf, size_t len)
{
ssize_t ret = super::socket_send(sock, buf, len);
m_bytes += ret - super::header_len();
if (m_start == timestamp())
m_start = timer::now();
m_end = timer::now();
if (!m_interval.count())
return ret;
wait();
m_timestamp_last = timer::now();
return ret;
}
示例15: finishSuite
void TextOutput::finishSuite(const std::string& suiteName, const unsigned int numTests, const unsigned int numPositiveTests, const std::chrono::microseconds totalDuration)
{
if(mode <= Verbose || numTests != numPositiveTests)
stream << "Suite '" << suiteName << "' finished, " << numPositiveTests << '/' << numTests << " successful (" << prettifyPercentage(numPositiveTests, numTests) << "%) in " << totalDuration.count() << " microseconds (" << totalDuration.count()/1000.0 << " ms)." << std::endl;
}