From patchwork Wed Nov 27 08:49:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2383 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3AFD161C5C for ; Wed, 27 Nov 2019 09:49:29 +0100 (CET) Received: from pendragon.tok.corp.google.com (unknown [104.132.253.101]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 154419F4 for ; Wed, 27 Nov 2019 09:49:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1574844569; bh=dggPb64g4G4E36RnOUlFO9IBTdilVFJ4kqh4Q74w8AU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RvOa/w7ogY9Fu6UF7KtMSBgg6gYsIpPE8LJ21HE9Lh2x0HEDShAwcec0m7Ex8U+2I uwGGO0ucuqvod6FEUiM17P7ldbuWpgl5I3hVAjJ+TwcZAj0jyTXWKyF/JZmKn8H7J0 +XfUBMocG8qurtfru7NSkDGNAKpKXamhJkm8Kp74= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 27 Nov 2019 10:49:09 +0200 Message-Id: <20191127084909.10612-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191127084909.10612-1-laurent.pinchart@ideasonboard.com> References: <20191127084909.10612-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] test: object-invoke: Delete InvokeObject after thread termination 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: , X-List-Received-Date: Wed, 27 Nov 2019 08:49:29 -0000 The InvokeObject instance is created on the stack in the run() method, and is thus destroyed before the thread the object is bound to terminates. This creates a race condition as the object message handler could be running when the object is deleted. Fix this by moving the InvokeObject to a member field. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- test/object-invoke.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp index 6582fa75ae11..560adee14e3a 100644 --- a/test/object-invoke.cpp +++ b/test/object-invoke.cpp @@ -60,23 +60,22 @@ protected: int run() { EventDispatcher *dispatcher = Thread::current()->eventDispatcher(); - InvokedObject object; /* * Test that queued method invocation in the same thread goes * through the event dispatcher. */ - object.invokeMethod(&InvokedObject::method, - ConnectionTypeQueued, 42); + object_.invokeMethod(&InvokedObject::method, + ConnectionTypeQueued, 42); - if (object.status() != InvokedObject::NoCall) { + if (object_.status() != InvokedObject::NoCall) { cerr << "Method not invoked asynchronously" << endl; return TestFail; } dispatcher->processEvents(); - switch (object.status()) { + switch (object_.status()) { case InvokedObject::NoCall: cout << "Method not invoked for main thread" << endl; return TestFail; @@ -87,7 +86,7 @@ protected: break; } - if (object.value() != 42) { + if (object_.value() != 42) { cout << "Method invoked with incorrect value for main thread" << endl; return TestFail; } @@ -96,15 +95,15 @@ protected: * Move the object to a thread and verify that auto method * invocation is delivered in the correct thread. */ - object.reset(); - object.moveToThread(&thread_); + object_.reset(); + object_.moveToThread(&thread_); thread_.start(); - object.invokeMethod(&InvokedObject::method, - ConnectionTypeBlocking, 42); + object_.invokeMethod(&InvokedObject::method, + ConnectionTypeBlocking, 42); - switch (object.status()) { + switch (object_.status()) { case InvokedObject::NoCall: cout << "Method not invoked for custom thread" << endl; return TestFail; @@ -115,7 +114,7 @@ protected: break; } - if (object.value() != 42) { + if (object_.value() != 42) { cout << "Method invoked with incorrect value for custom thread" << endl; return TestFail; } @@ -131,6 +130,7 @@ protected: private: Thread thread_; + InvokedObject object_; }; TEST_REGISTER(ObjectInvokeTest)