Show a patch.

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

{
    "id": 15220,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/15220/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15220/",
    "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": "<20211226231255.18653-2-laurent.pinchart@ideasonboard.com>",
    "date": "2021-12-26T23:12:54",
    "name": "[libcamera-devel,v2,1/2] libcamera: media_device: Move recursive lock handling to pipeline handler",
    "commit_ref": "ec6921d7f7ef70cd7c5ea3d7a20082d66b8aa6e5",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "f0a59f20d90a1d1fcb83a8860e34ea89a99b2d08",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/15220/mbox/",
    "series": [
        {
            "id": 2865,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2865/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2865",
            "date": "2021-12-26T23:12:53",
            "name": "libcamera: Small cleanups for pipeline handler locking",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2865/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15220/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15220/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2C917C3258\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 26 Dec 2021 23:13:09 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 41E7F60912;\n\tMon, 27 Dec 2021 00:13:08 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DB8BD608E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Dec 2021 00:13:05 +0100 (CET)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 81607A15\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Dec 2021 00:13:05 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"DSpz6UOU\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1640560385;\n\tbh=2fBi/E7xfJUsa6NW8y2N4x7gxRYz3bcVIvyPZkjOPb8=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=DSpz6UOU7DUvX6YmNK3QEwe1PYSUnwdCWHAMUg2rw+sMO78wsP/LhKNc0jWIOee5B\n\thjqzUsumQ9NbXt5Ahy6mr9HUIAox/ebuBxChr2C88qyPMU7A4h+Vmj2JaDHVC4YRvJ\n\tdIPwNKx3vmk0LrPmMPrrsbxJe/DUfgg43AAUxn1A=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 27 Dec 2021 01:12:54 +0200",
        "Message-Id": "<20211226231255.18653-2-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20211226231255.18653-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20211226231255.18653-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 1/2] libcamera: media_device: Move\n\trecursive lock handling to pipeline handler",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The MediaDevice lock is meant to prevent concurrent usage of multiple\ncameras from the same pipeline handlers. As media devices are acquired\nby pipeline handlers, we can't have multiple pipeline handlers trying to\nlock the same media device. The recursive locking detection can thus be\nmoved to the pipeline handler. This simplifies the media device\nimplementation that now implements true lock semantics, and prepares for\nsupport of concurrent camera usage.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v1:\n\n- Fix lock owner check un PipelineHandler::unlock()\n---\n include/libcamera/internal/media_device.h     |  1 -\n include/libcamera/internal/pipeline_handler.h |  2 ++\n src/libcamera/media_device.cpp                | 14 +-------------\n src/libcamera/pipeline_handler.cpp            | 13 ++++++++++++-\n 4 files changed, 15 insertions(+), 15 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h\nindex af0b25b731eb..6e2a63f38229 100644\n--- a/include/libcamera/internal/media_device.h\n+++ b/include/libcamera/internal/media_device.h\n@@ -86,7 +86,6 @@ private:\n \tUniqueFD fd_;\n \tbool valid_;\n \tbool acquired_;\n-\tbool lockOwner_;\n \n \tstd::map<unsigned int, MediaObject *> objects_;\n \tstd::vector<MediaEntity *> entities_;\ndiff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex ec986a518b5c..a7331cedfb16 100644\n--- a/include/libcamera/internal/pipeline_handler.h\n+++ b/include/libcamera/internal/pipeline_handler.h\n@@ -88,6 +88,8 @@ private:\n \n \tconst char *name_;\n \n+\tbool lockOwner_;\n+\n \tfriend class PipelineHandlerFactory;\n };\n \ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 0b7940182d0c..941f86c25f66 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -63,8 +63,7 @@ LOG_DEFINE_CATEGORY(MediaDevice)\n  * populate() before the media graph can be queried.\n  */\n MediaDevice::MediaDevice(const std::string &deviceNode)\n-\t: deviceNode_(deviceNode), valid_(false), acquired_(false),\n-\t  lockOwner_(false)\n+\t: deviceNode_(deviceNode), valid_(false), acquired_(false)\n {\n }\n \n@@ -145,15 +144,9 @@ bool MediaDevice::lock()\n \tif (!fd_.isValid())\n \t\treturn false;\n \n-\t/* Do not allow nested locking in the same libcamera instance. */\n-\tif (lockOwner_)\n-\t\treturn false;\n-\n \tif (lockf(fd_.get(), F_TLOCK, 0))\n \t\treturn false;\n \n-\tlockOwner_ = true;\n-\n \treturn true;\n }\n \n@@ -171,11 +164,6 @@ void MediaDevice::unlock()\n \tif (!fd_.isValid())\n \t\treturn;\n \n-\tif (!lockOwner_)\n-\t\treturn;\n-\n-\tlockOwner_ = false;\n-\n \tlockf(fd_.get(), F_ULOCK, 0);\n }\n \ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex 0bc0e341b9e7..a9241ac62979 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -67,7 +67,7 @@ LOG_DEFINE_CATEGORY(Pipeline)\n  * respective factories.\n  */\n PipelineHandler::PipelineHandler(CameraManager *manager)\n-\t: manager_(manager)\n+\t: manager_(manager), lockOwner_(false)\n {\n }\n \n@@ -155,6 +155,10 @@ MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,\n  */\n bool PipelineHandler::lock()\n {\n+\t/* Do not allow nested locking in the same libcamera instance. */\n+\tif (lockOwner_)\n+\t\treturn false;\n+\n \tfor (std::shared_ptr<MediaDevice> &media : mediaDevices_) {\n \t\tif (!media->lock()) {\n \t\t\tunlock();\n@@ -162,6 +166,8 @@ bool PipelineHandler::lock()\n \t\t}\n \t}\n \n+\tlockOwner_ = true;\n+\n \treturn true;\n }\n \n@@ -177,8 +183,13 @@ bool PipelineHandler::lock()\n  */\n void PipelineHandler::unlock()\n {\n+\tif (!lockOwner_)\n+\t\treturn;\n+\n \tfor (std::shared_ptr<MediaDevice> &media : mediaDevices_)\n \t\tmedia->unlock();\n+\n+\tlockOwner_ = false;\n }\n \n /**\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "1/2"
    ]
}