From patchwork Tue Feb 12 22:20:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 554 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE68F60B21 for ; Tue, 12 Feb 2019 23:20:07 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 344BD100002; Tue, 12 Feb 2019 22:20:06 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 12 Feb 2019 23:20:18 +0100 Message-Id: <20190212222021.28517-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212222021.28517-1-jacopo@jmondi.org> References: <20190212222021.28517-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] libcamera: v4l2_subdevice: Forward-declare MediaEntity X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2019 22:20:08 -0000 The V4L2Subdevice class uses MediaEntity instances, and the corresponding header is not included. Fix this by forward declaring the MediaEntity class. Fixes: 468176fa07d9 ("libcamera: Add V4L2Subdevice") Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/include/v4l2_subdevice.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index 8fd666078985..ffa92100ffbc 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -12,6 +12,7 @@ namespace libcamera { struct Rectangle; +class MediaEntity; struct V4L2SubdeviceFormat { uint32_t mbus_code; From patchwork Tue Feb 12 22:20:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 555 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F0E360B21 for ; Tue, 12 Feb 2019 23:20:09 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 4BA1D100002; Tue, 12 Feb 2019 22:20:08 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 12 Feb 2019 23:20:19 +0100 Message-Id: <20190212222021.28517-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212222021.28517-1-jacopo@jmondi.org> References: <20190212222021.28517-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] libcamera: device_enumerator: Break line longer than 80 columns X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2019 22:20:09 -0000 Since there is no valid reason to exceed 80 columns for this lane, break it. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/device_enumerator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index 703b03dd418a..03923b3bb457 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -234,7 +234,8 @@ int DeviceEnumerator::addDevice(const std::string &deviceNode) if (entity->deviceMajor() == 0 && entity->deviceMinor() == 0) continue; - std::string deviceNode = lookupDeviceNode(entity->deviceMajor(), entity->deviceMinor()); + std::string deviceNode = lookupDeviceNode(entity->deviceMajor(), + entity->deviceMinor()); if (deviceNode.empty()) return -EINVAL; From patchwork Tue Feb 12 22:20:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 556 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3882860B21 for ; Tue, 12 Feb 2019 23:20:10 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 61A4D100002; Tue, 12 Feb 2019 22:20:09 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 12 Feb 2019 23:20:20 +0100 Message-Id: <20190212222021.28517-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212222021.28517-1-jacopo@jmondi.org> References: <20190212222021.28517-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] libcamera: device_enumerator: Remove move() on search() return X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2019 22:20:10 -0000 Remove the std::move() call on the shared_ptr returned by the search() method and remove the std::move() call on temporary return value in pipeline handlers that use the method. Thanks to copy elision, the regular constructor of the newly created object is called, avoiding un-necessary copies. Furthermore, the use of std::move() in the return and assignment statements prevents the compiler from performing copy elision, forcing it to generate two sequences of un-necessary calls to the class' move constructor and destructor. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/device_enumerator.cpp | 2 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++-- src/libcamera/pipeline/uvcvideo.cpp | 2 +- src/libcamera/pipeline/vimc.cpp | 2 +- test/v4l2_device/v4l2_device_test.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index 03923b3bb457..7db40812906b 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -308,7 +308,7 @@ std::shared_ptr DeviceEnumerator::search(const DeviceMatch &dm) LOG(DeviceEnumerator, Debug) << "Successful match for media device \"" << media->driver() << "\""; - return std::move(media); + return media; } } diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 34b03995ae31..f11e9cc61283 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -279,11 +279,11 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator) imgu_dm.add("ipu3-imgu 1 viewfinder"); imgu_dm.add("ipu3-imgu 1 3a stat"); - cio2_ = std::move(enumerator->search(cio2_dm)); + cio2_ = enumerator->search(cio2_dm); if (!cio2_) return false; - imgu_ = std::move(enumerator->search(imgu_dm)); + imgu_ = enumerator->search(imgu_dm); if (!imgu_) return false; diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index fc31c52c0ecd..bf0d2fee3851 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -139,7 +139,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) { DeviceMatch dm("uvcvideo"); - media_ = std::move(enumerator->search(dm)); + media_ = enumerator->search(dm); if (!media_) return false; diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index 46840a4f4104..3aed24c3158a 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -148,7 +148,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) dm.add("RGB/YUV Input"); dm.add("Scaler"); - media_ = std::move(enumerator->search(dm)); + media_ = enumerator->search(dm); if (!media_) return false; diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp index 18d014caf4c8..76f2e55d8cb4 100644 --- a/test/v4l2_device/v4l2_device_test.cpp +++ b/test/v4l2_device/v4l2_device_test.cpp @@ -40,7 +40,7 @@ int V4L2DeviceTest::init() } DeviceMatch dm("uvcvideo"); - media_ = std::move(enumerator_->search(dm)); + media_ = enumerator_->search(dm); if (!media_) return TestSkip; From patchwork Tue Feb 12 22:20:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 557 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 91515610BB for ; Tue, 12 Feb 2019 23:20:11 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 85C35100002; Tue, 12 Feb 2019 22:20:10 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 12 Feb 2019 23:20:21 +0100 Message-Id: <20190212222021.28517-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212222021.28517-1-jacopo@jmondi.org> References: <20190212222021.28517-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] Documentation: coding-style: Discourage move on shared_ptr<> X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2019 22:20:11 -0000 Using std::move() on return statement of a method or on the its returned value prevents the compiler from implementing copy-elision. Discourage that in the coding style document. Signed-off-by: Laurent Pinchart Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- Documentation/coding-style.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst index 51afef27e9c1..065fbe0ab07b 100644 --- a/Documentation/coding-style.rst +++ b/Documentation/coding-style.rst @@ -151,6 +151,10 @@ reference for the duration of the operation that borrows it. never by reference. The caller can decide whether to transfer its ownership of the std::shared_ptr<> with std::move() or retain it. The callee shall use std::move() if it needs to store the shared pointer. + * Do not over-use std::move(), as it may prevent copy-elision. In particular + a function returning a std::shared_ptr<> value shall not use std::move() in + its return statements, and its callers shall not wrap the function call + with std::move(). * Borrowed references to shared objects are passed as references to the objects themselves, not to the std::shared_ptr<>, with the same rules as for single owner objects.