Patch Detail
Show a patch.
GET /api/patches/2805/?format=api
{ "id": 2805, "url": "https://patchwork.libcamera.org/api/patches/2805/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2805/", "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": "<20200213124538.21556-1-laurent.pinchart@ideasonboard.com>", "date": "2020-02-13T12:45:36", "name": "[libcamera-devel,v2,1/3] libcamera: thread: Support timeout in wait() function", "commit_ref": "3f207e0b333c6b8f071f6d04cea96eb9c26b0f16", "pull_url": null, "state": "accepted", "archived": false, "hash": "b5ec2a8f805537d918adc913e5bffdd25e1137c2", "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/2805/mbox/", "series": [ { "id": 669, "url": "https://patchwork.libcamera.org/api/series/669/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=669", "date": "2020-02-13T12:45:36", "name": "[libcamera-devel,v2,1/3] libcamera: thread: Support timeout in wait() function", "version": 2, "mbox": "https://patchwork.libcamera.org/series/669/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2805/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2805/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 E5A336043A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Feb 2020 13:45:58 +0100 (CET)", "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6730D504\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Feb 2020 13:45:58 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1581597958;\n\tbh=hZSK0l6AfPfGCcA9tZ491nF3xbSfMbucnv2w4Y3oWRs=;\n\th=From:To:Subject:Date:From;\n\tb=B8NXFA0wnF23Rlop2gzIq9z/arqaw4v14z/lFpzKkCCSJVGgrzjsc+2cyZLIfmoHl\n\tn9bHEOQoqn1Huk9PaYQt5ZrQz+L1xbMWQQX0eIzcerHrkWTXuv8MPZ+j9O3z9LI3jV\n\t+tuYa5IlDlgXId05WHRanx+u8bOjwrqc7Y0K/xOI=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 13 Feb 2020 14:45:36 +0200", "Message-Id": "<20200213124538.21556-1-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.24.1", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 1/3] libcamera: thread: Support timeout\n\tin wait() function", "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": "Thu, 13 Feb 2020 12:45:59 -0000" }, "content": "Add a parameter to the Thread::wait() function to wait with a timeout.\nThe delay value utils::duration::max() waits forever.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\nChanges since v1:\n\n- Invert return value of the wait() function to match the documentation\n---\n src/libcamera/include/thread.h | 4 +++-\n src/libcamera/thread.cpp | 28 +++++++++++++++++++++++++---\n 2 files changed, 28 insertions(+), 4 deletions(-)", "diff": "diff --git a/src/libcamera/include/thread.h b/src/libcamera/include/thread.h\nindex 819a9879ac56..d700f111a3ae 100644\n--- a/src/libcamera/include/thread.h\n+++ b/src/libcamera/include/thread.h\n@@ -14,6 +14,8 @@\n \n #include <libcamera/signal.h>\n \n+#include \"utils.h\"\n+\n namespace libcamera {\n \n class EventDispatcher;\n@@ -33,7 +35,7 @@ public:\n \n \tvoid start();\n \tvoid exit(int code = 0);\n-\tvoid wait();\n+\tbool wait(utils::duration duration = utils::duration::max());\n \n \tbool isRunning();\n \ndiff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp\nindex 1d0a600ab5cc..b613305fdc87 100644\n--- a/src/libcamera/thread.cpp\n+++ b/src/libcamera/thread.cpp\n@@ -8,6 +8,7 @@\n #include \"thread.h\"\n \n #include <atomic>\n+#include <condition_variable>\n #include <list>\n #include <unistd.h>\n #include <sys/syscall.h>\n@@ -155,6 +156,7 @@ private:\n \n \tstd::atomic<EventDispatcher *> dispatcher_;\n \n+\tstd::condition_variable cv_;\n \tstd::atomic<bool> exit_;\n \tint exitCode_;\n \n@@ -334,6 +336,7 @@ void Thread::finishThread()\n \tdata_->mutex_.unlock();\n \n \tfinished.emit(this);\n+\tdata_->cv_.notify_all();\n }\n \n /**\n@@ -360,14 +363,33 @@ void Thread::exit(int code)\n \n /**\n * \\brief Wait for the thread to finish\n+ * \\param[in] duration Maximum wait duration\n *\n- * This method waits until the thread finishes, or returns immediately if the\n- * thread is not running.\n+ * This function waits until the thread finishes or the \\a duration has\n+ * elapsed, whichever happens first. If \\a duration is equal to\n+ * utils::duration::max(), the wait never times out. If the thread is not\n+ * running the function returns immediately.\n+ *\n+ * \\return True if the thread has finished, or false if the wait timed out\n */\n-void Thread::wait()\n+bool Thread::wait(utils::duration duration)\n {\n+\tbool finished = true;\n+\n+\t{\n+\t\tMutexLocker locker(data_->mutex_);\n+\n+\t\tif (duration == utils::duration::max())\n+\t\t\tdata_->cv_.wait(locker, [&]() { return !data_->running_; });\n+\t\telse\n+\t\t\tfinished = data_->cv_.wait_for(locker, duration,\n+\t\t\t\t\t\t [&]() { return !data_->running_; });\n+\t}\n+\n \tif (thread_.joinable())\n \t\tthread_.join();\n+\n+\treturn finished;\n }\n \n /**\n", "prefixes": [ "libcamera-devel", "v2", "1/3" ] }