[{"id":1433,"web_url":"https://patchwork.libcamera.org/comment/1433/","msgid":"<20190417110202.GF4993@pendragon.ideasonboard.com>","date":"2019-04-17T11:02:02","subject":"Re: [libcamera-devel] [RFC 09/11] libcamera: media_device: Add\n\tfunctions to lock device for other processes","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 Sun, Apr 14, 2019 at 03:35:04AM +0200, Niklas Söderlund wrote:\n> Add lock() and unlock() which backed by lockf() allows an instance of\n> libcamera to claim exclusive access to a media device. These functions\n> is the base to allow multiple users of libcamera to coexist in the\n> system without stepping on each others toes.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/include/media_device.h |  4 ++++\n>  src/libcamera/media_device.cpp       | 29 +++++++++++++++++++++++++++-\n>  2 files changed, 32 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\n> index 5d28a7bb8214ef4a..e2956549fa201ea3 100644\n> --- a/src/libcamera/include/media_device.h\n> +++ b/src/libcamera/include/media_device.h\n> @@ -64,6 +64,10 @@ private:\n>  \tbool acquire();\n>  \tvoid release();\n>  \n> +\tbool lockOwner_;\n> +\tbool lock();\n> +\tvoid unlock();\n> +\n\nWe usually put functions first, and variables next.\n\n>  \tstd::map<unsigned int, MediaObject *> objects_;\n>  \tMediaObject *object(unsigned int id);\n>  \tbool addObject(MediaObject *object);\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index 46931f52688f6c82..5cea4e63715125c8 100644\n> --- a/src/libcamera/media_device.cpp\n> +++ b/src/libcamera/media_device.cpp\n> @@ -62,7 +62,8 @@ LOG_DEFINE_CATEGORY(MediaDevice)\n>   * populate() before the media graph can be queried.\n>   */\n>  MediaDevice::MediaDevice(const std::string &deviceNode)\n> -\t: deviceNode_(deviceNode), fd_(-1), valid_(false), acquired_(false)\n> +\t: deviceNode_(deviceNode), fd_(-1), valid_(false), acquired_(false),\n> +\t  lockOwner_(false)\n>  {\n>  }\n>  \n> @@ -421,6 +422,32 @@ void MediaDevice::release()\n>  \tacquired_ = false;\n>  }\n>  \n> +bool MediaDevice::lock()\n\nCould you please document those two functions, and especially the pre\nand post conditions ?\n\n> +{\n> +\tif (fd_ == -1)\n> +\t\treturn false;\n> +\n> +\tif (lockOwner_)\n> +\t\treturn true;\n> +\n> +\tif (lockf(fd_, F_TLOCK, 0))\n> +\t\treturn false;\n> +\n> +\tlockOwner_ = true;\n> +\n> +\treturn true;\n> +}\n> +\n> +void MediaDevice::unlock()\n> +{\n> +\tif (fd_ == -1)\n> +\t\treturn;\n> +\n> +\tlockOwner_ = false;\n> +\n> +\tlockf(fd_, F_ULOCK, 0);\n> +}\n> +\n>  /**\n>   * \\var MediaDevice::objects_\n>   * \\brief Global map of media objects (entities, pads, links) keyed by their","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 1A3C760DBE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Apr 2019 13:02:12 +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 77E83312;\n\tWed, 17 Apr 2019 13:02:11 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1555498931;\n\tbh=72fWray0ZU15qfeYbNmiGl0U4S5XyFIWFv5WNqicDnM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=eUpLIPdzB8ufXkF5+0vypjTxOt4uOsm67IE6laebj0NWME+NRer2Xfxi84Pl77rlk\n\t77M20izC5UVZ8u6b1W7oZ1H0hDigRROATGBIbLLdPQ+2OGGsXNF+SX+PMiJH/eTkQb\n\tXNIHog0x25wLQTxwkRFOBS70hLqSPq5S5eI8C+m0=","Date":"Wed, 17 Apr 2019 14:02:02 +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":"<20190417110202.GF4993@pendragon.ideasonboard.com>","References":"<20190414013506.10515-1-niklas.soderlund@ragnatech.se>\n\t<20190414013506.10515-10-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":"<20190414013506.10515-10-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [RFC 09/11] libcamera: media_device: Add\n\tfunctions to lock device for other processes","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":"Wed, 17 Apr 2019 11:02:12 -0000"}}]