Show a patch.

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

{
    "id": 2381,
    "url": "https://patchwork.libcamera.org/api/patches/2381/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2381/",
    "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": "<20191127084909.10612-3-laurent.pinchart@ideasonboard.com>",
    "date": "2019-11-27T08:49:07",
    "name": "[libcamera-devel,3/5] libcamera: thread: Fix race condition when dispatching messages",
    "commit_ref": "e54e9ebff4293c2bcacac4ecb10af8b29480fba9",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "5c142c3d814f98efdb37dbffe0c358112bd5c115",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2381/mbox/",
    "series": [
        {
            "id": 580,
            "url": "https://patchwork.libcamera.org/api/series/580/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=580",
            "date": "2019-11-27T08:49:05",
            "name": "[libcamera-devel,1/5] test: message: Fix message handling in MessageReceiver",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/580/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2381/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2381/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C82160BB8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Nov 2019 09:49:26 +0100 (CET)",
            "from pendragon.tok.corp.google.com (unknown [104.132.253.101])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F3A269F4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Nov 2019 09:49:24 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1574844565;\n\tbh=XdmYqbeOJzAczJosIpJ/e4IR/lacPzAmhE0GxY0CLyg=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=riZS7kcV3m0k6MZZtfaaEQSpRixZzMCh+tTAxHy3KMJWJoW3tWVDi8HLvWxz8wXK+\n\t9ow2t8/ms/kuq0ZD+V5bWvSmPHOgmFdQJx5NNplx0pR55DHn5paKZa/zUxA/jAxzEz\n\tMEQWECWT6Rf3QYoIUukd6r9NH1HTcK3QN2bZ7RrU=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 27 Nov 2019 10:49:07 +0200",
        "Message-Id": "<20191127084909.10612-3-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.23.0",
        "In-Reply-To": "<20191127084909.10612-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20191127084909.10612-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 3/5] libcamera: thread: Fix race condition\n\twhen dispatching messages",
        "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, 27 Nov 2019 08:49:26 -0000"
    },
    "content": "The Object class stores the number of pending messages that have been\nposted for it, while the actual messages are stored in a per-thread list\nin the ThreadData class. When dispatching messages, the message is\nremoved from the list, passed to the receiver, and the number of pending\nmessages is updated.\n\nIn order to avoid too much contention on the list lock, the lock is\ndropped to pass the message to the receiver and then taken again. This\ncreates a race condition window with Thread::removeMessages(), as the\nnumber of pending messages for a receiver is briefly out of sync with\nthe pending messages list. The assertion at the end of removeMessages()\nthus sometimes fails.\n\nFix this by decrementing the pending messages counter before releasing\nthe lock in Thread::dispatchMessages(). This fixes the slow message\nreceiver test in MessageTest.\n\nFixes: 01b930964acd (\"libcamera: thread: Add a messaging passing API\")\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/thread.cpp | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp\nindex 029a0e8fddd5..18ebd16a7e2f 100644\n--- a/src/libcamera/thread.cpp\n+++ b/src/libcamera/thread.cpp\n@@ -439,11 +439,11 @@ void Thread::dispatchMessages()\n \t\tObject *receiver = msg->receiver_;\n \t\tASSERT(data_ == receiver->thread()->data_);\n \n+\t\treceiver->pendingMessages_--;\n+\n \t\tlocker.unlock();\n \t\treceiver->message(msg.get());\n \t\tlocker.lock();\n-\n-\t\treceiver->pendingMessages_--;\n \t}\n }\n \n",
    "prefixes": [
        "libcamera-devel",
        "3/5"
    ]
}