From patchwork Thu Mar 25 13:42:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11711 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B7042C32E9 for ; Thu, 25 Mar 2021 13:42:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0619468D6F; Thu, 25 Mar 2021 14:42:42 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XFLiqdm1"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D952268D65 for ; Thu, 25 Mar 2021 14:42:36 +0100 (CET) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1F5A89E2; Thu, 25 Mar 2021 14:42:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1616679756; bh=vWzp2bDJ+S4i2TlHdo96t+Gp4Gtj4US4xzNZZNTCwd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XFLiqdm1lkJPqQeCOMI4E/fpelQkE+11NyWwDJ0jwesZ7ZQZXiRrBNEdOYK4w4wwj CJhLNmA5mhMkgU2mur/lvhl6mijBVpdhXsE73GUgU7cXh8/MO77XYSLqkYwB4VrsnT qZjJSevcAAphj4WtQhknyy0MszVmrdARwy9Ql0io= From: Kieran Bingham To: libcamera devel 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 with a state machine X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Asynchronous tasks can only be submitted while the IPA is running. Further more, the shutdown sequence can not be tracked with a simple running flag. We can also be in the state 'Stopping' where we have not yet completed all events, but we must not commence anything new. Refactor the running_ boolean into a stateful enum to track this. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- .../libcamera_templates/module_ipa_proxy.cpp.tmpl | 8 ++++---- .../libcamera_templates/module_ipa_proxy.h.tmpl | 8 +++++++- .../generators/libcamera_templates/proxy_functions.tmpl | 7 +++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl index e3b541db4e36..dd0f4d3f64b6 100644 --- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl +++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl @@ -45,7 +45,7 @@ namespace {{ns}} { {%- endif %} {{proxy_name}}::{{proxy_name}}(IPAModule *ipam, bool isolate) - : IPAProxy(ipam), running_(false), + : IPAProxy(ipam), state_(Stopped), isolate_(isolate), seq_(0) { LOG(IPAProxy, Debug) @@ -155,7 +155,7 @@ void {{proxy_name}}::recvMessage(const IPCMessage &data) return {{ "_ret" if method|method_return_value != "void" }}; {%- elif method.mojom_name == "start" %} - running_ = true; + state_ = Running; thread_.start(); {{ "return " if method|method_return_value != "void" -}} @@ -173,7 +173,7 @@ void {{proxy_name}}::recvMessage(const IPCMessage &data) {%- endfor -%} ); {% elif method|is_async %} - ASSERT(running_); + ASSERT(state_ == Running); proxy_.invokeMethod(&ThreadProxy::{{method.mojom_name}}, ConnectionTypeQueued, {%- for param in method|method_param_names -%} {{param}}{{- ", " if not loop.last}} @@ -226,7 +226,7 @@ void {{proxy_name}}::recvMessage(const IPCMessage &data) {% for method in interface_event.methods %} {{proxy_funcs.func_sig(proxy_name, method, "Thread")}} { - ASSERT(running_); + ASSERT(state_ != Stopped); {{method.mojom_name}}.emit({{method.parameters|params_comma_sep}}); } diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl index efb09a180b90..e33c26492d91 100644 --- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl +++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl @@ -104,7 +104,13 @@ private: {{interface_name}} *ipa_; }; - bool running_; + enum {{proxy_name}}States { + Stopped, + Stopping, + Running, + }; + enum {{proxy_name}}States state_; + Thread thread_; ThreadProxy proxy_; std::unique_ptr<{{interface_name}}> ipa_; diff --git a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl index 8addc2fad0a8..09394a4fec83 100644 --- a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl +++ b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl @@ -23,9 +23,12 @@ # \brief Generate function body for IPA stop() function for thread #} {%- macro stop_thread_body() -%} - if (!running_) + ASSERT(state_ != Stopping); + if (state_ != Running) return; + state_ = Stopping; + proxy_.invokeMethod(&ThreadProxy::stop, ConnectionTypeBlocking); thread_.exit(); @@ -33,7 +36,7 @@ Thread::current()->dispatchMessages(Message::Type::InvokeMessage); - running_ = false; + state_ = Stopped; {%- endmacro -%}