From patchwork Thu Jun 10 07:50:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12535 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A75D4BD78E for ; Thu, 10 Jun 2021 07:50:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5646368938; Thu, 10 Jun 2021 09:50:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="mboGGsJ/"; dkim-atps=neutral Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4FCD36892F for ; Thu, 10 Jun 2021 09:50:38 +0200 (CEST) Received: by mail-pg1-x52f.google.com with SMTP id y12so10083437pgk.6 for ; Thu, 10 Jun 2021 00:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pWxJ4OnA63T98e6zNE9xleVDI6Wpjy17l9FjAPBNIrM=; b=mboGGsJ/NLkz/ZfbnVWWukzzAbsb88fCfwU0/2U+0Uj+VTXJruJC4WljiDDHyVdvLo OOM0c+UbinNyCeK5IyvFbLhtWSczP6YrL+zSWDs8WyeiepfoCqcDtBCQO6jGslxFWP1h fGuCOTLMIa6QpsfEZ0ow9/pR6t2lWD60qrNMc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pWxJ4OnA63T98e6zNE9xleVDI6Wpjy17l9FjAPBNIrM=; b=mg8Z7OwX5KnopH26FtcyYiWkRqazS3owG9s3lfVGnJf/Y6Q3u3jc+jXb4OilDwAlxH em1pSCJaghWUOUIEXZ1iGe0ylswd5QYksCj97u0NjXExv7hInI5pvxsIkIzRBVztCz58 BbkWTiClzsu6YJLvcEQMTh98yQ6M/d883rFCTPp4nn0yWzStJJC9rSDr06kszAm92rnI 5gsLqZ0Gd9NIQPg5fgKd/8ugnzHVONP/KxVv3tkKmip0uQQF7xaO0NqI3fnM92HBNdJz Fu6vV5qU1wN2yei6Y0ceoDxQBMBphgCYvm/KP9iJ0o5VtlZHXJHvk00MyzhQNVJfGPo/ E4+g== X-Gm-Message-State: AOAM533Vy3tJifADXNc12j8lzpAPLPquS2QQj3BtZq2W2yTWyRsFFIIO xcwUOW3UchK6q9/KzEvdQSZFpKk7NMKIRA== X-Google-Smtp-Source: ABdhPJz+IHnvo779Ik9vMJ3M32OPkrG+RoPAaQn+55gsZRWeE3f0j9nGUqVtDFf7GujJ/8VGTQW2GA== X-Received: by 2002:a63:f13:: with SMTP id e19mr3715702pgl.112.1623311436598; Thu, 10 Jun 2021 00:50:36 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:98e0:b356:1c8a:25d4]) by smtp.gmail.com with ESMTPSA id d66sm1565161pfa.32.2021.06.10.00.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 00:50:36 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 10 Jun 2021 16:50:19 +0900 Message-Id: <20210610075027.523672-3-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog In-Reply-To: <20210610075027.523672-1-hiroh@chromium.org> References: <20210610075027.523672-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 02/10] libcamera: EventDispatcherPoll: Manage fd by ScopedFD X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Manages the event file descriptor owned by EventDispatcherPoll by ScopedFD. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- include/libcamera/internal/event_dispatcher_poll.h | 4 +++- src/libcamera/event_dispatcher_poll.cpp | 11 +++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/libcamera/internal/event_dispatcher_poll.h b/include/libcamera/internal/event_dispatcher_poll.h index 33de051d..a309bb7f 100644 --- a/include/libcamera/internal/event_dispatcher_poll.h +++ b/include/libcamera/internal/event_dispatcher_poll.h @@ -11,6 +11,8 @@ #include #include +#include + #include "libcamera/internal/event_dispatcher.h" struct pollfd; @@ -48,7 +50,7 @@ private: std::map notifiers_; std::list timers_; - int eventfd_; + ScopedFD eventfd_; bool processingEvents_; }; diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp index 456c6def..65e46b92 100644 --- a/src/libcamera/event_dispatcher_poll.cpp +++ b/src/libcamera/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_ = ScopedFD(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;