Message ID | 20211128235752.10836-9-laurent.pinchart@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Laurent, On Mon, Nov 29, 2021 at 01:57:43AM +0200, Laurent Pinchart wrote: > From: Hirokazu Honda <hiroh@chromium.org> > > Manages the event file descriptor owned by EventDispatcherPoll > by UniqueFD. > > Signed-off-by: Hirokazu Honda <hiroh@chromium.org> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Thanks j > --- > include/libcamera/base/event_dispatcher_poll.h | 3 ++- > src/libcamera/base/event_dispatcher_poll.cpp | 11 +++++------ > 2 files changed, 7 insertions(+), 7 deletions(-) > > diff --git a/include/libcamera/base/event_dispatcher_poll.h b/include/libcamera/base/event_dispatcher_poll.h > index 3d2fc7bbc4c3..b7840309bb25 100644 > --- a/include/libcamera/base/event_dispatcher_poll.h > +++ b/include/libcamera/base/event_dispatcher_poll.h > @@ -14,6 +14,7 @@ > #include <libcamera/base/private.h> > > #include <libcamera/base/event_dispatcher.h> > +#include <libcamera/base/unique_fd.h> > > struct pollfd; > > @@ -50,7 +51,7 @@ private: > > std::map<int, EventNotifierSetPoll> notifiers_; > std::list<Timer *> timers_; > - int eventfd_; > + UniqueFD eventfd_; > > bool processingEvents_; > }; > diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp > index 3c9a126c0bd6..8ee22d5adcc4 100644 > --- a/src/libcamera/base/event_dispatcher_poll.cpp > +++ b/src/libcamera/base/event_dispatcher_poll.cpp > @@ -54,14 +54,13 @@ EventDispatcherPoll::EventDispatcherPoll() > * Create the event fd. Failures are fatal as we can't implement an > * interruptible dispatcher without the fd. > */ > - eventfd_ = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); > - if (eventfd_ < 0) > + eventfd_ = UniqueFD(eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)); > + if (!eventfd_.isValid()) > LOG(Event, Fatal) << "Unable to create eventfd"; > } > > EventDispatcherPoll::~EventDispatcherPoll() > { > - close(eventfd_); > } > > void EventDispatcherPoll::registerEventNotifier(EventNotifier *notifier) > @@ -154,7 +153,7 @@ void EventDispatcherPoll::processEvents() > for (auto notifier : notifiers_) > pollfds.push_back({ notifier.first, notifier.second.events(), 0 }); > > - pollfds.push_back({ eventfd_, POLLIN, 0 }); > + pollfds.push_back({ eventfd_.get(), POLLIN, 0 }); > > /* Wait for events and process notifiers and timers. */ > do { > @@ -176,7 +175,7 @@ void EventDispatcherPoll::processEvents() > void EventDispatcherPoll::interrupt() > { > uint64_t value = 1; > - ssize_t ret = write(eventfd_, &value, sizeof(value)); > + ssize_t ret = write(eventfd_.get(), &value, sizeof(value)); > if (ret != sizeof(value)) { > if (ret < 0) > ret = -errno; > @@ -230,7 +229,7 @@ void EventDispatcherPoll::processInterrupt(const struct pollfd &pfd) > return; > > uint64_t value; > - ssize_t ret = read(eventfd_, &value, sizeof(value)); > + ssize_t ret = read(eventfd_.get(), &value, sizeof(value)); > if (ret != sizeof(value)) { > if (ret < 0) > ret = -errno; > -- > Regards, > > Laurent Pinchart >
diff --git a/include/libcamera/base/event_dispatcher_poll.h b/include/libcamera/base/event_dispatcher_poll.h index 3d2fc7bbc4c3..b7840309bb25 100644 --- a/include/libcamera/base/event_dispatcher_poll.h +++ b/include/libcamera/base/event_dispatcher_poll.h @@ -14,6 +14,7 @@ #include <libcamera/base/private.h> #include <libcamera/base/event_dispatcher.h> +#include <libcamera/base/unique_fd.h> struct pollfd; @@ -50,7 +51,7 @@ private: std::map<int, EventNotifierSetPoll> notifiers_; std::list<Timer *> timers_; - int eventfd_; + UniqueFD eventfd_; bool processingEvents_; }; diff --git a/src/libcamera/base/event_dispatcher_poll.cpp b/src/libcamera/base/event_dispatcher_poll.cpp index 3c9a126c0bd6..8ee22d5adcc4 100644 --- a/src/libcamera/base/event_dispatcher_poll.cpp +++ b/src/libcamera/base/event_dispatcher_poll.cpp @@ -54,14 +54,13 @@ EventDispatcherPoll::EventDispatcherPoll() * Create the event fd. Failures are fatal as we can't implement an * interruptible dispatcher without the fd. */ - eventfd_ = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); - if (eventfd_ < 0) + eventfd_ = UniqueFD(eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)); + if (!eventfd_.isValid()) LOG(Event, Fatal) << "Unable to create eventfd"; } EventDispatcherPoll::~EventDispatcherPoll() { - close(eventfd_); } void EventDispatcherPoll::registerEventNotifier(EventNotifier *notifier) @@ -154,7 +153,7 @@ void EventDispatcherPoll::processEvents() for (auto notifier : notifiers_) pollfds.push_back({ notifier.first, notifier.second.events(), 0 }); - pollfds.push_back({ eventfd_, POLLIN, 0 }); + pollfds.push_back({ eventfd_.get(), POLLIN, 0 }); /* Wait for events and process notifiers and timers. */ do { @@ -176,7 +175,7 @@ void EventDispatcherPoll::processEvents() void EventDispatcherPoll::interrupt() { uint64_t value = 1; - ssize_t ret = write(eventfd_, &value, sizeof(value)); + ssize_t ret = write(eventfd_.get(), &value, sizeof(value)); if (ret != sizeof(value)) { if (ret < 0) ret = -errno; @@ -230,7 +229,7 @@ void EventDispatcherPoll::processInterrupt(const struct pollfd &pfd) return; uint64_t value; - ssize_t ret = read(eventfd_, &value, sizeof(value)); + ssize_t ret = read(eventfd_.get(), &value, sizeof(value)); if (ret != sizeof(value)) { if (ret < 0) ret = -errno;