From patchwork Mon Oct 28 10:49:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2279 Return-Path: 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 C58C46017E for ; Mon, 28 Oct 2019 11:49:26 +0100 (CET) Received: from pendragon.ideasonboard.com (unknown [91.217.168.176]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 79244325 for ; Mon, 28 Oct 2019 11:49:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1572259766; bh=QnAw0eeLXgkW37YTFFzpftiqmtMObRRfG6mrQNrpA2c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Dn04odB7ZbEwDepxlA6GcaaSJRrTtHyyUk2Lo19x/1eYllm5nxcoo3h5ZUCxgslE0 LpNAljXHuZ7S+plY+2x9aPTbDtSQ/EDMuX2Lmcdg2dOtrK2FPufMha755zp1/Y+BZD sSLJvuz7v+7jlsuxI4l/+gCGkGuvitiOYYhbs3tk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Oct 2019 12:49:10 +0200 Message-Id: <20191028104913.14985-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028104913.14985-1-laurent.pinchart@ideasonboard.com> References: <20191028104913.14985-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 6/9] libcamera: object: Use bound method activePack() for invokeMethod() 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: , X-List-Received-Date: Mon, 28 Oct 2019 10:49:28 -0000 The BoundMethodBase::activatePack() and the internal Object::invokeMethod() are duplicate implementation of the same mechanism. Use the former to replace the latter. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/bound_method.h | 4 ++-- include/libcamera/object.h | 8 ++++---- src/libcamera/bound_method.cpp | 6 +++--- src/libcamera/object.cpp | 7 ------- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h index 06c5a3b12305..bdeb5469cda3 100644 --- a/include/libcamera/bound_method.h +++ b/include/libcamera/bound_method.h @@ -37,7 +37,7 @@ public: Object *object() const { return object_; } ConnectionType connectionType() const { return connectionType_; } - void activatePack(void *pack); + void activatePack(void *pack, bool deleteMethod); virtual void invokePack(void *pack) = 0; protected: @@ -109,7 +109,7 @@ public: void activate(Args... args) { if (this->object_) - BoundMethodBase::activatePack(new PackType{ args... }); + BoundMethodBase::activatePack(new PackType{ args... }, false); else (static_cast(this->obj_)->*func_)(args...); } diff --git a/include/libcamera/object.h b/include/libcamera/object.h index 3308330af857..603a229288c2 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -33,10 +33,12 @@ public: void invokeMethod(void (T::*func)(Args...), Args... args) { T *obj = static_cast(this); - BoundMethodBase *method = new BoundMemberMethod(obj, this, func); + BoundMethodBase *method = + new BoundMemberMethod(obj, this, func, + ConnectionTypeQueued); void *pack = new typename BoundMemberMethod::PackType{ args... }; - invokeMethod(method, pack); + method->activatePack(pack, true); } Thread *thread() const { return thread_; } @@ -53,8 +55,6 @@ private: friend class BoundMethodBase; friend class Thread; - void invokeMethod(BoundMethodBase *method, void *pack); - void notifyThreadMove(); void connect(SignalBase *signal); diff --git a/src/libcamera/bound_method.cpp b/src/libcamera/bound_method.cpp index 600717363444..4c0cd415a3f1 100644 --- a/src/libcamera/bound_method.cpp +++ b/src/libcamera/bound_method.cpp @@ -48,7 +48,7 @@ namespace libcamera { * deadlock will occur. */ -void BoundMethodBase::activatePack(void *pack) +void BoundMethodBase::activatePack(void *pack, bool deleteMethod) { ConnectionType type = connectionType_; if (type == ConnectionTypeAuto) { @@ -66,7 +66,7 @@ void BoundMethodBase::activatePack(void *pack) case ConnectionTypeQueued: { std::unique_ptr msg = - utils::make_unique(this, pack); + utils::make_unique(this, pack, nullptr, deleteMethod); object_->postMessage(std::move(msg)); break; } @@ -75,7 +75,7 @@ void BoundMethodBase::activatePack(void *pack) Semaphore semaphore; std::unique_ptr msg = - utils::make_unique(this, pack, &semaphore); + utils::make_unique(this, pack, &semaphore, deleteMethod); object_->postMessage(std::move(msg)); semaphore.acquire(); diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp index b0818f9aa25f..509b2ebac537 100644 --- a/src/libcamera/object.cpp +++ b/src/libcamera/object.cpp @@ -153,13 +153,6 @@ void Object::message(Message *msg) * remains valid until the method is invoked. */ -void Object::invokeMethod(BoundMethodBase *method, void *args) -{ - std::unique_ptr msg = - utils::make_unique(method, args, nullptr, true); - postMessage(std::move(msg)); -} - /** * \fn Object::thread() * \brief Retrieve the thread the object is bound to