From patchwork Wed Jan 23 08:59:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 346 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6633060C98 for ; Wed, 23 Jan 2019 09:59:29 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E15C023D for ; Wed, 23 Jan 2019 09:59:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1548233969; bh=agpvYX4U9f4P8YjrOd42wLo6vxSKRnt8qWskjDqQIPs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=L+thkplDUnyoK1jHB61ETTBimwQGGWQ72Dyw1gwVLfoP5hYrnc3uMqOW5+iZlS84k ZHGBywjCs4MdrK9hEFz4nhhFYLH0EZnHiwnTmFVmdexBtlIy7IWyjGiz0ts73Lk2Ig 5Kvi9XmCbh9tA8m9wQYyVsatTKseIzQKc2JUmp9c= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Jan 2019 10:59:21 +0200 Message-Id: <20190123085923.12524-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190123085923.12524-1-laurent.pinchart@ideasonboard.com> References: <20190123085923.12524-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] libcamera: event_dispatcher_poll: Handle interrupted ppoll() calls X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jan 2019 08:59:29 -0000 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 Reviewed-by: Kieran Bingham --- src/libcamera/event_dispatcher_poll.cpp | 58 +++++++++++-------- src/libcamera/include/event_dispatcher_poll.h | 1 + 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp index eefac54ca6da..6e0609c34ddc 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 *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 &pollfds) { static const struct { diff --git a/src/libcamera/include/event_dispatcher_poll.h b/src/libcamera/include/event_dispatcher_poll.h index a41926e11a11..ac3efde082b4 100644 --- a/src/libcamera/include/event_dispatcher_poll.h +++ b/src/libcamera/include/event_dispatcher_poll.h @@ -41,6 +41,7 @@ private: std::map notifiers_; std::list timers_; + int poll(std::vector *pollfds); void processNotifiers(const std::vector &pollfds); void processTimers(); };