本文整理汇总了C++中std::chrono::nanoseconds类的典型用法代码示例。如果您正苦于以下问题:C++ nanoseconds类的具体用法?C++ nanoseconds怎么用?C++ nanoseconds使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了nanoseconds类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_absolute_time_duration
inline absolute_time_duration make_absolute_time_duration(std::chrono::nanoseconds time) {
auto& t = impl::get_mach_timebase_info_data();
if (t.numer != t.denom && t.numer != 0) {
return absolute_time_duration(time.count() * t.denom / t.numer);
}
return absolute_time_duration(time.count());
}
示例2: ASSERT
SharedPtr<Event> HLERequestContext::SleepClientThread(SharedPtr<Thread> thread,
const std::string& reason,
std::chrono::nanoseconds timeout,
WakeupCallback&& callback) {
// Put the client thread to sleep until the wait event is signaled or the timeout expires.
thread->wakeup_callback = [context = *this, callback](ThreadWakeupReason reason,
SharedPtr<Thread> thread,
SharedPtr<WaitObject> object) mutable {
ASSERT(thread->status == THREADSTATUS_WAIT_HLE_EVENT);
callback(thread, context, reason);
auto& process = thread->owner_process;
// We must copy the entire command buffer *plus* the entire static buffers area, since
// the translation might need to read from it in order to retrieve the StaticBuffer
// target addresses.
std::array<u32_le, IPC::COMMAND_BUFFER_LENGTH + 2 * IPC::MAX_STATIC_BUFFERS> cmd_buff;
Memory::ReadBlock(*process, thread->GetCommandBufferAddress(), cmd_buff.data(),
cmd_buff.size() * sizeof(u32));
context.WriteToOutgoingCommandBuffer(cmd_buff.data(), *process, Kernel::g_handle_table);
// Copy the translated command buffer back into the thread's command buffer area.
Memory::WriteBlock(*process, thread->GetCommandBufferAddress(), cmd_buff.data(),
cmd_buff.size() * sizeof(u32));
};
auto event = Kernel::Event::Create(Kernel::ResetType::OneShot, "HLE Pause Event: " + reason);
thread->status = THREADSTATUS_WAIT_HLE_EVENT;
thread->wait_objects = {event};
event->AddWaitingThread(thread);
if (timeout.count() > 0)
thread->WakeAfterDelay(timeout.count());
return event;
}
示例3:
mir::EventUPtr mie::LibInputDevice::convert_event(libinput_event_keyboard* keyboard)
{
std::chrono::nanoseconds const time = std::chrono::microseconds(libinput_event_keyboard_get_time_usec(keyboard));
auto const action = libinput_event_keyboard_get_key_state(keyboard) == LIBINPUT_KEY_STATE_PRESSED ?
mir_keyboard_action_down :
mir_keyboard_action_up;
auto const code = libinput_event_keyboard_get_key(keyboard);
report->received_event_from_kernel(time.count(), EV_KEY, code, action);
return builder->key_event(time, action, xkb_keysym_t{0}, code);
}
示例4: sleep
void Timer::sleep(std::chrono::nanoseconds duration) {
assert(dispatcher != nullptr);
assert(context == nullptr);
if (stopped) {
throw InterruptedException();
}
Dispatcher::OperationContext timerContext;
timerContext.context = dispatcher->getCurrentContext();
timerContext.interrupted = false;
timer = dispatcher->getTimer();
struct kevent event;
EV_SET(&event, timer, EVFILT_TIMER, EV_ADD | EV_ENABLE | EV_ONESHOT, 0, duration.count() / 1000000, &timerContext);
if (kevent(dispatcher->getKqueue(), &event, 1, NULL, 0, NULL) == -1) {
throw std::runtime_error("Timer::stop, kevent() failed, errno=" + std::to_string(errno));
}
context = &timerContext;
dispatcher->dispatch();
assert(dispatcher != nullptr);
assert(timerContext.context == dispatcher->getCurrentContext());
assert(context == &timerContext);
context = nullptr;
timerContext.context = nullptr;
dispatcher->pushTimer(timer);
if (timerContext.interrupted) {
throw InterruptedException();
}
}
示例5: sleep
void Timer::sleep(std::chrono::nanoseconds duration) {
assert(dispatcher != nullptr);
assert(context == nullptr);
if (stopped) {
throw InterruptedException();
}
LARGE_INTEGER duration2;
duration2.QuadPart = static_cast<LONGLONG>(duration.count() / -100);
Context context2 = {dispatcher, GetCurrentFiber(), false};
if (SetWaitableTimer(timer, &duration2, 0, callbackProcedure, &context2, FALSE) != TRUE) {
std::cerr << "SetWaitableTimer failed, result=" << GetLastError() << '.' << std::endl;
throw std::runtime_error("Timer::sleep");
}
context = &context2;
dispatcher->yield();
assert(dispatcher != nullptr);
assert(context2.context == nullptr);
assert(context == &context2);
context = nullptr;
if (context2.interrupted) {
throw InterruptedException();
}
}
示例6:
std::shared_ptr<LooperSource>
LooperSource::AsTimer(std::chrono::nanoseconds repeatInterval) {
WaitSetUpdateHandler updateHandler =
[repeatInterval](LooperSource *source, WaitSet::Handle waitsetHandle,
Handle readHandle, bool adding) {
LooperSource_UpdateKeventSource(waitsetHandle,
readHandle,
EVFILT_TIMER,
adding ? EV_ADD : EV_DELETE,
NOTE_NSECONDS,
repeatInterval.count(),
source);
};
auto timer = std::make_shared<LooperSource>(nullptr,
nullptr,
nullptr,
nullptr);
timer->setCustomWaitSetUpdateHandler(updateHandler);
return timer;
}
示例7: can_write
bool file::can_write(std::chrono::seconds s, std::chrono::nanoseconds n)
{
timespec time = { static_cast<std::time_t>(s.count()), static_cast<long>(n.count()) };
fd_set fds;
FD_ZERO(&fds);
FD_SET(_M_fd, &fds);
int count = pselect(_M_fd+1, 0, &fds, 0, &time, nullptr);
if(count == -1) throw errno_error();
return count;
}
示例8: MirPointerButton
mir::EventUPtr mie::LibInputDevice::convert_button_event(libinput_event_pointer* pointer)
{
std::chrono::nanoseconds const time = std::chrono::microseconds(libinput_event_pointer_get_time_usec(pointer));
auto const button = libinput_event_pointer_get_button(pointer);
auto const action = (libinput_event_pointer_get_button_state(pointer) == LIBINPUT_BUTTON_STATE_PRESSED)?
mir_pointer_action_button_down : mir_pointer_action_button_up;
auto const do_not_swap_buttons = mir_pointer_handedness_right;
auto const pointer_button = mie::to_pointer_button(button, do_not_swap_buttons);
auto const relative_x_value = 0.0f;
auto const relative_y_value = 0.0f;
auto const hscroll_value = 0.0f;
auto const vscroll_value = 0.0f;
report->received_event_from_kernel(time.count(), EV_KEY, pointer_button, action);
if (action == mir_pointer_action_button_down)
button_state = MirPointerButton(button_state | uint32_t(pointer_button));
else
button_state = MirPointerButton(button_state & ~uint32_t(pointer_button));
return builder->pointer_event(time, action, button_state, hscroll_value, vscroll_value, relative_x_value, relative_y_value);
}
示例9: acquire_next_image
std::tuple<VkResult, uint32_t> acquire_next_image(swapchain_type &swapchain,
std::chrono::nanoseconds timeout,
const semaphore::semaphore_type &semaphore,
const fence::fence_type &fence) {
uint32_t image_index;
std::lock(internal::get_mutex(swapchain), internal::get_mutex(semaphore));
std::lock_guard<std::mutex> swapchain_lock(internal::get_mutex(swapchain), std::adopt_lock);
std::lock_guard<std::mutex> semaphore_lock(internal::get_mutex(semaphore), std::adopt_lock);
std::lock_guard<std::mutex> fence_lock(internal::get_mutex(fence), std::adopt_lock);
const VkResult result(vkAcquireNextImageKHR(
internal::get_instance(*internal::get_parent(swapchain)),
internal::get_instance(swapchain), timeout.count(),
internal::get_instance(semaphore), internal::get_instance(fence),
&image_index));
return std::make_tuple(result, image_index);
}
示例10: sleep
void Timer::sleep(std::chrono::nanoseconds duration) {
assert(dispatcher != nullptr);
assert(context == nullptr);
if (dispatcher->interrupted()) {
throw InterruptedException();
}
LARGE_INTEGER frequency;
LARGE_INTEGER ticks;
QueryPerformanceCounter(&ticks);
QueryPerformanceFrequency(&frequency);
uint64_t currentTime = ticks.QuadPart / (frequency.QuadPart / 1000);
uint64_t time = currentTime + duration.count() / 1000000;
TimerContext timerContext{ time, dispatcher->getCurrentContext(), false };
context = &timerContext;
dispatcher->addTimer(time, dispatcher->getCurrentContext());
dispatcher->getCurrentContext()->interruptProcedure = [&]() {
assert(dispatcher != nullptr);
assert(context != nullptr);
TimerContext* timerContext = static_cast<TimerContext*>(context);
if (!timerContext->interrupted) {
dispatcher->interruptTimer(timerContext->time, timerContext->context);
timerContext->interrupted = true;
}
};
dispatcher->dispatch();
dispatcher->getCurrentContext()->interruptProcedure = nullptr;
assert(timerContext.context == dispatcher->getCurrentContext());
assert(dispatcher != nullptr);
assert(context == &timerContext);
context = nullptr;
if (timerContext.interrupted) {
throw InterruptedException();
}
}
示例11: assert
void Timer::sleep(std::chrono::nanoseconds duration) {
assert(dispatcher != nullptr);
assert(context == nullptr);
if (dispatcher->interrupted()) {
throw InterruptedException();
}
if(duration.count() == 0 ) {
dispatcher->yield();
} else {
timer = dispatcher->getTimer();
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration);
itimerspec expires;
expires.it_interval.tv_nsec = expires.it_interval.tv_sec = 0;
expires.it_value.tv_sec = seconds.count();
expires.it_value.tv_nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(duration - seconds).count();
timerfd_settime(timer, 0, &expires, NULL);
ContextPair contextPair;
OperationContext timerContext;
timerContext.interrupted = false;
timerContext.context = dispatcher->getCurrentContext();
contextPair.writeContext = nullptr;
contextPair.readContext = &timerContext;
epoll_event timerEvent;
timerEvent.events = EPOLLIN | EPOLLONESHOT;
timerEvent.data.ptr = &contextPair;
if (epoll_ctl(dispatcher->getEpoll(), EPOLL_CTL_MOD, timer, &timerEvent) == -1) {
throw std::runtime_error("Timer::sleep, epoll_ctl failed, " + lastErrorMessage());
}
dispatcher->getCurrentContext()->interruptProcedure = [&]() {
assert(dispatcher != nullptr);
assert(context != nullptr);
OperationContext* timerContext = static_cast<OperationContext*>(context);
if (!timerContext->interrupted) {
uint64_t value = 0;
if(::read(timer, &value, sizeof value) == -1 ){
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wlogical-op"
if(errno == EAGAIN || errno == EWOULDBLOCK) {
#pragma GCC diagnostic pop
timerContext->interrupted = true;
dispatcher->pushContext(timerContext->context);
} else {
throw std::runtime_error("Timer::sleep, interrupt procedure, read failed, " + lastErrorMessage());
}
} else {
assert(value>0);
dispatcher->pushContext(timerContext->context);
}
epoll_event timerEvent;
timerEvent.events = EPOLLONESHOT;
timerEvent.data.ptr = nullptr;
if (epoll_ctl(dispatcher->getEpoll(), EPOLL_CTL_MOD, timer, &timerEvent) == -1) {
throw std::runtime_error("Timer::sleep, interrupt procedure, epoll_ctl failed, " + lastErrorMessage());
}
}
};
context = &timerContext;
dispatcher->dispatch();
dispatcher->getCurrentContext()->interruptProcedure = nullptr;
assert(dispatcher != nullptr);
assert(timerContext.context == dispatcher->getCurrentContext());
assert(contextPair.writeContext == nullptr);
assert(context == &timerContext);
context = nullptr;
timerContext.context = nullptr;
dispatcher->pushTimer(timer);
if (timerContext.interrupted) {
throw InterruptedException();
}
}
}
示例12: Duration
Duration(std::chrono::nanoseconds inNanosconds) : mNanoseconds(inNanosconds.count()) {}
示例13: seek
/**
* Sets the playback to a specified time point of the played data
* \param[in] time The time point to which playback should seek, expressed in units of nanoseconds (zero value = start)
*/
void seek(std::chrono::nanoseconds time)
{
rs2_error* e = nullptr;
rs2_playback_seek(_dev.get(), time.count(), &e);
error::handle(e);
}
示例14: sleep
void Timer::sleep(std::chrono::nanoseconds duration) {
assert(dispatcher != nullptr);
assert(context == nullptr);
if (dispatcher->interrupted()) {
throw InterruptedException();
}
OperationContext timerContext;
timerContext.context = dispatcher->getCurrentContext();
timerContext.interrupted = false;
timer = dispatcher->getTimer();
struct kevent event;
EV_SET(&event, timer, EVFILT_TIMER, EV_ADD | EV_ENABLE | EV_ONESHOT, NOTE_NSECONDS, duration.count(), &timerContext);
if (kevent(dispatcher->getKqueue(), &event, 1, NULL, 0, NULL) == -1) {
throw std::runtime_error("Timer::stop, kevent failed, " + lastErrorMessage());
}
context = &timerContext;
dispatcher->getCurrentContext()->interruptProcedure = [&] {
assert(dispatcher != nullptr);
assert(context != nullptr);
OperationContext* timerContext = static_cast<OperationContext*>(context);
if (!timerContext->interrupted) {
struct kevent event;
EV_SET(&event, timer, EVFILT_TIMER, EV_DELETE, 0, 0, NULL);
if (kevent(dispatcher->getKqueue(), &event, 1, NULL, 0, NULL) == -1) {
throw std::runtime_error("Timer::stop, kevent failed, " + lastErrorMessage());
}
dispatcher->pushContext(timerContext->context);
timerContext->interrupted = true;
}
};
dispatcher->dispatch();
dispatcher->getCurrentContext()->interruptProcedure = nullptr;
assert(dispatcher != nullptr);
assert(timerContext.context == dispatcher->getCurrentContext());
assert(context == &timerContext);
context = nullptr;
timerContext.context = nullptr;
dispatcher->pushTimer(timer);
if (timerContext.interrupted) {
throw InterruptedException();
}
}
示例15: NanosecondsForFutureWait
autoboost::chrono::nanoseconds NanosecondsForFutureWait(const std::chrono::nanoseconds& time) {
return autoboost::chrono::nanoseconds(time.count());
}