Show a patch.

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

{
    "id": 1830,
    "url": "https://patchwork.libcamera.org/api/patches/1830/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1830/",
    "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": "<20190817152104.10834-13-laurent.pinchart@ideasonboard.com>",
    "date": "2019-08-17T15:20:58",
    "name": "[libcamera-devel,v2,12/18] libcamera: timer: Bind timers to threads",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "1b073729063010a1e10b4d1b0f7af6cbf92e5247",
    "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/1830/mbox/",
    "series": [
        {
            "id": 463,
            "url": "https://patchwork.libcamera.org/api/series/463/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=463",
            "date": "2019-08-17T15:20:46",
            "name": "Object & Thread enhancements",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/463/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1830/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1830/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 4E90761920\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Aug 2019 17:21:17 +0200 (CEST)",
            "from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DB9B5E70\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Aug 2019 17:21:16 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1566055277;\n\tbh=k3lsHINhRA1bC8Q8vyGfm6YEox6cCIeNKhXPKEZincc=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=UWDwJfmQcP91gByQYZ+XmbjMzIuLyCugoVWFfXoJs9GL9l9gi1Ne4pvvxD4x1jTEx\n\t+RCPHsxUz8cEvuB46bKjveXjgRVoDnrtFds2DhZOSiU0/AQvoeiS1gFlV9b3dyslav\n\tv2dRJpb3q2jh9E5iQ+FyXHqan0elg4Xe5cwYTovo=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 17 Aug 2019 18:20:58 +0300",
        "Message-Id": "<20190817152104.10834-13-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190817152104.10834-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20190817152104.10834-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 12/18] libcamera: timer: Bind timers to\n\tthreads",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.23",
        "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": "Sat, 17 Aug 2019 15:21:18 -0000"
    },
    "content": "The Timer instances are registered with the event dispatcher instance of\nthe CameraManager. This makes it impossible to use timers in other\nthreads.\n\nFix this by inheriting from Object, which allows binding instances to a\nthread, and register them with the event dispatcher for the thread they\nare bound to.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\nChanges since v1:\n\n- Fix invokeMethod() call\n---\n include/libcamera/timer.h | 11 ++++++++++-\n src/libcamera/timer.cpp   | 28 ++++++++++++++++++++++++++--\n 2 files changed, 36 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h\nindex f082339b1fed..853808e07da8 100644\n--- a/include/libcamera/timer.h\n+++ b/include/libcamera/timer.h\n@@ -9,11 +9,14 @@\n \n #include <cstdint>\n \n+#include <libcamera/object.h>\n #include <libcamera/signal.h>\n \n namespace libcamera {\n \n-class Timer\n+class Message;\n+\n+class Timer : public Object\n {\n public:\n \tTimer();\n@@ -28,7 +31,13 @@ public:\n \n \tSignal<Timer *> timeout;\n \n+protected:\n+\tvoid message(Message *msg) override;\n+\n private:\n+\tvoid registerTimer();\n+\tvoid unregisterTimer();\n+\n \tunsigned int interval_;\n \tuint64_t deadline_;\n };\ndiff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp\nindex 0dcb4e767be3..f45061d4c6f6 100644\n--- a/src/libcamera/timer.cpp\n+++ b/src/libcamera/timer.cpp\n@@ -13,6 +13,8 @@\n #include <libcamera/event_dispatcher.h>\n \n #include \"log.h\"\n+#include \"message.h\"\n+#include \"thread.h\"\n \n /**\n  * \\file timer.h\n@@ -66,7 +68,7 @@ void Timer::start(unsigned int msec)\n \t\t<< \"Starting timer \" << this << \" with interval \"\n \t\t<< msec << \": deadline \" << deadline_;\n \n-\tCameraManager::instance()->eventDispatcher()->registerTimer(this);\n+\tregisterTimer();\n }\n \n /**\n@@ -79,11 +81,21 @@ void Timer::start(unsigned int msec)\n  */\n void Timer::stop()\n {\n-\tCameraManager::instance()->eventDispatcher()->unregisterTimer(this);\n+\tunregisterTimer();\n \n \tdeadline_ = 0;\n }\n \n+void Timer::registerTimer()\n+{\n+\tthread()->eventDispatcher()->registerTimer(this);\n+}\n+\n+void Timer::unregisterTimer()\n+{\n+\tthread()->eventDispatcher()->unregisterTimer(this);\n+}\n+\n /**\n  * \\brief Check if the timer is running\n  * \\return True if the timer is running, false otherwise\n@@ -112,4 +124,16 @@ bool Timer::isRunning() const\n  * The timer pointer is passed as a parameter.\n  */\n \n+void Timer::message(Message *msg)\n+{\n+\tif (msg->type() == Message::ThreadMoveMessage) {\n+\t\tif (deadline_) {\n+\t\t\tunregisterTimer();\n+\t\t\tinvokeMethod(&Timer::registerTimer);\n+\t\t}\n+\t}\n+\n+\tObject::message(msg);\n+}\n+\n } /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "12/18"
    ]
}