Show a patch.

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

{
    "id": 1790,
    "url": "https://patchwork.libcamera.org/api/patches/1790/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1790/",
    "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": "<20190812124642.24287-13-laurent.pinchart@ideasonboard.com>",
    "date": "2019-08-12T12:46:36",
    "name": "[libcamera-devel,12/18] libcamera: timer: Bind timers to threads",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "2fa46e4596c26dbac66eacb576ab7b436167c8c8",
    "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/1790/mbox/",
    "series": [
        {
            "id": 455,
            "url": "https://patchwork.libcamera.org/api/series/455/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=455",
            "date": "2019-08-12T12:46:24",
            "name": "Object & Thread enhancements",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/455/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1790/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1790/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A653D6194D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2019 14:46:53 +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 3C086594\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2019 14:46:53 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1565614013;\n\tbh=ZlbB3R8I8PLgHfRPqB6j65JLevL/YJbu2SIQ8Nl4tpM=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=hulO7jW+kcEr3mrdZthWqUfwseM01SW4UGYQBgWHmxSy7Nnq9kfMtuZhANgN/CH2s\n\tRMvNFWA1zrTEGVgdyHDl+XE2xLPU78Ue7dL2chzFbDx+iTUzyHHW8UBDuid7Xi6YYr\n\tnO5s0iIOsLcTb/NWrh2Gg99V5pCFzqe2duYQJY8M=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 12 Aug 2019 15:46:36 +0300",
        "Message-Id": "<20190812124642.24287-13-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190812124642.24287-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20190812124642.24287-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 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": "Mon, 12 Aug 2019 12:46:54 -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>\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..21c0a444cdce 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(this, &Timer::registerTimer);\n+\t\t}\n+\t}\n+\n+\tObject::message(msg);\n+}\n+\n } /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "12/18"
    ]
}