当前位置: 首页>>代码示例>>C++>>正文


C++ chrono::nanoseconds类代码示例

本文整理汇总了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());
}
开发者ID:tekezo,项目名称:Karabiner-Elements,代码行数:7,代码来源:chrono.hpp

示例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;
}
开发者ID:namkazt,项目名称:citra,代码行数:34,代码来源:hle_ipc.cpp

示例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);
}
开发者ID:ubuntu-touch-leo,项目名称:mir,代码行数:11,代码来源:libinput_device.cpp

示例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();
  }
}
开发者ID:cryptobuks,项目名称:forknote,代码行数:31,代码来源:Timer.cpp

示例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();
  }
}
开发者ID:OneEvilCoin,项目名称:OneEvilCoin-v2,代码行数:25,代码来源:Timer.cpp

示例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;
}
开发者ID:chinmaygarde,项目名称:CoreLib,代码行数:26,代码来源:LooperSource_Apple.cpp

示例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;
}
开发者ID:dimitry-ishenko,项目名称:camel,代码行数:13,代码来源:file.cpp

示例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);
}
开发者ID:ubuntu-touch-leo,项目名称:mir,代码行数:23,代码来源:libinput_device.cpp

示例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);
}
开发者ID:kleopatra999,项目名称:vulkan-cpp-library,代码行数:16,代码来源:swapchain.cpp

示例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();
  }
}
开发者ID:conordb,项目名称:bytecoin,代码行数:36,代码来源:Timer.cpp

示例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();
    }
  }
}
开发者ID:blockchain-research-foundation,项目名称:worktipscoin,代码行数:79,代码来源:Timer.cpp

示例12: Duration

 Duration(std::chrono::nanoseconds inNanosconds) : mNanoseconds(inNanosconds.count()) {}
开发者ID:CCJY,项目名称:coliru,代码行数:1,代码来源:main.cpp

示例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);
 }
开发者ID:UnaNancyOwen,项目名称:librealsense,代码行数:10,代码来源:rs_record_playback.hpp

示例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();
  }
}
开发者ID:conordb,项目名称:bytecoin,代码行数:49,代码来源:Timer.cpp

示例15: NanosecondsForFutureWait

autoboost::chrono::nanoseconds NanosecondsForFutureWait(const std::chrono::nanoseconds& time) {
  return autoboost::chrono::nanoseconds(time.count());
}
开发者ID:c-zheng,项目名称:autowiring,代码行数:3,代码来源:CoreJob.cpp


注:本文中的std::chrono::nanoseconds类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。