Patch Detail
Show a patch.
GET /api/patches/8420/?format=api
{ "id": 8420, "url": "https://patchwork.libcamera.org/api/patches/8420/?format=api", "web_url": "https://patchwork.libcamera.org/patch/8420/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200624145256.48266-23-paul.elder@ideasonboard.com>", "date": "2020-06-24T14:52:56", "name": "[libcamera-devel,v4,22/22] v4l2: v4l2_camera_proxy: Serialize accesses to the proxy", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "78a1e791e03500e192fe89bd273617397a491825", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/8420/mbox/", "series": [ { "id": 1041, "url": "https://patchwork.libcamera.org/api/series/1041/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1041", "date": "2020-06-24T14:52:34", "name": "Support v4l2-compliance", "version": 4, "mbox": "https://patchwork.libcamera.org/series/1041/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/8420/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/8420/checks/", "tags": {}, "headers": { "Return-Path": "<paul.elder@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B6BB5609A5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Jun 2020 16:54:07 +0200 (CEST)", "from jade.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:8147:f2a2:a8c6:9087])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id ECB462A8;\n\tWed, 24 Jun 2020 16:54:05 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"VGDtdiN+\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593010447;\n\tbh=4PjURdrMQaH5PwCLBd19kqpMlFRZU1ZDQ80XITlobP4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=VGDtdiN+dJu93JXDXMoow3g6aPatWPFD/TdCrwDIP8QyspG7WcsBWaE4WWe+CbecB\n\tERUXeY+lef6/gNxrzLX6nhe/dw+7b6LvOfoeS03QkXu+25WV9szvzTa74LdkCjqo/e\n\t+/4jEV5gnBjDJgBxyf3YHROgv8T1mUNVpo5Se2i8=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 24 Jun 2020 23:52:56 +0900", "Message-Id": "<20200624145256.48266-23-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.27.0", "In-Reply-To": "<20200624145256.48266-1-paul.elder@ideasonboard.com>", "References": "<20200624145256.48266-1-paul.elder@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 22/22] v4l2: v4l2_camera_proxy:\n\tSerialize accesses to the proxy", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "X-List-Received-Date": "Wed, 24 Jun 2020 14:54:08 -0000" }, "content": "Make the V4L2 compatibility layer thread-safe by serializing accesses to\nthe V4L2CameraProxy with a lock. Release the lock when blocking for\ndqbuf.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v4:\n- cosmetic changes\n\nNew in v3\n---\n src/v4l2/v4l2_camera_proxy.cpp | 21 +++++++++++++++++----\n src/v4l2/v4l2_camera_proxy.h | 5 ++++-\n 2 files changed, 21 insertions(+), 5 deletions(-)", "diff": "diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\nindex 3b7a6f4..6896e55 100644\n--- a/src/v4l2/v4l2_camera_proxy.cpp\n+++ b/src/v4l2/v4l2_camera_proxy.cpp\n@@ -45,6 +45,8 @@ int V4L2CameraProxy::open(V4L2CameraFile *file)\n {\n \tLOG(V4L2Compat, Debug) << \"Servicing open fd = \" << file->efd();\n \n+\tMutexLocker locker(proxyMutex_);\n+\n \tif (refcount_++) {\n \t\tfiles_.insert(file);\n \t\treturn 0;\n@@ -79,6 +81,8 @@ void V4L2CameraProxy::close(V4L2CameraFile *file)\n {\n \tLOG(V4L2Compat, Debug) << \"Servicing close fd = \" << file->efd();\n \n+\tMutexLocker locker(proxyMutex_);\n+\n \tfiles_.erase(file);\n \n \trelease(file);\n@@ -94,6 +98,8 @@ void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags,\n {\n \tLOG(V4L2Compat, Debug) << \"Servicing mmap\";\n \n+\tMutexLocker locker(proxyMutex_);\n+\n \t/* \\todo Validate prot and flags properly. */\n \tif (prot != (PROT_READ | PROT_WRITE)) {\n \t\terrno = EINVAL;\n@@ -128,6 +134,8 @@ int V4L2CameraProxy::munmap(void *addr, size_t length)\n {\n \tLOG(V4L2Compat, Debug) << \"Servicing munmap\";\n \n+\tMutexLocker locker(proxyMutex_);\n+\n \tauto iter = mmaps_.find(addr);\n \tif (iter == mmaps_.end() || length != sizeimage_) {\n \t\terrno = EINVAL;\n@@ -589,7 +597,8 @@ int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg)\n \treturn ret;\n }\n \n-int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg)\n+int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg,\n+\t\t\t\t MutexLocker *locker)\n {\n \tLOG(V4L2Compat, Debug) << \"Servicing vidioc_dqbuf fd = \" << file->efd();\n \n@@ -606,9 +615,11 @@ int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg)\n \t !validateMemoryType(arg->memory))\n \t\treturn -EINVAL;\n \n-\tif (!file->nonBlocking())\n+\tif (!file->nonBlocking()) {\n+\t\tlocker->unlock();\n \t\tvcam_->waitForBufferAvailable();\n-\telse if (!vcam_->isBufferAvailable())\n+\t\tlocker->lock();\n+\t} else if (!vcam_->isBufferAvailable())\n \t\treturn -EAGAIN;\n \n \t/*\n@@ -703,6 +714,8 @@ const std::set<unsigned long> V4L2CameraProxy::supportedIoctls_ = {\n \n int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *arg)\n {\n+\tMutexLocker locker(proxyMutex_);\n+\n \tif (!arg && (_IOC_DIR(request) & _IOC_WRITE)) {\n \t\terrno = EFAULT;\n \t\treturn -1;\n@@ -763,7 +776,7 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *ar\n \t\tret = vidioc_qbuf(file, static_cast<struct v4l2_buffer *>(arg));\n \t\tbreak;\n \tcase VIDIOC_DQBUF:\n-\t\tret = vidioc_dqbuf(file, static_cast<struct v4l2_buffer *>(arg));\n+\t\tret = vidioc_dqbuf(file, static_cast<struct v4l2_buffer *>(arg), &locker);\n \t\tbreak;\n \tcase VIDIOC_STREAMON:\n \t\tret = vidioc_streamon(file, static_cast<int *>(arg));\ndiff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\nindex 5de2c5a..d78a472 100644\n--- a/src/v4l2/v4l2_camera_proxy.h\n+++ b/src/v4l2/v4l2_camera_proxy.h\n@@ -61,7 +61,7 @@ private:\n \tint vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuffers *arg);\n \tint vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg);\n \tint vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg);\n-\tint vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg);\n+\tint vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, MutexLocker *locker);\n \tint vidioc_streamon(V4L2CameraFile *file, int *arg);\n \tint vidioc_streamoff(V4L2CameraFile *file, int *arg);\n \n@@ -105,6 +105,9 @@ private:\n \t * will return -EBUSY.\n \t */\n \tV4L2CameraFile *owner_;\n+\n+\t/* This mutex is to serialize access to the proxy. */\n+\tMutex proxyMutex_;\n };\n \n #endif /* __V4L2_CAMERA_PROXY_H__ */\n", "prefixes": [ "libcamera-devel", "v4", "22/22" ] }