Show a patch.

GET /api/1.1/patches/4196/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 4196,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/4196/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/4196/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20200623190836.53446-23-paul.elder@ideasonboard.com>",
    "date": "2020-06-23T19:08:36",
    "name": "[libcamera-devel,v3,22/22] v4l2: v4l2_camera_proxy: Serialize accesses to the proxy",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "a78ea1d93936572be0fbfca8264906869ef814a5",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/4196/mbox/",
    "series": [
        {
            "id": 1034,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1034/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1034",
            "date": "2020-06-23T19:08:14",
            "name": "Support v4l2-compliance",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/1034/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/4196/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/4196/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 9DD28609A5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Jun 2020 21:09:54 +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 D82D62A9;\n\tTue, 23 Jun 2020 21:09:52 +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=\"aYFYKMfd\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1592939394;\n\tbh=k8o6WuWrzmBNrvXuH4vQNDxdWsdjieEbXQZDGJ4Tib8=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=aYFYKMfdizUdEB3LEj/WS9j4AU9LmiDaW2fM2FHpDHKnazmUj9Oj7xXEFIzQOgtQg\n\tdvILgj1TUHqiFDFUQCgU9XJmWfMf4BuKKaLeQuY8Eb+XPgCmM7enG/4E+kfuDRxadS\n\t/NQZXFDC49F8Z8z767+/CZKj8PtD4c85jipjs+ss=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 24 Jun 2020 04:08:36 +0900",
        "Message-Id": "<20200623190836.53446-23-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "In-Reply-To": "<20200623190836.53446-1-paul.elder@ideasonboard.com>",
        "References": "<20200623190836.53446-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 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": "Tue, 23 Jun 2020 19:09:54 -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>\n\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 ed3bcbc..fb3a1fc 100644\n--- a/src/v4l2/v4l2_camera_proxy.cpp\n+++ b/src/v4l2/v4l2_camera_proxy.cpp\n@@ -43,6 +43,8 @@ V4L2CameraProxy::V4L2CameraProxy(unsigned int index,\n \n int V4L2CameraProxy::open(V4L2CameraFile *file)\n {\n+\tMutexLocker locker(proxyMutex_);\n+\n \tLOG(V4L2Compat, Debug) << \"Servicing open fd = \" << file->efd();\n \n \tfiles_.insert(file);\n@@ -75,6 +77,8 @@ int V4L2CameraProxy::open(V4L2CameraFile *file)\n \n void V4L2CameraProxy::close(V4L2CameraFile *file)\n {\n+\tMutexLocker locker(proxyMutex_);\n+\n \tLOG(V4L2Compat, Debug) << \"Servicing close fd = \" << file->efd();\n \n \tfiles_.erase(file);\n@@ -90,6 +94,8 @@ void V4L2CameraProxy::close(V4L2CameraFile *file)\n void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags,\n \t\t\t    off64_t offset)\n {\n+\tMutexLocker locker(proxyMutex_);\n+\n \tLOG(V4L2Compat, Debug) << \"Servicing mmap\";\n \n \t/* \\todo Validate prot and flags properly. */\n@@ -124,6 +130,8 @@ void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags,\n \n int V4L2CameraProxy::munmap(void *addr, size_t length)\n {\n+\tMutexLocker locker(proxyMutex_);\n+\n \tLOG(V4L2Compat, Debug) << \"Servicing munmap\";\n \n \tauto iter = mmaps_.find(addr);\n@@ -592,7 +600,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,\n+\t\t\t\t  struct v4l2_buffer *arg, MutexLocker &locker)\n {\n \tLOG(V4L2Compat, Debug) << \"Servicing vidioc_dqbuf fd = \" << file->efd();\n \n@@ -609,9 +618,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@@ -706,6 +717,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@@ -766,7 +779,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 041f536..b6d2c2c 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 * g/s_priority, enum/g/s_input\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",
        "v3",
        "22/22"
    ]
}