summaryrefslogtreecommitdiff
path: root/src/libcamera/event_dispatcher_poll.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-23 10:00:35 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-23 18:51:56 +0200
commitd370c1b46e1733905fd76eec004be26475afae9d (patch)
tree90415bb821ad84ea1839ceade3cec3ad5af706d0 /src/libcamera/event_dispatcher_poll.cpp
parent83c73c39c5c6b115fc80e6133433b70753499bab (diff)
libcamera: event_dispatcher_poll: Handle interrupted ppoll() calls
The ppoll() call can be interrupted if a signal is delivered. Handle the EINTR error code gracefully by restarting the call. This fixes the event-dispatcher test failure. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@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.cpp58
1 files changed, 33 insertions, 25 deletions
diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp
index eefac54c..6e0609c3 100644
--- a/src/libcamera/event_dispatcher_poll.cpp
+++ b/src/libcamera/event_dispatcher_poll.cpp
@@ -128,32 +128,11 @@ void EventDispatcherPoll::processEvents()
for (auto notifier : notifiers_)
pollfds.push_back({ notifier.first, notifier.second.events(), 0 });
- /* Compute the timeout. */
- Timer *nextTimer = !timers_.empty() ? timers_.front() : nullptr;
- 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;
- }
-
- LOG(Event, Debug)
- << "timeout " << timeout.tv_sec << "."
- << std::setfill('0') << std::setw(9)
- << timeout.tv_nsec;
- }
-
/* Wait for events and process notifiers and timers. */
- ret = ppoll(pollfds.data(), pollfds.size(),
- nextTimer ? &timeout : nullptr, nullptr);
+ do {
+ ret = poll(&pollfds);
+ } while (ret == -1 && errno == EINTR);
+
if (ret < 0) {
ret = -errno;
LOG(Event, Warning) << "poll() failed with " << strerror(-ret);
@@ -178,6 +157,35 @@ short EventDispatcherPoll::EventNotifierSetPoll::events() const
return events;
}
+int EventDispatcherPoll::poll(std::vector<struct pollfd> *pollfds)
+{
+ /* Compute the timeout. */
+ Timer *nextTimer = !timers_.empty() ? timers_.front() : nullptr;
+ 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;
+ }
+
+ LOG(Event, Debug)
+ << "timeout " << timeout.tv_sec << "."
+ << std::setfill('0') << std::setw(9)
+ << timeout.tv_nsec;
+ }
+
+ return ppoll(pollfds->data(), pollfds->size(),
+ nextTimer ? &timeout : nullptr, nullptr);
+}
+
void EventDispatcherPoll::processNotifiers(const std::vector<struct pollfd> &pollfds)
{
static const struct {