From patchwork Fri Apr 23 04:04:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12089 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 6E448BDB1A for ; Fri, 23 Apr 2021 04:04:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E402E68872; Fri, 23 Apr 2021 06:04:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Gc3V9+Tq"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC03768861 for ; Fri, 23 Apr 2021 06:04:34 +0200 (CEST) Received: by mail-pj1-x102d.google.com with SMTP id m6-20020a17090a8586b02901507e1acf0fso543218pjn.3 for ; Thu, 22 Apr 2021 21:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VHFK4Q8bcE+PiHiCFkfv4rLEEKhtKOVVSjtRsIfzi8E=; b=Gc3V9+TqlBDENFZyjxVbDp8AgRLFBVo4J2GtxIvDUhunFotk5l36q8rUyDAam+ANFn yoki0pvlw+K9QZiDSFRImMS1X4wF2weJ8cNgmB2QJRuniA+Jf8KkJLAgm8W6qICVXaTQ dMZ6MVsQnvXUAHv7zJ2r8fXLbAK0zWeMgxMkg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VHFK4Q8bcE+PiHiCFkfv4rLEEKhtKOVVSjtRsIfzi8E=; b=U8BnHRRl8zTQc85drLw4L0wPuVFgK4Kpk7YEBlSG4Cb0e4he6FF304AFNhqXRNlU2F enmP33yf5DUsJZwQHh97Y7A1NdQu6EYLO+D86zSodcOBYSpPxXAAYZfh+3QTiYtsrZtX CHSxhnp30sUOWnuCz1VhmB9w8NfCnRJq0uOqkTqVadg0VXODGQ++N0whzsfBunmyfmWf pHuRXeABFU7zvLJlGs3OmzlJXR2cVHrljeR6e+0TWnGizFEq0cM9IwPDM4Epgt745WEV RryHdAXEUqyvZT3xyZKbdXVofpuS/lSJfJ2KkWODGrMWE1N/noWIpcHTwqa1C9P9Gs/7 WzRg== X-Gm-Message-State: AOAM53285VXQLKII+9EfQB0TDCgPQoRuLZWGZSFMrHSwaRvwAJ7uVSuJ t5NW/7kPOJvNJoufU/Uhq9W8QmCjSI2ePQ== X-Google-Smtp-Source: ABdhPJx6lF6S9u3HpJ779p22cNPr/tpNn70hbqVKLQgNmYgwtXgmGacslnGZAI8oc2S10cqVCAqTGA== X-Received: by 2002:a17:90b:1b4a:: with SMTP id nv10mr3646159pjb.75.1619150673178; Thu, 22 Apr 2021 21:04:33 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:8537:2d4f:8d35:5777]) by smtp.gmail.com with ESMTPSA id i22sm3604830pgj.90.2021.04.22.21.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 21:04:32 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 23 Apr 2021 13:04:27 +0900 Message-Id: <20210423040427.1226704-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH] android: CameraWorker: Cancel pending messages in queue in stop() 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" CameraWorker::stop() executes Thread::exit() and Thread::wait(). However, intuitively, the two functions doesn't clean up pending messages in the message queue of the thread. They are rather cleaned in the destruction of CameraWorker, but CameraWorker's life time is the same as CameraDevice and thus CameraManager, which is never destroyed. On the other hand, Camera3RequestDescriptors are destroyed in CameraDevice::stop(). This causes CameraWorker::Worker::queueRequest() starts to be executed after CameraWorker::start(), which is after CameraDevice::stop(). This obviously causes a segmentation fault, because CameraWorker::Worker::queueRequest() touches CaptureRequest which is owned by Camera3RequestDescriptor. This fixes the issue by cancel pending message in thread queue in CameraWorker::stop() with Thread::dispatchMessages(). Signed-off-by: Hirokazu Honda --- src/android/camera_worker.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/android/camera_worker.cpp b/src/android/camera_worker.cpp index 300ddde0..b68ce9d5 100644 --- a/src/android/camera_worker.cpp +++ b/src/android/camera_worker.cpp @@ -62,6 +62,7 @@ void CameraWorker::start() void CameraWorker::stop() { + thread_.dispatchMessages(Message::Type::InvokeMessage); thread_.exit(); thread_.wait(); }