From patchwork Fri Jul 31 13:39:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9087 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 E96D0BD878 for ; Fri, 31 Jul 2020 13:39:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 411D261DCF; Fri, 31 Jul 2020 15:39:55 +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="e/PRgMsR"; 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 3F2F260398 for ; Fri, 31 Jul 2020 15:39:54 +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=ZFE6B/f5by20p3Ug15oaegZvlQiuBRRNoM6HSMeK4eY=; b=e/PRgMsRNk0jtudUNdFm2YkdTB4PYz4IVBUC8r2qHgq5cpE8YHspy/M5VtfTe3TT3w72 73rTKH+/a3t4PWrC9aOsFW/B0CjlMYmhPxlzwadRL+tn+ANFwaEEACDO9FfWvzDM4ARyXh cX4mh6iElHT/VIAyagSSgBJP1wFbEwvfQ= Received: by filterdrecv-p3mdw1-7ff865655c-g882x with SMTP id filterdrecv-p3mdw1-7ff865655c-g882x-20-5F241F28-4F 2020-07-31 13:39:52.777678457 +0000 UTC m=+156222.255847520 Received: from mail.uajain.com (unknown) by ismtpd0006p1hnd1.sendgrid.net (SG) with ESMTP id k7-u94p2T0KoV6lnWcaagw for ; Fri, 31 Jul 2020 13:39:52.366 +0000 (UTC) From: Umang Jain Date: Fri, 31 Jul 2020 13:39:52 +0000 (UTC) Message-Id: <20200731133947.84258-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcp6CL6ozs3IeZvk96OtB41FraVTNUEerr68HEcxQWFp7KCL1EDPr1Toh858nCzu9GGoBcRYn338QJcRejp7o7IJwC5RFp37UsSgcGPjjGQyFWpXXEKh/7dCPZ9hraNKbXbtC8nLI+CdCiA6ErxskT4AAljraR2i13omJ1Px84uLU6k4aXGoVFOM+DSx8/9AAJRYWNfEHG0qnfTkyUL78dfg== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH v3 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 v3: - Address review for 1/3. dispatchMessages() message loop changed to support handling dispatching of all or per type messages. 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 | 1 + include/libcamera/internal/thread.h | 3 +- include/libcamera/object.h | 2 + src/libcamera/camera.cpp | 2 +- src/libcamera/camera_manager.cpp | 6 +- src/libcamera/message.cpp | 2 + src/libcamera/object.cpp | 48 ++++++++++ src/libcamera/thread.cpp | 30 +++++-- test/meson.build | 1 + test/object-delete.cpp | 125 +++++++++++++++++++++++++++ 11 files changed, 210 insertions(+), 13 deletions(-) create mode 100644 test/object-delete.cpp