[{"id":1593,"web_url":"https://patchwork.libcamera.org/comment/1593/","msgid":"<20190511133737.GK4946@pendragon.ideasonboard.com>","date":"2019-05-11T13:37:37","subject":"Re: [libcamera-devel] [PATCH v3 11/11] libcamera: camera: Lock the\n\tpipeline handler in acquire()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Sat, May 11, 2019 at 11:19:07AM +0200, Niklas Söderlund wrote:\n> To allow more than one application using libcamera simultaneously there\n> can be no overlap between which cameras are in use by which user. As a\n> camera is part of a pipeline handler and there might be shared resources\n> between all cameras exposed by that pipeline handler it's not enough to\n> to only lock access to a single camera, all cameras from that pipeline\n> need to be tied to the same process.\n> \n> Allow for this by locking the whole pipeline when one of its cameras\n> is acquired by the user. Other processes can still enumerate and list\n> all cameras in the system but can't acquire a camera from a locked\n> pipeline handler.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/camera.cpp | 7 +++++++\n>  1 file changed, 7 insertions(+)\n> \n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index cb45bafe3fb1ff85..b7c9b80de409baf3 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -489,6 +489,11 @@ int Camera::acquire()\n\nYou should update the documentation of the acquire() and release()\nmethods.\n\n>  \tif (!stateIs(CameraAvailable))\n>  \t\treturn -EBUSY;\n>  \n> +\tif (!pipe_->lock()) {\n> +\t\tLOG(Camera, Info) << \"Pipeline handler in use by other process\";\n\ns/other/another/\n\n> +\t\treturn -EBUSY;\n> +\t}\n> +\n>  \tstate_ = CameraAcquired;\n>  \n>  \treturn 0;\n> @@ -510,6 +515,8 @@ int Camera::release()\n>  \tif (!stateBetween(CameraAvailable, CameraConfigured))\n>  \t\treturn -EBUSY;\n>  \n> +\tpipe_->unlock();\n> +\n>  \tstate_ = CameraAvailable;\n>  \n>  \treturn 0;","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B13F560E4F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 11 May 2019 15:37:53 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 458A8D5;\n\tSat, 11 May 2019 15:37:53 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1557581873;\n\tbh=n5Zv2CVfSo/4zRMq47PeDxcigOSsV21dBxnPfobYz88=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=OrYNv8Bobe+zMnhKXqg9RWlxd6yBIqVXt+3nhzQqucQuQlQ6xH8aGEcsPfjRNV7bh\n\tj0V1q191fZUVTOtmQ1EuMezJ+dR8/6VkkfpG+vpT+fkWaGKk3tdtarMrCxW1bZ5YUj\n\tvR0rAxorDseECZVmTPOyZVSiCj8aijs8oWdPMPEE=","Date":"Sat, 11 May 2019 16:37:37 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190511133737.GK4946@pendragon.ideasonboard.com>","References":"<20190511091907.10050-1-niklas.soderlund@ragnatech.se>\n\t<20190511091907.10050-12-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190511091907.10050-12-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 11/11] libcamera: camera: Lock the\n\tpipeline handler in acquire()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sat, 11 May 2019 13:37:53 -0000"}}]