From patchwork Mon Oct 28 10:49:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2274 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 D4FCC6017E for ; Mon, 28 Oct 2019 11:49:25 +0100 (CET) Received: from pendragon.ideasonboard.com (unknown [91.217.168.176]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7E0CE9C2 for ; Mon, 28 Oct 2019 11:49:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1572259765; bh=v/OpZsArzT+Zf/lqelVeH/VCkVhny0DLIylZF2B19zE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EARnHxndFQDPEtjrB9NFfZd+EGKZrcF9rgbKaOLqbhLxSOiYT1BB5DbqBskn2BJEn VFIPFIL8kQxTVQAs3aNldjeP3adb/fTzj4hANbMwxF6MywWdUKENAhC53rDY38Y6Je 0lnvL7WrpKqvk5go8jHF8VGa9CAV6iNaz4xOmdSg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Oct 2019 12:49:05 +0200 Message-Id: <20191028104913.14985-2-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 1/9] libcamera: Add Semaphore class 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:26 -0000 Add a general-purpose counting semaphore class. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/include/meson.build | 1 + src/libcamera/include/semaphore.h | 34 ++++++++++ src/libcamera/meson.build | 1 + src/libcamera/semaphore.cpp | 103 ++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 src/libcamera/include/semaphore.h create mode 100644 src/libcamera/semaphore.cpp diff --git a/src/libcamera/include/meson.build b/src/libcamera/include/meson.build index 2c74d29bd925..64c2155f90cf 100644 --- a/src/libcamera/include/meson.build +++ b/src/libcamera/include/meson.build @@ -17,6 +17,7 @@ libcamera_headers = files([ 'message.h', 'pipeline_handler.h', 'process.h', + 'semaphore.h', 'thread.h', 'utils.h', 'v4l2_controls.h', diff --git a/src/libcamera/include/semaphore.h b/src/libcamera/include/semaphore.h new file mode 100644 index 000000000000..c6b286536eb3 --- /dev/null +++ b/src/libcamera/include/semaphore.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * semaphore.h - General-purpose counting semaphore + */ +#ifndef __LIBCAMERA_SEMAPHORE_H__ +#define __LIBCAMERA_SEMAPHORE_H__ + +#include + +#include "thread.h" + +namespace libcamera { + +class Semaphore +{ +public: + Semaphore(unsigned int n = 0); + + unsigned int available(); + void acquire(unsigned int n = 1); + bool tryAcquire(unsigned int n = 1); + void release(unsigned int n = 1); + +private: + Mutex mutex_; + std::condition_variable cv_; + unsigned int available_; +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_SEMAPHORE_H__ */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index d329820b9582..dab5dbff77b7 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -27,6 +27,7 @@ libcamera_sources = files([ 'pipeline_handler.cpp', 'process.cpp', 'request.cpp', + 'semaphore.cpp', 'signal.cpp', 'stream.cpp', 'thread.cpp', diff --git a/src/libcamera/semaphore.cpp b/src/libcamera/semaphore.cpp new file mode 100644 index 000000000000..ce1eae4914ed --- /dev/null +++ b/src/libcamera/semaphore.cpp @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * semaphore.cpp - General-purpose counting semaphore + */ + +#include "semaphore.h" +#include "thread.h" + +/** + * \file semaphore.h + * \brief General-purpose counting semaphore + */ + +namespace libcamera { + +/** + * \class Semaphore + * \brief General-purpose counting semaphore + * + * A semaphore is a locking primitive that protects resources. It is created + * with an initial number of resources (which may be 0), and offers two + * primitives to acquire and release resources. The acquire() method tries to + * acquire a number of resources, and blocks if not enough resources are + * available until they get released. The release() method releases a number of + * resources, waking up any consumer blocked on an acquire() call. + */ + +/** + * \brief Construct a semaphore with \a n resources + * \param[in] n The resource count + */ +Semaphore::Semaphore(unsigned int n) + : available_(n) +{ +} + +/** + * \brief Retrieve the number of available resources + * \return The number of available resources + */ +unsigned int Semaphore::available() +{ + MutexLocker locker(mutex_); + return available_; +} + +/** + * \brief Acquire \a n resources + * \param[in] n The resource count + * + * This method attempts to acquire \a n resources. If \a n is higher than the + * number of available resources, the call will block until enough resources + * become available. + */ +void Semaphore::acquire(unsigned int n) +{ + MutexLocker locker(mutex_); + cv_.wait(locker, [&] { return available_ >= n; }); + available_ -= n; +} + +/** + * \brief Try to acquire \a n resources without blocking + * \param[in] n The resource count + * + * This method attempts to acquire \a n resources. If \a n is higher than the + * number of available resources, it returns false immediately without + * acquiring any resource. Otherwise it acquires the resources and returns + * true. + * + * \return True if the resources have been acquired, false otherwise + */ +bool Semaphore::tryAcquire(unsigned int n) +{ + MutexLocker locker(mutex_); + if (available_ < n) + return false; + + available_ -= n; + return true; +} + +/** + * \brief Release \a n resources + * \param[in] n The resource count + * + * This method releases \a n resources, increasing the available resource count + * by \a n. If the number of available resources becomes large enough for any + * consumer blocked on an acquire() call, those consumers get woken up. + */ +void Semaphore::release(unsigned int n) +{ + { + MutexLocker locker(mutex_); + available_ += n; + } + + cv_.notify_all(); +} + +} /* namespace libcamera */ From patchwork Mon Oct 28 10:49:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2275 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 0D3A760180 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 B0628325 for ; Mon, 28 Oct 2019 11:49:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1572259765; bh=bZ0U1F0cR4aWfYQjFJGt08aQHdMjbaUgrBZtrHOjRh4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TknU/cwt/GOHT40MaWaYuKFEPaZ9RuGU2UQO4VntN6nZ6NQG7nVjW9DrLjtGTQLCw hYO/VXPLN2LChVC7qNxfK1MeH7RS0+mjH5b8bW5YjEC0ycnMZjXMUp2+2+glH6DnC5 NM06wijv+J/mGF4xpRuC8BDIkFK+Vy9Q06vgqPNA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Oct 2019 12:49:06 +0200 Message-Id: <20191028104913.14985-3-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 2/9] libcamera: bound_method: Define connection type for method invocation 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:26 -0000 From: Jacopo Mondi Define an enumeration of connection types to describe the delivery method of signals and method invocation. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- Documentation/Doxyfile.in | 4 +--- include/libcamera/bound_method.h | 7 +++++++ src/libcamera/bound_method.cpp | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in index 5237cf60854f..24babfd8b366 100644 --- a/Documentation/Doxyfile.in +++ b/Documentation/Doxyfile.in @@ -837,9 +837,7 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = @TOP_SRCDIR@/include/libcamera/bound_method.h \ - @TOP_SRCDIR@/src/libcamera/bound_method.cpp \ - @TOP_SRCDIR@/src/libcamera/device_enumerator_sysfs.cpp \ +EXCLUDE = @TOP_SRCDIR@/src/libcamera/device_enumerator_sysfs.cpp \ @TOP_SRCDIR@/src/libcamera/device_enumerator_udev.cpp \ @TOP_SRCDIR@/src/libcamera/include/device_enumerator_sysfs.h \ @TOP_SRCDIR@/src/libcamera/include/device_enumerator_udev.h \ diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h index 8ebaadbec887..e1524c917e4b 100644 --- a/include/libcamera/bound_method.h +++ b/include/libcamera/bound_method.h @@ -14,6 +14,13 @@ namespace libcamera { class Object; +enum ConnectionType { + ConnectionTypeAuto, + ConnectionTypeDirect, + ConnectionTypeQueued, + ConnectionTypeBlocking, +}; + class BoundMethodBase { public: diff --git a/src/libcamera/bound_method.cpp b/src/libcamera/bound_method.cpp index d89f84c03f4d..ab6ecd9423d1 100644 --- a/src/libcamera/bound_method.cpp +++ b/src/libcamera/bound_method.cpp @@ -11,8 +11,42 @@ #include "thread.h" #include "utils.h" +/** + * \file bound_method.h + * \brief Method bind and invocation + */ + namespace libcamera { +/** + * \enum ConnectionType + * \brief Connection type for asynchronous communication + * + * This enumeration describes the possible types of asynchronous communication + * between a sender and a receiver. It applies to Signal::emit() and + * Object::invokeMethod(). + * + * \var ConnectionType::ConnectionTypeAuto + * \brief If the sender and the receiver live in the same thread, + * ConnectionTypeDirect is used. Otherwise ConnectionTypeQueued is used. + * + * \var ConnectionType::ConnectionTypeDirect + * \brief The receiver is invoked immediately and synchronously in the sender's + * thread. + * + * \var ConnectionType::ConnectionTypeQueued + * \brief The receiver is invoked asynchronously in its thread when control + * returns to the thread's event loop. The sender proceeds without waiting for + * the invocation to complete. + * + * \var ConnectionType::ConnectionTypeBlocking + * \brief The receiver is invoked asynchronously in its thread when control + * returns to the thread's event loop. The sender blocks until the receiver + * signals the completion of the invocation. This connection type shall not be + * used when the sender and receiver live in the same thread, otherwise + * deadlock will occur. + */ + void BoundMethodBase::activatePack(void *pack) { if (Thread::current() == object_->thread()) { From patchwork Mon Oct 28 10:49:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2276 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 31D226017E 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 DF000A4C for ; Mon, 28 Oct 2019 11:49:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1572259766; bh=GPxlhK6U01oMVH8OGNLeyCuixGsGDfei1PeXb8w4vFo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QzfrqDvj0MnB0OtAQFa7HAaDJIp4pQAq/P9D5ShVvQSLdgzy5JCDH0rnNqJJlzYG7 KmO5LQTb2I9gn8JW25PVY7w6YxyxW44LWhLMkwgrp+dU8nPMI1gtq3SV5PMKS1cGaN soJf1wANZhgiGSAx9SSMEb1w6Fzk4pJ4eAnk/wgk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Oct 2019 12:49:07 +0200 Message-Id: <20191028104913.14985-4-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 3/9] libcamera: bound_method: Store connection type in BoundMethodBase 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:26 -0000 Store the connection type in the base BoundMethodBase class to make it accessible to all bound methods. The default type is ConnectionTypeAuto. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/bound_method.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h index e1524c917e4b..06c5a3b12305 100644 --- a/include/libcamera/bound_method.h +++ b/include/libcamera/bound_method.h @@ -24,8 +24,10 @@ enum ConnectionType { class BoundMethodBase { public: - BoundMethodBase(void *obj, Object *object) - : obj_(obj), object_(object) {} + BoundMethodBase(void *obj, Object *object, ConnectionType type) + : obj_(obj), object_(object), connectionType_(type) + { + } virtual ~BoundMethodBase() {} template::value>::type * = nullptr> @@ -33,6 +35,7 @@ public: bool match(Object *object) { return object == object_; } Object *object() const { return object_; } + ConnectionType connectionType() const { return connectionType_; } void activatePack(void *pack); virtual void invokePack(void *pack) = 0; @@ -40,6 +43,7 @@ public: protected: void *obj_; Object *object_; + ConnectionType connectionType_; }; template @@ -76,8 +80,8 @@ private: } public: - BoundMethodArgs(void *obj, Object *object) - : BoundMethodBase(obj, object) {} + BoundMethodArgs(void *obj, Object *object, ConnectionType type) + : BoundMethodBase(obj, object, type) {} void invokePack(void *pack) override { @@ -94,8 +98,11 @@ class BoundMemberMethod : public BoundMethodArgs public: using PackType = std::tuple::type...>; - BoundMemberMethod(T *obj, Object *object, void (T::*func)(Args...)) - : BoundMethodArgs(obj, object), func_(func) {} + BoundMemberMethod(T *obj, Object *object, void (T::*func)(Args...), + ConnectionType type = ConnectionTypeAuto) + : BoundMethodArgs(obj, object, type), func_(func) + { + } bool match(void (T::*func)(Args...)) const { return func == func_; } @@ -121,7 +128,10 @@ class BoundStaticMethod : public BoundMethodArgs { public: BoundStaticMethod(void (*func)(Args...)) - : BoundMethodArgs(nullptr, nullptr), func_(func) {} + : BoundMethodArgs(nullptr, nullptr, ConnectionTypeAuto), + func_(func) + { + } bool match(void (*func)(Args...)) const { return func == func_; } From patchwork Mon Oct 28 10:49:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2277 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 646F260180 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 1E1D6325 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=xBRtcyjKiHUhrZ0qK3tIzDsBlecQZet6R3llMvEY5kY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=o9AdMbnFzXguC3hbW3AeN35XyEgO4YBBJDSHSgq0CdFYpZnlIOBWOd2RAKva+nOo+ SvmPbU94bsVpWBNbLZChejdQK5xEQnEcH0eMHMJwJS8Cledubm4U65e1I/VXe5ae3U G+T0rnzTpmwA2qqbsHAg/0PK0Wagvi+xiTKOe5y4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Oct 2019 12:49:08 +0200 Message-Id: <20191028104913.14985-5-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 4/9] libcamera: bound_method: Support connection types 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:27 -0000 Support all connection types in the BoundMethodBase::activePack() method. To support this, add a semaphore to the InvokeMessage to signal delivery. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/bound_method.cpp | 30 ++++++++++++++++++++++++++++-- src/libcamera/include/message.h | 5 +++++ src/libcamera/message.cpp | 11 +++++++++-- src/libcamera/object.cpp | 8 +++++++- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/libcamera/bound_method.cpp b/src/libcamera/bound_method.cpp index ab6ecd9423d1..600717363444 100644 --- a/src/libcamera/bound_method.cpp +++ b/src/libcamera/bound_method.cpp @@ -8,6 +8,7 @@ #include #include "message.h" +#include "semaphore.h" #include "thread.h" #include "utils.h" @@ -49,12 +50,37 @@ namespace libcamera { void BoundMethodBase::activatePack(void *pack) { - if (Thread::current() == object_->thread()) { + ConnectionType type = connectionType_; + if (type == ConnectionTypeAuto) { + if (Thread::current() == object_->thread()) + type = ConnectionTypeDirect; + else + type = ConnectionTypeQueued; + } + + switch (type) { + case ConnectionTypeDirect: + default: invokePack(pack); - } else { + break; + + case ConnectionTypeQueued: { std::unique_ptr msg = utils::make_unique(this, pack); object_->postMessage(std::move(msg)); + break; + } + + case ConnectionTypeBlocking: { + Semaphore semaphore; + + std::unique_ptr msg = + utils::make_unique(this, pack, &semaphore); + object_->postMessage(std::move(msg)); + + semaphore.acquire(); + break; + } } } diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h index 1cfde5669ede..311755cc60fe 100644 --- a/src/libcamera/include/message.h +++ b/src/libcamera/include/message.h @@ -15,6 +15,7 @@ namespace libcamera { class BoundMethodBase; class Object; +class Semaphore; class Thread; class Message @@ -48,14 +49,18 @@ class InvokeMessage : public Message { public: InvokeMessage(BoundMethodBase *method, void *pack, + Semaphore *semaphore = nullptr, bool deleteMethod = false); ~InvokeMessage(); + Semaphore *semaphore() const { return semaphore_; } + void invoke(); private: BoundMethodBase *method_; void *pack_; + Semaphore *semaphore_; bool deleteMethod_; }; diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp index efafb655c17e..daf653221077 100644 --- a/src/libcamera/message.cpp +++ b/src/libcamera/message.cpp @@ -119,13 +119,14 @@ Message::Type Message::registerMessageType() * \brief Construct an InvokeMessage for method invocation on an Object * \param[in] method The bound method * \param[in] pack The packed method arguments + * \param[in] semaphore The semaphore used to signal message delivery * \param[in] deleteMethod True to delete the \a method when the message is * destroyed */ InvokeMessage::InvokeMessage(BoundMethodBase *method, void *pack, - bool deleteMethod) + Semaphore *semaphore, bool deleteMethod) : Message(Message::InvokeMessage), method_(method), pack_(pack), - deleteMethod_(deleteMethod) + semaphore_(semaphore), deleteMethod_(deleteMethod) { } @@ -135,6 +136,12 @@ InvokeMessage::~InvokeMessage() delete method_; } +/** + * \fn InvokeMessage::semaphore() + * \brief Retrieve the message semaphore passed to the constructor + * \return The message semaphore + */ + /** * \brief Invoke the method bound to InvokeMessage::method_ with arguments * InvokeMessage::pack_ diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp index 98aa0af2f9b9..b0818f9aa25f 100644 --- a/src/libcamera/object.cpp +++ b/src/libcamera/object.cpp @@ -13,6 +13,7 @@ #include "log.h" #include "message.h" +#include "semaphore.h" #include "thread.h" #include "utils.h" @@ -123,7 +124,12 @@ void Object::message(Message *msg) switch (msg->type()) { case Message::InvokeMessage: { InvokeMessage *iMsg = static_cast(msg); + Semaphore *semaphore = iMsg->semaphore(); iMsg->invoke(); + + if (semaphore) + semaphore->release(); + break; } @@ -150,7 +156,7 @@ void Object::message(Message *msg) void Object::invokeMethod(BoundMethodBase *method, void *args) { std::unique_ptr msg = - utils::make_unique(method, args, true); + utils::make_unique(method, args, nullptr, true); postMessage(std::move(msg)); } From patchwork Mon Oct 28 10:49:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2278 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 96C3760C14 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 4C01B9C2 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=dhSMSoGff5nMEeAkkqC736uZ5lQgBGNG5b33Ev5fQC8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=e6FNA0zTSfFL/mf8014iZNNAf99Do8QzQqK5b8mO3RN/juz1BzSEHN/I1EslA+FnO IPRoxeCYVNcZj2HOUV+HjPRtJGLigVsZlJBctEuF2ocxeU8lobeqjvllJpR69+DEP4 HNlmmPMLQmHlP2/Uk5cxxIl17Z33W1YqWt+zZjOI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Oct 2019 12:49:09 +0200 Message-Id: <20191028104913.14985-6-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 5/9] libcamera: signal: Specify connection type for signals 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 Add a connection type parameter to the Signal::connect() method to control signal delivery. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/signal.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/libcamera/signal.h b/include/libcamera/signal.h index b8a60281cceb..57598335932c 100644 --- a/include/libcamera/signal.h +++ b/include/libcamera/signal.h @@ -55,11 +55,12 @@ public: #ifndef __DOXYGEN__ template::value>::type * = nullptr> - void connect(T *obj, void (T::*func)(Args...)) + void connect(T *obj, void (T::*func)(Args...), + ConnectionType type = ConnectionTypeAuto) { Object *object = static_cast(obj); object->connect(this); - slots_.push_back(new BoundMemberMethod(obj, object, func)); + slots_.push_back(new BoundMemberMethod(obj, object, func, type)); } template::value>::type * = nullptr> 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 From patchwork Mon Oct 28 10:49:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2280 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 ED76B6139C 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 A8F369C2 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=iVo/C52z3aQ/4H+6fm7BOXDR4iRuOX3VIw/M79icSuA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ksLxwzlFTosu1Nz+fYleRGjRxpxWnp0KFGjua23GiyqoUJjZ54PSFqOylmWFGW+hD uLnScqKDURkyi5Ej6j2bpu1VvUgQozRswpUVreZcSOSdMYw2LwQ1HC8N3hGGfToxLk E3EEG9W8axe30ripGNq12/mmoDfqOgxvDLgC1cvc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Oct 2019 12:49:11 +0200 Message-Id: <20191028104913.14985-8-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 7/9] libcamera: object: Add connection type parameter to 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 From: Jacopo Mondi Allow specifying a different connection type than ConnectionTypeQueued for Object::invokeMethod(). Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/object.h | 5 ++--- src/android/camera_proxy.cpp | 3 ++- src/libcamera/event_notifier.cpp | 3 ++- src/libcamera/object.cpp | 9 +++++---- src/libcamera/timer.cpp | 3 ++- test/object-invoke.cpp | 14 ++++++++------ 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/include/libcamera/object.h b/include/libcamera/object.h index 603a229288c2..91b56596c9db 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -30,12 +30,11 @@ public: void postMessage(std::unique_ptr msg); template::value>::type * = nullptr> - void invokeMethod(void (T::*func)(Args...), Args... args) + void invokeMethod(void (T::*func)(Args...), ConnectionType type, Args... args) { T *obj = static_cast(this); BoundMethodBase *method = - new BoundMemberMethod(obj, this, func, - ConnectionTypeQueued); + new BoundMemberMethod(obj, this, func, type); void *pack = new typename BoundMemberMethod::PackType{ args... }; method->activatePack(pack, true); diff --git a/src/android/camera_proxy.cpp b/src/android/camera_proxy.cpp index 4f5c0a024903..43e1e1c3af53 100644 --- a/src/android/camera_proxy.cpp +++ b/src/android/camera_proxy.cpp @@ -187,6 +187,7 @@ int CameraProxy::processCaptureRequest(camera3_capture_request_t *request) void CameraProxy::threadRpcCall(ThreadRpc &rpcRequest) { - cameraDevice_->invokeMethod(&CameraDevice::call, &rpcRequest); + cameraDevice_->invokeMethod(&CameraDevice::call, ConnectionTypeQueued, + &rpcRequest); rpcRequest.waitDelivery(); } diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/event_notifier.cpp index 687969b0a8d1..4326b0b413e2 100644 --- a/src/libcamera/event_notifier.cpp +++ b/src/libcamera/event_notifier.cpp @@ -128,7 +128,8 @@ void EventNotifier::message(Message *msg) if (msg->type() == Message::ThreadMoveMessage) { if (enabled_) { setEnabled(false); - invokeMethod(&EventNotifier::setEnabled, true); + invokeMethod(&EventNotifier::setEnabled, + ConnectionTypeQueued, true); } } diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp index 509b2ebac537..db2c6f68fbc8 100644 --- a/src/libcamera/object.cpp +++ b/src/libcamera/object.cpp @@ -139,14 +139,15 @@ void Object::message(Message *msg) } /** - * \fn void Object::invokeMethod(void (T::*func)(Args...), Args... args) + * \fn void Object::invokeMethod() * \brief Invoke a method asynchronously on an Object instance * \param[in] func The object method to invoke + * \param[in] type Connection type for method invocation * \param[in] args The method arguments * - * This method invokes the member method \a func when control returns to the - * event loop of the object's thread. The method is executed in the object's - * thread with arguments \a args. + * This method invokes the member method \a func with arguments \a args, based + * on the connection \a type. Depending on the type, the method will be called + * synchronously in the same thread or asynchronously in the object's thread. * * Arguments \a args passed by value or reference are copied, while pointers * are passed untouched. The caller shall ensure that any pointer argument diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp index ddb20954afa7..4c68883204e8 100644 --- a/src/libcamera/timer.cpp +++ b/src/libcamera/timer.cpp @@ -170,7 +170,8 @@ void Timer::message(Message *msg) if (msg->type() == Message::ThreadMoveMessage) { if (isRunning()) { unregisterTimer(); - invokeMethod(&Timer::registerTimer); + invokeMethod(&Timer::registerTimer, + ConnectionTypeQueued); } } diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp index 37a274402e6d..f6ae2604db76 100644 --- a/test/object-invoke.cpp +++ b/test/object-invoke.cpp @@ -64,10 +64,11 @@ protected: InvokedObject object; /* - * Test that method invocation in the same thread goes through - * the event dispatcher. + * Test that queued method invocation in the same thread goes + * through the event dispatcher. */ - object.invokeMethod(&InvokedObject::method, 42); + object.invokeMethod(&InvokedObject::method, + ConnectionTypeQueued, 42); if (object.status() != InvokedObject::NoCall) { cerr << "Method not invoked asynchronously" << endl; @@ -93,15 +94,16 @@ protected: } /* - * Move the object to a thread and verify that the method is - * delivered in the correct thread. + * Move the object to a thread and verify that auto method + * invocation is delivered in the correct thread. */ object.reset(); object.moveToThread(&thread_); thread_.start(); - object.invokeMethod(&InvokedObject::method, 42); + object.invokeMethod(&InvokedObject::method, + ConnectionTypeAuto, 42); this_thread::sleep_for(chrono::milliseconds(100)); switch (object.status()) { From patchwork Mon Oct 28 10:49:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2281 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 2F03161513 for ; Mon, 28 Oct 2019 11:49:27 +0100 (CET) Received: from pendragon.ideasonboard.com (unknown [91.217.168.176]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D8E49325 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=1572259767; bh=LHtBu+7U4FTmS3INOykeGAs9ueXc5uRI7GPWy1Vdmcc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iRHrjAMgAkxxFf4hrj1mjk6LldGFQgchxR0BIDTt5kl24itArYc9M+3uK0Z9nqROq N9yORpG4XAg/uNVCEE8mVCTXnOaacQOIh52j44GqnhUFKKtncsWO9xuOxV4MFrxZ9z Mqmxta3AXXRsscGcP8jiFackmFeenFXaBdrl/67g= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Oct 2019 12:49:12 +0200 Message-Id: <20191028104913.14985-9-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 8/9] test: object-invoke: Invoke method in blocking mode 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 From: Jacopo Mondi Change the object-invoke test to perform the second method invocation operation in blocking mode. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- test/object-invoke.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp index f6ae2604db76..6582fa75ae11 100644 --- a/test/object-invoke.cpp +++ b/test/object-invoke.cpp @@ -5,7 +5,6 @@ * object-invoke.cpp - Cross-thread Object method invocation test */ -#include #include #include @@ -103,8 +102,7 @@ protected: thread_.start(); object.invokeMethod(&InvokedObject::method, - ConnectionTypeAuto, 42); - this_thread::sleep_for(chrono::milliseconds(100)); + ConnectionTypeBlocking, 42); switch (object.status()) { case InvokedObject::NoCall: From patchwork Mon Oct 28 10:49:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2282 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5FFB761514 for ; Mon, 28 Oct 2019 11:49:27 +0100 (CET) Received: from pendragon.ideasonboard.com (unknown [91.217.168.176]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1A9E19C2 for ; Mon, 28 Oct 2019 11:49:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1572259767; bh=KJQRk/mfhn82QYmQ1g9EnP7fgiM5aHgDErpvFKsmWPE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jEIJ4wSYMmb28pRZ1SgYebMl02Wx/goqPVYqaKr7awbBAVshmHM7HU1qHG0c6KwtT 9SBxnZvN00Zsw3az9Xa69lUZHUD0dN+EWeZCucZkV47W9d2jySEBckFcsRTTlXLGpl eE+YiHhYeALtyx9tTXh8lgV8xGIk+JTxBleHGMug= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Oct 2019 12:49:13 +0200 Message-Id: <20191028104913.14985-10-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 9/9] android: Replace ThreadRPC with blocking method call 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 From: Jacopo Mondi Use the newly introduced InvocationTypeBlocking message type to replace the blocking message delivery implemented with the ThreadRPC class in the Android camera HAL. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/android/camera_device.cpp | 34 ++++++------------------------ src/android/camera_device.h | 5 +---- src/android/camera_proxy.cpp | 21 ++++--------------- src/android/camera_proxy.h | 3 --- src/android/meson.build | 1 - src/android/thread_rpc.cpp | 26 ----------------------- src/android/thread_rpc.h | 39 ----------------------------------- 7 files changed, 11 insertions(+), 118 deletions(-) delete mode 100644 src/android/thread_rpc.cpp delete mode 100644 src/android/thread_rpc.h diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index c7c9b3fd1724..897f545864a9 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -11,7 +11,6 @@ #include "utils.h" #include "camera_metadata.h" -#include "thread_rpc.h" using namespace libcamera; @@ -64,25 +63,6 @@ CameraDevice::~CameraDevice() delete it.second; } -/* - * Handle RPC request received from the associated proxy. - */ -void CameraDevice::call(ThreadRpc *rpc) -{ - switch (rpc->tag) { - case ThreadRpc::ProcessCaptureRequest: - processCaptureRequest(rpc->request); - break; - case ThreadRpc::Close: - close(); - break; - default: - LOG(HAL, Error) << "Unknown RPC operation: " << rpc->tag; - } - - rpc->notifyReception(); -} - int CameraDevice::open() { int ret = camera_->acquire(); @@ -698,7 +678,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return 0; } -int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) +void CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) { StreamConfiguration *streamConfiguration = &config_->at(0); Stream *stream = streamConfiguration->stream(); @@ -706,7 +686,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques if (camera3Request->num_output_buffers != 1) { LOG(HAL, Error) << "Invalid number of output buffers: " << camera3Request->num_output_buffers; - return -EINVAL; + return; } /* Start the camera if that's the first request we handle. */ @@ -714,14 +694,14 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques int ret = camera_->allocateBuffers(); if (ret) { LOG(HAL, Error) << "Failed to allocate buffers"; - return ret; + return; } ret = camera_->start(); if (ret) { LOG(HAL, Error) << "Failed to start camera"; camera_->freeBuffers(); - return ret; + return; } running_ = true; @@ -769,7 +749,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques if (!buffer) { LOG(HAL, Error) << "Failed to create buffer"; delete descriptor; - return -EINVAL; + return; } Request *request = @@ -782,13 +762,11 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques goto error; } - return 0; + return; error: delete request; delete descriptor; - - return ret; } void CameraDevice::requestComplete(Request *request, diff --git a/src/android/camera_device.h b/src/android/camera_device.h index d5d136a74f4a..2105b5b9a1e7 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -20,7 +20,6 @@ #include "message.h" class CameraMetadata; -class ThreadRpc; class CameraDevice : public libcamera::Object { @@ -28,15 +27,13 @@ public: CameraDevice(unsigned int id, const std::shared_ptr &camera); ~CameraDevice(); - void call(ThreadRpc *rpc); - int open(); void close(); void setCallbacks(const camera3_callback_ops_t *callbacks); camera_metadata_t *getStaticMetadata(); const camera_metadata_t *constructDefaultRequestSettings(int type); int configureStreams(camera3_stream_configuration_t *stream_list); - int processCaptureRequest(camera3_capture_request_t *request); + void processCaptureRequest(camera3_capture_request_t *request); void requestComplete(libcamera::Request *request, const std::map &buffers); diff --git a/src/android/camera_proxy.cpp b/src/android/camera_proxy.cpp index 43e1e1c3af53..3964b5665e2f 100644 --- a/src/android/camera_proxy.cpp +++ b/src/android/camera_proxy.cpp @@ -16,7 +16,6 @@ #include "utils.h" #include "camera_device.h" -#include "thread_rpc.h" using namespace libcamera; @@ -148,10 +147,8 @@ int CameraProxy::open(const hw_module_t *hardwareModule) void CameraProxy::close() { - ThreadRpc rpcRequest; - rpcRequest.tag = ThreadRpc::Close; - - threadRpcCall(rpcRequest); + cameraDevice_->invokeMethod(&CameraDevice::close, + ConnectionTypeBlocking); } void CameraProxy::initialize(const camera3_callback_ops_t *callbacks) @@ -176,18 +173,8 @@ int CameraProxy::configureStreams(camera3_stream_configuration_t *stream_list) int CameraProxy::processCaptureRequest(camera3_capture_request_t *request) { - ThreadRpc rpcRequest; - rpcRequest.tag = ThreadRpc::ProcessCaptureRequest; - rpcRequest.request = request; - - threadRpcCall(rpcRequest); + cameraDevice_->invokeMethod(&CameraDevice::processCaptureRequest, + ConnectionTypeBlocking, request); return 0; } - -void CameraProxy::threadRpcCall(ThreadRpc &rpcRequest) -{ - cameraDevice_->invokeMethod(&CameraDevice::call, ConnectionTypeQueued, - &rpcRequest); - rpcRequest.waitDelivery(); -} diff --git a/src/android/camera_proxy.h b/src/android/camera_proxy.h index 7940eac4e376..e8cfbc9dd526 100644 --- a/src/android/camera_proxy.h +++ b/src/android/camera_proxy.h @@ -14,7 +14,6 @@ #include class CameraDevice; -class ThreadRpc; class CameraProxy { @@ -35,8 +34,6 @@ public: camera3_device_t *camera3Device() { return &camera3Device_; } private: - void threadRpcCall(ThreadRpc &rpcRequest); - unsigned int id_; CameraDevice *cameraDevice_; camera3_device_t camera3Device_; diff --git a/src/android/meson.build b/src/android/meson.build index b5e4eeeb73a8..70dfcc1df27a 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -4,7 +4,6 @@ android_hal_sources = files([ 'camera_device.cpp', 'camera_metadata.cpp', 'camera_proxy.cpp', - 'thread_rpc.cpp' ]) android_camera_metadata_sources = files([ diff --git a/src/android/thread_rpc.cpp b/src/android/thread_rpc.cpp deleted file mode 100644 index f57891ff56bf..000000000000 --- a/src/android/thread_rpc.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * thread_rpc.cpp - Inter-thread procedure call - */ - -#include "thread.h" -#include "thread_rpc.h" - -using namespace libcamera; - -void ThreadRpc::notifyReception() -{ - { - libcamera::MutexLocker locker(mutex_); - delivered_ = true; - } - cv_.notify_one(); -} - -void ThreadRpc::waitDelivery() -{ - libcamera::MutexLocker locker(mutex_); - cv_.wait(locker, [&] { return delivered_; }); -} diff --git a/src/android/thread_rpc.h b/src/android/thread_rpc.h deleted file mode 100644 index f577a5d9fb32..000000000000 --- a/src/android/thread_rpc.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * thread_rpc.h - Inter-thread procedure call - */ -#ifndef __ANDROID_THREAD_RPC_H__ -#define __ANDROID_THREAD_RPC_H__ - -#include -#include - -#include - -class ThreadRpc -{ -public: - enum RpcTag { - ProcessCaptureRequest, - Close, - }; - - ThreadRpc() - : delivered_(false) {} - - void notifyReception(); - void waitDelivery(); - - RpcTag tag; - - camera3_capture_request_t *request; - -private: - bool delivered_; - std::mutex mutex_; - std::condition_variable cv_; -}; - -#endif /* __ANDROID_THREAD_RPC_H__ */