[libcamera-devel,v2,03/13] libcamera: camera_manager: Return a copy of the vector from cameras()

Message ID 20200122205723.8865-4-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Initial libcamera threading model
Related show

Commit Message

Laurent Pinchart Jan. 22, 2020, 8:57 p.m. UTC
Making CameraManager::cameras() thread-safe requires returning a copy of
the cameras vector instead of a reference. This is also required for
hot-plugging support and is thus desirable.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/camera_manager.h | 2 +-
 src/libcamera/camera_manager.cpp   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Niklas Söderlund Jan. 23, 2020, 8:22 p.m. UTC | #1
Hi Laurent,

Thanks for your work.

On 2020-01-22 22:57:13 +0200, Laurent Pinchart wrote:
> Making CameraManager::cameras() thread-safe requires returning a copy of
> the cameras vector instead of a reference. This is also required for
> hot-plugging support and is thus desirable.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  include/libcamera/camera_manager.h | 2 +-
>  src/libcamera/camera_manager.cpp   | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h
> index 068afd58762f..079f848aec79 100644
> --- a/include/libcamera/camera_manager.h
> +++ b/include/libcamera/camera_manager.h
> @@ -30,7 +30,7 @@ public:
>  	int start();
>  	void stop();
>  
> -	const std::vector<std::shared_ptr<Camera>> &cameras() const;
> +	std::vector<std::shared_ptr<Camera>> cameras() const;
>  	std::shared_ptr<Camera> get(const std::string &name);
>  	std::shared_ptr<Camera> get(dev_t devnum);
>  
> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
> index e0a07ec557d3..5fc1bba974c6 100644
> --- a/src/libcamera/camera_manager.cpp
> +++ b/src/libcamera/camera_manager.cpp
> @@ -244,7 +244,7 @@ void CameraManager::stop()
>   *
>   * \return List of all available cameras
>   */
> -const std::vector<std::shared_ptr<Camera>> &CameraManager::cameras() const
> +std::vector<std::shared_ptr<Camera>> CameraManager::cameras() const
>  {
>  	return p_->cameras_;
>  }
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h
index 068afd58762f..079f848aec79 100644
--- a/include/libcamera/camera_manager.h
+++ b/include/libcamera/camera_manager.h
@@ -30,7 +30,7 @@  public:
 	int start();
 	void stop();
 
-	const std::vector<std::shared_ptr<Camera>> &cameras() const;
+	std::vector<std::shared_ptr<Camera>> cameras() const;
 	std::shared_ptr<Camera> get(const std::string &name);
 	std::shared_ptr<Camera> get(dev_t devnum);
 
diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
index e0a07ec557d3..5fc1bba974c6 100644
--- a/src/libcamera/camera_manager.cpp
+++ b/src/libcamera/camera_manager.cpp
@@ -244,7 +244,7 @@  void CameraManager::stop()
  *
  * \return List of all available cameras
  */
-const std::vector<std::shared_ptr<Camera>> &CameraManager::cameras() const
+std::vector<std::shared_ptr<Camera>> CameraManager::cameras() const
 {
 	return p_->cameras_;
 }