{"id":11711,"url":"https://patchwork.libcamera.org/api/1.1/patches/11711/?format=json","web_url":"https://patchwork.libcamera.org/patch/11711/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210325134231.1400051-4-kieran.bingham@ideasonboard.com>","date":"2021-03-25T13:42:21","name":"[libcamera-devel,v3,01/11] utils: ipc: proxy: Track IPA with a state machine","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"2b76e25f96b260a0fafb1fdee2eedaf553eb484b","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":{"id":11,"url":"https://patchwork.libcamera.org/api/1.1/users/11/?format=json","username":"kbingham","first_name":"Kieran","last_name":"Bingham","email":"kieran.bingham@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/11711/mbox/","series":[{"id":1832,"url":"https://patchwork.libcamera.org/api/1.1/series/1832/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1832","date":"2021-03-25T13:42:18","name":"[libcamera-devel,v3,01/11] utils: ipc: proxy: Track IPA with a state machine","version":1,"mbox":"https://patchwork.libcamera.org/series/1832/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11711/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11711/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 B7042C32E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Mar 2021 13:42:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0619468D6F;\n\tThu, 25 Mar 2021 14:42:42 +0100 (CET)","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 D952268D65\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Mar 2021 14:42:36 +0100 (CET)","from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net\n\t[86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1F5A89E2;\n\tThu, 25 Mar 2021 14:42:36 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"XFLiqdm1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1616679756;\n\tbh=vWzp2bDJ+S4i2TlHdo96t+Gp4Gtj4US4xzNZZNTCwd0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=XFLiqdm1lkJPqQeCOMI4E/fpelQkE+11NyWwDJ0jwesZ7ZQZXiRrBNEdOYK4w4wwj\n\tCJhLNmA5mhMkgU2mur/lvhl6mijBVpdhXsE73GUgU7cXh8/MO77XYSLqkYwB4VrsnT\n\tqZjJSevcAAphj4WtQhknyy0MszVmrdARwy9Ql0io=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Thu, 25 Mar 2021 13:42:21 +0000","Message-Id":"<20210325134231.1400051-4-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20210325134231.1400051-1-kieran.bingham@ideasonboard.com>","References":"<20210325134231.1400051-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 01/11] utils: ipc: proxy: Track IPA\n\twith a state machine","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=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Asynchronous tasks can only be submitted while the IPA is running.\n\nFurther more, the shutdown sequence can not be tracked with a simple\nrunning flag. We can also be in the state 'Stopping' where we have not\nyet completed all events, but we must not commence anything new.\n\nRefactor the running_ boolean into a stateful enum to track this.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n .../libcamera_templates/module_ipa_proxy.cpp.tmpl         | 8 ++++----\n .../libcamera_templates/module_ipa_proxy.h.tmpl           | 8 +++++++-\n .../generators/libcamera_templates/proxy_functions.tmpl   | 7 +++++--\n 3 files changed, 16 insertions(+), 7 deletions(-)","diff":"diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\nindex e3b541db4e36..dd0f4d3f64b6 100644\n--- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n+++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n@@ -45,7 +45,7 @@ namespace {{ns}} {\n {%- endif %}\n \n {{proxy_name}}::{{proxy_name}}(IPAModule *ipam, bool isolate)\n-\t: IPAProxy(ipam), running_(false),\n+\t: IPAProxy(ipam), state_(Stopped),\n \t  isolate_(isolate), seq_(0)\n {\n \tLOG(IPAProxy, Debug)\n@@ -155,7 +155,7 @@ void {{proxy_name}}::recvMessage(const IPCMessage &data)\n \n \treturn {{ \"_ret\" if method|method_return_value != \"void\" }};\n {%- elif method.mojom_name == \"start\" %}\n-\trunning_ = true;\n+\tstate_ = Running;\n \tthread_.start();\n \n \t{{ \"return \" if method|method_return_value != \"void\" -}}\n@@ -173,7 +173,7 @@ void {{proxy_name}}::recvMessage(const IPCMessage &data)\n \t{%- endfor -%}\n );\n {% elif method|is_async %}\n-\tASSERT(running_);\n+\tASSERT(state_ == Running);\n \tproxy_.invokeMethod(&ThreadProxy::{{method.mojom_name}}, ConnectionTypeQueued,\n \t{%- for param in method|method_param_names -%}\n \t\t{{param}}{{- \", \" if not loop.last}}\n@@ -226,7 +226,7 @@ void {{proxy_name}}::recvMessage(const IPCMessage &data)\n {% for method in interface_event.methods %}\n {{proxy_funcs.func_sig(proxy_name, method, \"Thread\")}}\n {\n-\tASSERT(running_);\n+\tASSERT(state_ != Stopped);\n \t{{method.mojom_name}}.emit({{method.parameters|params_comma_sep}});\n }\n \ndiff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl\nindex efb09a180b90..e33c26492d91 100644\n--- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl\n+++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl\n@@ -104,7 +104,13 @@ private:\n \t\t{{interface_name}} *ipa_;\n \t};\n \n-\tbool running_;\n+\tenum {{proxy_name}}States {\n+\t\tStopped,\n+\t\tStopping,\n+\t\tRunning,\n+\t};\n+\tenum {{proxy_name}}States state_;\n+\n \tThread thread_;\n \tThreadProxy proxy_;\n \tstd::unique_ptr<{{interface_name}}> ipa_;\ndiff --git a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl\nindex 8addc2fad0a8..09394a4fec83 100644\n--- a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl\n+++ b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl\n@@ -23,9 +23,12 @@\n  # \\brief Generate function body for IPA stop() function for thread\n  #}\n {%- macro stop_thread_body() -%}\n-\tif (!running_)\n+\tASSERT(state_ != Stopping);\n+\tif (state_ != Running)\n \t\treturn;\n \n+\tstate_ = Stopping;\n+\n \tproxy_.invokeMethod(&ThreadProxy::stop, ConnectionTypeBlocking);\n \n \tthread_.exit();\n@@ -33,7 +36,7 @@\n \n \tThread::current()->dispatchMessages(Message::Type::InvokeMessage);\n \n-\trunning_ = false;\n+\tstate_ = Stopped;\n {%- endmacro -%}\n \n \n","prefixes":["libcamera-devel","v3","01/11"]}