From patchwork Fri Jun 5 09:01:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 3939 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8591E61027 for ; Fri, 5 Jun 2020 11:01:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XZ7280gF"; dkim-atps=neutral Received: from emerald.amanokami.net (fs76eef344.knge213.ap.nuro.jp [118.238.243.68]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 57D6B27C; Fri, 5 Jun 2020 11:01:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1591347682; bh=QB20CXQv4BOODnqeSakNDMIm1j3itxDVfiqH16KTQ/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZ7280gFjPQF05Rh1AnVS28JHClLRD5mYIAFZB53Y6xfhLkH9mqjG12GfoId/ttCZ mwpxgN4AnW0FSbUhByLZt3BrHD+OrZ1QsjvsAfD1HNdR/q1jrYoZsPcax5AvLkZRMz Y0iu31m51U8zVExOxLMLsxuZI0tZ7rvifD5aS/AY= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Jun 2020 18:01:03 +0900 Message-Id: <20200605090106.15424-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200605090106.15424-1-paul.elder@ideasonboard.com> References: <20200605090106.15424-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/7] v4l2: v4l2_camera_proxy: Acquire only one buffer semaphore on VIDIOC_DQBUF 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: , X-List-Received-Date: Fri, 05 Jun 2020 09:01:22 -0000 We use a semaphore to atomically keep track of how many buffers are available for dequeueing. The check for how to acquire the semaphore was incorrect, leading to a double acquire upon a successful nonblocking acquire. Fix this. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- Changes in v2: restructured the if block so it's easier to read --- src/v4l2/v4l2_camera_proxy.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index ec6d265d..a0c6deea 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -426,10 +426,10 @@ int V4L2CameraProxy::vidioc_dqbuf(struct v4l2_buffer *arg) !validateMemoryType(arg->memory)) return -EINVAL; - if (nonBlocking_ && !vcam_->bufferSema_.tryAcquire()) - return -EAGAIN; - else + if (!nonBlocking_) vcam_->bufferSema_.acquire(); + else if (!vcam_->bufferSema_.tryAcquire()) + return -EAGAIN; updateBuffers();