Patch Detail
Show a patch.
GET /api/patches/10903/?format=api
{ "id": 10903, "url": "https://patchwork.libcamera.org/api/patches/10903/?format=api", "web_url": "https://patchwork.libcamera.org/patch/10903/", "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": "<20210119233315.3305649-1-niklas.soderlund@ragnatech.se>", "date": "2021-01-19T23:33:15", "name": "[libcamera-devel,v2] cam: event_loop: Stop processing calls when event loop is exiting", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "2c61d7fcef4fcb79ced1c8f440cfb29ffe4f661f", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": { "id": 16, "url": "https://patchwork.libcamera.org/api/users/16/?format=api", "username": "neg", "first_name": "Niklas", "last_name": "Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "mbox": "https://patchwork.libcamera.org/patch/10903/mbox/", "series": [ { "id": 1586, "url": "https://patchwork.libcamera.org/api/series/1586/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1586", "date": "2021-01-19T23:33:15", "name": "[libcamera-devel,v2] cam: event_loop: Stop processing calls when event loop is exiting", "version": 2, "mbox": "https://patchwork.libcamera.org/series/1586/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/10903/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/10903/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 ED3C9C0F1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Jan 2021 23:33:25 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CAB4A68170;\n\tWed, 20 Jan 2021 00:33:25 +0100 (CET)", "from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A1AB6010B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Jan 2021 00:33:24 +0100 (CET)", "from bismarck.berto.se (p4fca2458.dip0.t-ipconnect.de\n\t[79.202.36.88])\n\tby bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid b5de9dfd-5aae-11eb-a076-005056917f90;\n\tWed, 20 Jan 2021 00:33:22 +0100 (CET)" ], "X-Halon-ID": "b5de9dfd-5aae-11eb-a076-005056917f90", "Authorized-sender": "niklas.soderlund@fsdn.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 20 Jan 2021 00:33:15 +0100", "Message-Id": "<20210119233315.3305649-1-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.30.0", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v2] cam: event_loop: Stop processing calls\n\twhen event loop is exiting", "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>", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "base64", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Terminating the event loop with EventLoop::exit() does not grantee that\nit will terminate. If the event loops 'call later' queue can be kept\nnon-empty by continuously queuing new calls using EventLoop::callLater()\neither from a different thread or from callbacks in the loop itself\nEventLoop::dispatchCalls() will never complete and the loop will run\nforever.\n\nSolve this by evaluating the exit condition between each callback and\nonly enter the idle loop if there are no callbacks to process.\n\nReported-by: Sebastian Fricke <sebastian.fricke@posteo.net>\nFixes: f49e93338b6309a6 (\"cam: event_loop: Add deferred calls support\")\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n* Changes since v1\n- Was [PATCH 0/2] cam: Fix races in event loop and long request\n processing times\n- Rework dispatchCalls() instead of callLater() for a simpler fix.\n---\n src/cam/event_loop.cpp | 22 +++++++++++++---------\n src/cam/event_loop.h | 2 +-\n 2 files changed, 14 insertions(+), 10 deletions(-)", "diff": "diff --git a/src/cam/event_loop.cpp b/src/cam/event_loop.cpp\nindex 94c5d1d362455f33..18786b4500be9b6f 100644\n--- a/src/cam/event_loop.cpp\n+++ b/src/cam/event_loop.cpp\n@@ -41,7 +41,9 @@ int EventLoop::exec()\n \texit_.store(false, std::memory_order_release);\n \n \twhile (!exit_.load(std::memory_order_acquire)) {\n-\t\tdispatchCalls();\n+\t\tif (dispatchCall())\n+\t\t\tcontinue;\n+\n \t\tevent_base_loop(event_, EVLOOP_NO_EXIT_ON_EMPTY);\n \t}\n \n@@ -70,17 +72,19 @@ void EventLoop::callLater(const std::function<void()> &func)\n \tinterrupt();\n }\n \n-void EventLoop::dispatchCalls()\n+bool EventLoop::dispatchCall()\n {\n \tstd::unique_lock<std::mutex> locker(lock_);\n \n-\tfor (auto iter = calls_.begin(); iter != calls_.end(); ) {\n-\t\tstd::function<void()> call = std::move(*iter);\n+\tif (calls_.empty())\n+\t\treturn false;\n \n-\t\titer = calls_.erase(iter);\n+\tauto iter = calls_.begin();\n+\tstd::function<void()> call = std::move(*iter);\n+\tcalls_.erase(iter);\n \n-\t\tlocker.unlock();\n-\t\tcall();\n-\t\tlocker.lock();\n-\t}\n+\tlocker.unlock();\n+\tcall();\n+\n+\treturn true;\n }\ndiff --git a/src/cam/event_loop.h b/src/cam/event_loop.h\nindex 408073c50594d09d..b84e1c9e432086e3 100644\n--- a/src/cam/event_loop.h\n+++ b/src/cam/event_loop.h\n@@ -38,7 +38,7 @@ private:\n \tstd::mutex lock_;\n \n \tvoid interrupt();\n-\tvoid dispatchCalls();\n+\tbool dispatchCall();\n };\n \n #endif /* __CAM_EVENT_LOOP_H__ */\n", "prefixes": [ "libcamera-devel", "v2" ] }