From patchwork Fri Jul 31 10:53:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9084 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9C8E5BD86F for ; Fri, 31 Jul 2020 10:53:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D1F261E8B; Fri, 31 Jul 2020 12:53:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="VW8AWFIn"; dkim-atps=neutral Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C4CBC611A2 for ; Fri, 31 Jul 2020 12:53:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:mime-version:to:cc:content-transfer-encoding: content-type; s=s1; bh=I04tn81IngKwKAJKQ7dYDsm1euX/qYOFXXBHEHb+CcI=; b=VW8AWFInDitgLpIan/KgxReMDWACkzSTMbdTskbmTZL4FlnmzlaI6zXTUyY6GU+zNRwM HYQTB2yDlVcJLld/N2KmLB8IC5X9HfngLYgiJV4rXPzNri3LMrVIyqvBfxSCsTXcSO3l13 tjQhJt9CPPE2jBVBFE8JuQG9mWkhugqBM= Received: by filterdrecv-p3iad2-d8cc6d457-mbgrc with SMTP id filterdrecv-p3iad2-d8cc6d457-mbgrc-20-5F23F835-4 2020-07-31 10:53:41.195088329 +0000 UTC m=+146721.277578589 Received: from mail.uajain.com (unknown) by ismtpd0003p1hnd1.sendgrid.net (SG) with ESMTP id -LphvwJxQxazceky3YCWIQ for ; Fri, 31 Jul 2020 10:53:40.673 +0000 (UTC) From: Umang Jain Date: Fri, 31 Jul 2020 10:53:41 +0000 (UTC) Message-Id: <20200731105335.62014-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcIQ89AvAiYjJmgYkN1WcnPZEWb2pj5GIxoFLTGE/1KO5rE2Dy1FN/xfvB5ms8kZmlRVE+ef6IZxR9+pXHyi9/it1Mo/wO6BqvTQiu53jgzP8nKd3O3+sNdnVWjXC+uZ9qO5b/zwwkCjr1eUp82LrNHdu9iBL7uCdhUK91l8BJhI12gFAVeS4hsuj0JdtnE2QmogGRHQ4w4Q55HyQGBL+LvQ== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH v2 0/3] Add Object::deleteLater() support X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implementation of Object::deleteLater() which ensures shared objects are deleted in the thread to which they belong. This fixes the issue where on hot-unplug, the Camera object is deleted in QCam's application thread instead of CameraManager's thread and triggering the ASSERT() in processNotifier (since the event notifier got deleted out of context in a different thread). See [1] for discussion. [1] https://lists.libcamera.org/pipermail/libcamera-devel/2020-July/010951.html Changes in v2: - Extend Thread::setEventDispatcher to selectively deliver messages - This will help if we want to explicitly deliver some messages if event loop is not running. - Include Object::deleteLater() unit test - One \todo here as one case pending to cover; multiple deleteLater() should only delete the object once. - Review comments (mostly documentation fixes). Umang Jain (3): libcamera: thread: Support selective message dispatch to thread libcamera: object: Add deleteLater() support libcamera: camera: Ensure deletion via deleteLater() include/libcamera/camera.h | 3 +- include/libcamera/internal/message.h | 2 + include/libcamera/internal/thread.h | 3 +- include/libcamera/object.h | 2 + src/libcamera/camera.cpp | 2 +- src/libcamera/camera_manager.cpp | 6 +- src/libcamera/event_dispatcher_poll.cpp | 2 +- src/libcamera/message.cpp | 4 + src/libcamera/object.cpp | 48 +++++++++ src/libcamera/thread.cpp | 47 ++++++--- test/meson.build | 1 + test/object-delete.cpp | 125 ++++++++++++++++++++++++ 12 files changed, 227 insertions(+), 18 deletions(-) create mode 100644 test/object-delete.cpp