Patch Detail
Show a patch.
GET /api/patches/17519/?format=api
{ "id": 17519, "url": "https://patchwork.libcamera.org/api/patches/17519/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17519/", "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": "<20221003235843.19175-1-laurent.pinchart@ideasonboard.com>", "date": "2022-10-03T23:58:43", "name": "[libcamera-devel] test: threads: Test thread cleanup upon abnormal termination", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "371c0435b81fd853e67b461c35ba4fb6541135fd", "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/17519/mbox/", "series": [ { "id": 3529, "url": "https://patchwork.libcamera.org/api/series/3529/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3529", "date": "2022-10-03T23:58:43", "name": "[libcamera-devel] test: threads: Test thread cleanup upon abnormal termination", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3529/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17519/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17519/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 906A9C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 3 Oct 2022 23:58:48 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EB2AE603F6;\n\tTue, 4 Oct 2022 01:58:47 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ADDC0601C7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 4 Oct 2022 01:58:46 +0200 (CEST)", "from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0AE069DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 4 Oct 2022 01:58:45 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1664841527;\n\tbh=0XfW4UVqEqzpmbcgfIqltsawUMmBvAWwHhqKtF10AqA=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=ThzOLyJScL7YxJYG6QZtdH1r6F3O69IDs6jHNPGZZ9IRRx2OAsq/SuTHk3Lgu64V1\n\tNjQWxxRy2MnfnAPrH/DKFH9KbnLR0//vcwnwbDMuvznTxf+V+VXxEYPeQ7SEcPYS/X\n\tsuRpVHia1uioOR7KzioYQiOIi9bAPu3DrSWPEAL8bQRHeVxTUYfeMj1m4Gel3WO2OS\n\tFu07is7f92FuekCP8icYoFMmprhMQIyBS05k7SIjaW0RH65VNy5Gy3SMDZcX6CmzJA\n\t3TkdH/0QY+zq+vLzI9sPqC2eUtaggjrAwbdZEpVKsV0kYvK/dTmc8OKP2riVs7gqLV\n\tOTuAe+E6/71YA==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1664841526;\n\tbh=0XfW4UVqEqzpmbcgfIqltsawUMmBvAWwHhqKtF10AqA=;\n\th=From:To:Subject:Date:From;\n\tb=CtoKfJkGr9V3vIgTNfd3kozimIi2/s6onWtbSvUixNDOFPwY785nt6nuQQ/eBgu4x\n\t8pJ0TSIiq7qUgR56jIXaqY9KLb885fZz7Krjtlkf1sRedlLK9xYkpuHfZcUm0oXsaR\n\tGOU4+Aziy8AJ7Ru2C04qBfwaG006iyQVz5qX12BY=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"CtoKfJkG\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 4 Oct 2022 02:58:43 +0300", "Message-Id": "<20221003235843.19175-1-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.35.1", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH] test: threads: Test thread cleanup upon\n\tabnormal termination", "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>", "From": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "If a thread ends abnormally (that is, without retuning normally from its\nrun() function, for instance with a direct call to pthread_cancel()),\nthread cleanup should still be performed. Add a test to ensure this.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n test/threads.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 44 insertions(+)", "diff": "diff --git a/test/threads.cpp b/test/threads.cpp\nindex d83b5833998f..7daa76edb00e 100644\n--- a/test/threads.cpp\n+++ b/test/threads.cpp\n@@ -8,7 +8,9 @@\n #include <chrono>\n #include <iostream>\n #include <memory>\n+#include <pthread.h>\n #include <thread>\n+#include <time.h>\n \n #include <libcamera/base/thread.h>\n \n@@ -35,6 +37,32 @@ private:\n \tchrono::steady_clock::duration duration_;\n };\n \n+class CancelThread : public Thread\n+{\n+public:\n+\tCancelThread(bool &cancelled)\n+\t\t: cancelled_(cancelled)\n+\t{\n+\t}\n+\n+protected:\n+\tvoid run()\n+\t{\n+\t\tcancelled_ = true;\n+\n+\t\t/* Cancel the thread can call a guaranteed cancellation point. */\n+\t\tpthread_cancel(pthread_self());\n+\n+\t\tstruct timespec req{ 0, 100*000*000 };\n+\t\tnanosleep(&req, nullptr);\n+\n+\t\tcancelled_ = false;\n+\t}\n+\n+private:\n+\tbool &cancelled_;\n+};\n+\n class ThreadTest : public Test\n {\n protected:\n@@ -118,6 +146,22 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\t/* Test thread cleanup upon abnormal termination. */\n+\t\tbool cancelled = false;\n+\t\tbool finished = false;\n+\n+\t\tthread = std::make_unique<CancelThread>(cancelled);\n+\t\tthread->finished.connect(this, [&finished]() { finished = true; });\n+\n+\t\tthread->start();\n+\t\tthread->exit(0);\n+\t\tthread->wait(chrono::milliseconds(1000));\n+\n+\t\tif (!cancelled || !finished) {\n+\t\t\tcout << \"Cleanup failed upon abnormal termination\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\treturn TestPass;\n \t}\n \n", "prefixes": [ "libcamera-devel" ] }