[{"id":3579,"web_url":"https://patchwork.libcamera.org/comment/3579/","msgid":"<20200122163719.GY1124294@oden.dyn.berto.se>","date":"2020-01-22T16:37:19","subject":"Re: [libcamera-devel] [PATCH 17/19] libcamera: pipeline_handler:\n\tImplement the threading model","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2020-01-20 02:24:35 +0200, Laurent Pinchart wrote:\n> Document the threading model of the PipelineHandler class (and all its\n> derived classes). The model is already enforced by the Camera class, so\n> not much is required. As for the Camera class, disconnection is\n> currently left out.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\ns/Implement/Document/ in the patch subject, whit this fixed,\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/pipeline_handler.cpp | 36 ++++++++++++++++++++++++++++++\n>  1 file changed, 36 insertions(+)\n> \n> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\n> index 3091971d5da0..2ebf73b76e6b 100644\n> --- a/src/libcamera/pipeline_handler.cpp\n> +++ b/src/libcamera/pipeline_handler.cpp\n> @@ -166,6 +166,8 @@ PipelineHandler::~PipelineHandler()\n>   * If this function returns true, a new instance of the pipeline handler will\n>   * be created and its match() function called.\n>   *\n> + * \\context This function is called from the CameraManager thread.\n> + *\n>   * \\return true if media devices have been acquired and camera instances\n>   * created, or false otherwise\n>   */\n> @@ -182,6 +184,8 @@ PipelineHandler::~PipelineHandler()\n>   * device explicitly, it will be automatically released when the pipeline\n>   * handler is destroyed.\n>   *\n> + * \\context This function shall be called from the CameraManager thread.\n> + *\n>   * \\return A pointer to the matching MediaDevice, or nullptr if no match is found\n>   */\n>  MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,\n> @@ -205,6 +209,8 @@ MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,\n>   * This method shall not be called from pipeline handler implementation, as the\n>   * Camera class handles locking directly.\n>   *\n> + * \\context This function is \\threadsafe.\n> + *\n>   * \\return True if the devices could be locked, false otherwise\n>   * \\sa unlock()\n>   * \\sa MediaDevice::lock()\n> @@ -227,6 +233,8 @@ bool PipelineHandler::lock()\n>   * This method shall not be called from pipeline handler implementation, as the\n>   * Camera class handles locking directly.\n>   *\n> + * \\context This function is \\threadsafe.\n> + *\n>   * \\sa lock()\n>   */\n>  void PipelineHandler::unlock()\n> @@ -238,6 +246,7 @@ void PipelineHandler::unlock()\n>  /**\n>   * \\brief Retrieve the list of controls for a camera\n>   * \\param[in] camera The camera\n> + * \\context This function is \\threadsafe.\n>   * \\return A ControlInfoMap listing the controls support by \\a camera\n>   */\n>  const ControlInfoMap &PipelineHandler::controls(Camera *camera)\n> @@ -261,6 +270,10 @@ const ControlInfoMap &PipelineHandler::controls(Camera *camera)\n>   * The intended companion to this is \\a configure() which can be used to change\n>   * the group of streams parameters.\n>   *\n> + * \\context This function may be called from any thread and shall be\n> + * \\threadsafe. It shall not modify the state of the \\a camera in the pipeline\n> + * handler.\n> + *\n>   * \\return A valid CameraConfiguration if the requested roles can be satisfied,\n>   * or a null pointer otherwise. The ownership of the returned configuration is\n>   * passed to the caller.\n> @@ -286,6 +299,8 @@ const ControlInfoMap &PipelineHandler::controls(Camera *camera)\n>   * instance to each StreamConfiguration entry in the CameraConfiguration using\n>   * the StreamConfiguration::setStream() method.\n>   *\n> + * \\context This function is called from the CameraManager thread.\n> + *\n>   * \\return 0 on success or a negative error code otherwise\n>   */\n>  \n> @@ -316,6 +331,8 @@ const ControlInfoMap &PipelineHandler::controls(Camera *camera)\n>   *\n>   * The only intended caller is Camera::exportFrameBuffers().\n>   *\n> + * \\context This function is called from the CameraManager thread.\n> + *\n>   * \\return 0 on success or a negative error code otherwise\n>   */\n>  \n> @@ -343,6 +360,8 @@ const ControlInfoMap &PipelineHandler::controls(Camera *camera)\n>   *\n>   * The only intended caller is Camera::start().\n>   *\n> + * \\context This function is called from the CameraManager thread.\n> + *\n>   * \\return 0 on success or a negative error code otherwise\n>   */\n>  \n> @@ -358,6 +377,8 @@ const ControlInfoMap &PipelineHandler::controls(Camera *camera)\n>   * once per stream.\n>   *\n>   * The only intended callers are Camera::stop() and Camera::freeFrameBuffers().\n> + *\n> + * \\context This function is called from the CameraManager thread.\n>   */\n>  \n>  /**\n> @@ -370,6 +391,8 @@ const ControlInfoMap &PipelineHandler::controls(Camera *camera)\n>   * will in turn be called from the application to indicate that it has\n>   * configured the streams and is ready to capture.\n>   *\n> + * \\context This function is called from the CameraManager thread.\n> + *\n>   * \\return 0 on success or a negative error code otherwise\n>   */\n>  \n> @@ -380,6 +403,8 @@ const ControlInfoMap &PipelineHandler::controls(Camera *camera)\n>   *\n>   * This method stops capturing and processing requests immediately. All pending\n>   * requests are cancelled and complete immediately in an error state.\n> + *\n> + * \\context This function is called from the CameraManager thread.\n>   */\n>  \n>  /**\n> @@ -396,6 +421,8 @@ const ControlInfoMap &PipelineHandler::controls(Camera *camera)\n>   * when the pipeline handler is stopped with stop(). Request completion shall be\n>   * signalled by the pipeline handler using the completeRequest() method.\n>   *\n> + * \\context This function is called from the CameraManager thread.\n> + *\n>   * \\return 0 on success or a negative error code otherwise\n>   */\n>  int PipelineHandler::queueRequest(Camera *camera, Request *request)\n> @@ -422,6 +449,8 @@ int PipelineHandler::queueRequest(Camera *camera, Request *request)\n>   * parameters will be applied to the frames captured in the buffers provided in\n>   * the request.\n>   *\n> + * \\context This function is called from the CameraManager thread.\n> + *\n>   * \\return 0 on success or a negative error code otherwise\n>   */\n>  \n> @@ -438,6 +467,8 @@ int PipelineHandler::queueRequest(Camera *camera, Request *request)\n>   * pipeline handlers a chance to perform any operation that may still be\n>   * needed. They shall complete requests explicitly with completeRequest().\n>   *\n> + * \\context This function shall be called from the CameraManager thread.\n> + *\n>   * \\return True if all buffers contained in the request have completed, false\n>   * otherwise\n>   */\n> @@ -460,6 +491,8 @@ bool PipelineHandler::completeBuffer(Camera *camera, Request *request,\n>   * This method ensures that requests will be returned to the application in\n>   * submission order, the pipeline handler may call it on any complete request\n>   * without any ordering constraint.\n> + *\n> + * \\context This function shall be called from the CameraManager thread.\n>   */\n>  void PipelineHandler::completeRequest(Camera *camera, Request *request)\n>  {\n> @@ -493,6 +526,8 @@ void PipelineHandler::completeRequest(Camera *camera, Request *request)\n>   * is to be associated with. This is for the V4L2 compatibility layer to map\n>   * device nodes to Camera instances based on the device number\n>   * registered by this method in \\a devnum.\n> + *\n> + * \\context This function shall be called from the CameraManager thread.\n>   */\n>  void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera,\n>  \t\t\t\t     std::unique_ptr<CameraData> data,\n> @@ -586,6 +621,7 @@ CameraData *PipelineHandler::cameraData(const Camera *camera)\n>  /**\n>   * \\fn PipelineHandler::name()\n>   * \\brief Retrieve the pipeline handler name\n> + * \\context This function shall be \\threadsafe.\n>   * \\return The pipeline handler name\n>   */\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x142.google.com (mail-lf1-x142.google.com\n\t[IPv6:2a00:1450:4864:20::142])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 092A060804\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jan 2020 17:37:21 +0100 (CET)","by mail-lf1-x142.google.com with SMTP id i23so93557lfo.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jan 2020 08:37:21 -0800 (PST)","from localhost (h-93-159.A463.priv.bahnhof.se. [46.59.93.159])\n\tby smtp.gmail.com with ESMTPSA id\n\tq13sm24428663ljj.63.2020.01.22.08.37.19\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 22 Jan 2020 08:37:19 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=XNxQx9Qktg5qN0Cm57rW+/leWfcw9QZ/M+IudGferOs=;\n\tb=hVsZMTihb92dWt7FAjNrwnkGOhYEso+6zzIlbb6f9/5ZlbM35x2Rw9l4AJ5FA+g/8s\n\tukvzQzt2eYlbiiAj+BOLhpZ48SD9x3VB0I9wRN6UCw9AcT5pnH/ae3fXviiHAIvTxJKE\n\t3hg+sBwMItheGjMB0VdekZlnRC2rIcbKB57AvpmdbmBdls1/dHo2WtrVZAVjjxVcknvN\n\tDG3X3oN0u4v/fj8UJQKPnOiImq8f2Wcjp8YWrbi1A7bIY0RzwMJmLCUp+WYDsn8RPZk1\n\tfx4SwikWScApbpV3KLGmEsJEqW9POSypGROWDceWfetVCV1qQet8hkkkZFEFo70zFD0Y\n\t4x4A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=XNxQx9Qktg5qN0Cm57rW+/leWfcw9QZ/M+IudGferOs=;\n\tb=p4jNElE+/s1AkN/FVaod2Kg+fWrrRAMlaVgfFf6AsWf3lZ3zwcfURS+Av2YkefLBfp\n\tRflbFh2DYWC54VP13kma4GQca31I7EHN0kqF3WHqqtoznvR6BPmeIE6RLWdEdOFxgvPP\n\t5nkQlEPtWm32bgBmeGRMT6CMgpVuD3BfFUHRCjZn5ntOZi54P6+TeK3hUbi+aHQazub9\n\t4DxcYqNr2k2rw0NhAU/KdR+g9M6dEfUBwdWXJOLPUSp0jYmpQ++oSI1uGhs8GMtSnuX3\n\tOIarltlu4HqJEzhQ1px+3jjAy2qiXT3qenvLES8IcwmcjUT/99pn9uqEVbCG2nrLWcsi\n\tFwmA==","X-Gm-Message-State":"APjAAAXclbb7lsjk4uIDx0eUhYedAwS/6wPzcs2unG1HrTKkRiUi8uDE\n\tJBtpXHVTChmj6s8FCG0bG/sywg==","X-Google-Smtp-Source":"APXvYqwm20SNxqEvwPUxsfZoM4tRLaZumsjuUbmrPMOOc28+CA+goWKf9+fJzyHDhD9p38i/gAtNdA==","X-Received":"by 2002:a05:6512:15d:: with SMTP id\n\tm29mr2308937lfo.51.1579711040364; \n\tWed, 22 Jan 2020 08:37:20 -0800 (PST)","Date":"Wed, 22 Jan 2020 17:37:19 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200122163719.GY1124294@oden.dyn.berto.se>","References":"<20200120002437.6633-1-laurent.pinchart@ideasonboard.com>\n\t<20200120002437.6633-18-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200120002437.6633-18-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 17/19] libcamera: pipeline_handler:\n\tImplement the threading model","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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, 22 Jan 2020 16:37:21 -0000"}}]