summaryrefslogtreecommitdiff
path: root/src/libcamera/event_dispatcher_poll.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-09-14 03:40:47 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-09-14 15:05:45 +0300
commitcecfeed61e8bcb4b53c2ed8e1b26d8c8af38b8e3 (patch)
tree783fca9b32651efdca054ad152528b40f2566a74 /src/libcamera/event_dispatcher_poll.cpp
parent98dff063f2f497434978a46f9a676307365fd878 (diff)
libcamera: Switch to the std::chrono API
Replace the clock_gettime()-based API with durations expressed as integers with the std::chrono API. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/event_dispatcher_poll.cpp')
-rw-r--r--src/libcamera/event_dispatcher_poll.cpp24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp
index 281f37bd..51ac5adf 100644
--- a/src/libcamera/event_dispatcher_poll.cpp
+++ b/src/libcamera/event_dispatcher_poll.cpp
@@ -8,6 +8,7 @@
#include "event_dispatcher_poll.h"
#include <algorithm>
+#include <chrono>
#include <iomanip>
#include <poll.h>
#include <stdint.h>
@@ -20,6 +21,7 @@
#include "log.h"
#include "thread.h"
+#include "utils.h"
/**
* \file event_dispatcher_poll.h
@@ -206,17 +208,12 @@ int EventDispatcherPoll::poll(std::vector<struct pollfd> *pollfds)
struct timespec timeout;
if (nextTimer) {
- clock_gettime(CLOCK_MONOTONIC, &timeout);
- uint64_t now = timeout.tv_sec * 1000000000ULL + timeout.tv_nsec;
-
- if (nextTimer->deadline() > now) {
- uint64_t delta = nextTimer->deadline() - now;
- timeout.tv_sec = delta / 1000000000ULL;
- timeout.tv_nsec = delta % 1000000000ULL;
- } else {
- timeout.tv_sec = 0;
- timeout.tv_nsec = 0;
- }
+ utils::time_point now = utils::clock::now();
+
+ if (nextTimer->deadline() > now)
+ timeout = utils::duration_to_timespec(nextTimer->deadline() - now);
+ else
+ timeout = { 0, 0 };
LOG(Event, Debug)
<< "timeout " << timeout.tv_sec << "."
@@ -295,10 +292,7 @@ void EventDispatcherPoll::processNotifiers(const std::vector<struct pollfd> &pol
void EventDispatcherPoll::processTimers()
{
- struct timespec ts;
- uint64_t now;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- now = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
+ utils::time_point now = utils::clock::now();
while (!timers_.empty()) {
Timer *timer = timers_.front();