[{"id":2477,"web_url":"https://patchwork.libcamera.org/comment/2477/","msgid":"<20190819091612.ua6btmahqaazh5ra@uno.localdomain>","date":"2019-08-19T09:16:12","subject":"Re: [libcamera-devel] [PATCH 10/14] android: camera_hal_manager:\n\tStop thread when destroying","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Sun, Aug 18, 2019 at 04:13:25AM +0300, Laurent Pinchart wrote:\n> The CameraHalManager starts a thread that is never stopped. This leads\n> to the thread being destroyed while running, which causes a crash. Fix\n> this by stopping the thread and waiting for it to finish in the\n> destructor of the CameraHalManager.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/android/camera_hal_manager.cpp | 9 +++++++++\n>  src/android/camera_hal_manager.h   | 2 ++\n>  2 files changed, 11 insertions(+)\n>\n> diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp\n> index 37ba01355258..063080a0746b 100644\n> --- a/src/android/camera_hal_manager.cpp\n> +++ b/src/android/camera_hal_manager.cpp\n> @@ -28,6 +28,15 @@ LOG_DECLARE_CATEGORY(HAL);\n>   * their static information and to open and close camera devices.\n>   */\n>\n> +CameraHalManager::~CameraHalManager()\n> +{\n> +\tif (isRunning()) {\n> +\t\texit(0);\n\nTook me some time to realize this is not the c library exit()\nfunction\n\n> +\t\t/* \\todo Wait with a timeout, just in case. */\n\nDoesn't wait() removes the need for a timeout? Or is this to shorten\nthe waiting time?\n\nIn any case:\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n> +\t\twait();\n> +\t}\n> +}\n> +\n>  int CameraHalManager::init()\n>  {\n>  \t/*\n> diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h\n> index 8228623aba90..502115cf056f 100644\n> --- a/src/android/camera_hal_manager.h\n> +++ b/src/android/camera_hal_manager.h\n> @@ -24,6 +24,8 @@ class CameraProxy;\n>  class CameraHalManager : public libcamera::Thread\n>  {\n>  public:\n> +\t~CameraHalManager();\n> +\n>  \tint init();\n>\n>  \tCameraProxy *open(unsigned int id, const hw_module_t *module);\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":"<jacopo@jmondi.org>","Received":["from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F1E960E38\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 19 Aug 2019 11:14:44 +0200 (CEST)","from uno.localdomain (unknown [87.18.63.98])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 5A5FC4000F;\n\tMon, 19 Aug 2019 09:14:43 +0000 (UTC)"],"X-Originating-IP":"87.18.63.98","Date":"Mon, 19 Aug 2019 11:16:12 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190819091612.ua6btmahqaazh5ra@uno.localdomain>","References":"<20190818011329.14499-1-laurent.pinchart@ideasonboard.com>\n\t<20190818011329.14499-11-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"67ffudcezg4534yn\"","Content-Disposition":"inline","In-Reply-To":"<20190818011329.14499-11-laurent.pinchart@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 10/14] android: camera_hal_manager:\n\tStop thread when destroying","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":"Mon, 19 Aug 2019 09:14:44 -0000"}},{"id":2490,"web_url":"https://patchwork.libcamera.org/comment/2490/","msgid":"<20190819151439.GK5011@pendragon.ideasonboard.com>","date":"2019-08-19T15:14:39","subject":"Re: [libcamera-devel] [PATCH 10/14] android: camera_hal_manager:\n\tStop thread when destroying","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Mon, Aug 19, 2019 at 11:16:12AM +0200, Jacopo Mondi wrote:\n> On Sun, Aug 18, 2019 at 04:13:25AM +0300, Laurent Pinchart wrote:\n> > The CameraHalManager starts a thread that is never stopped. This leads\n> > to the thread being destroyed while running, which causes a crash. Fix\n> > this by stopping the thread and waiting for it to finish in the\n> > destructor of the CameraHalManager.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/android/camera_hal_manager.cpp | 9 +++++++++\n> >  src/android/camera_hal_manager.h   | 2 ++\n> >  2 files changed, 11 insertions(+)\n> >\n> > diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp\n> > index 37ba01355258..063080a0746b 100644\n> > --- a/src/android/camera_hal_manager.cpp\n> > +++ b/src/android/camera_hal_manager.cpp\n> > @@ -28,6 +28,15 @@ LOG_DECLARE_CATEGORY(HAL);\n> >   * their static information and to open and close camera devices.\n> >   */\n> >\n> > +CameraHalManager::~CameraHalManager()\n> > +{\n> > +\tif (isRunning()) {\n> > +\t\texit(0);\n> \n> Took me some time to realize this is not the c library exit()\n> function\n> \n> > +\t\t/* \\todo Wait with a timeout, just in case. */\n> \n> Doesn't wait() removes the need for a timeout? Or is this to shorten\n> the waiting time?\n\nIf the thread run() function never stops (which shouldn't happen, but\nbugs exist), wait() will wait forever. I think a timeout would be\nuseful.\n\n> In any case:\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> \n> > +\t\twait();\n> > +\t}\n> > +}\n> > +\n> >  int CameraHalManager::init()\n> >  {\n> >  \t/*\n> > diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h\n> > index 8228623aba90..502115cf056f 100644\n> > --- a/src/android/camera_hal_manager.h\n> > +++ b/src/android/camera_hal_manager.h\n> > @@ -24,6 +24,8 @@ class CameraProxy;\n> >  class CameraHalManager : public libcamera::Thread\n> >  {\n> >  public:\n> > +\t~CameraHalManager();\n> > +\n> >  \tint init();\n> >\n> >  \tCameraProxy *open(unsigned int id, const hw_module_t *module);","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 07B2060C1E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 19 Aug 2019 17:14:45 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 651C8510;\n\tMon, 19 Aug 2019 17:14:44 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1566227684;\n\tbh=0LFgcnh/YSOzFZxBHLGA7pqbo/M1O6nEgNxqL79mk5k=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=wY0IhUh8pM5J4DYiSa67uffDfVHHKWluTUiIwd3vIvVaMOI3qoPoSBdCgX6sG0TNM\n\tvRYAyi5r9JkzMzX+41+xCvocufv06FnhTtu1yknpui09JX04ZkjklCuZCD6K4M+w/b\n\tF0khESwTiNbp+/6bIkpmSue9HJRUDftHJiilObGY=","Date":"Mon, 19 Aug 2019 18:14:39 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190819151439.GK5011@pendragon.ideasonboard.com>","References":"<20190818011329.14499-1-laurent.pinchart@ideasonboard.com>\n\t<20190818011329.14499-11-laurent.pinchart@ideasonboard.com>\n\t<20190819091612.ua6btmahqaazh5ra@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190819091612.ua6btmahqaazh5ra@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 10/14] android: camera_hal_manager:\n\tStop thread when destroying","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":"Mon, 19 Aug 2019 15:14:45 -0000"}}]