From 8034af7423e0b9f00c84eaa00cd095dbcf44f4a5 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 18 Jan 2020 03:05:54 +0200 Subject: libcamera: bound_method: Avoid deadlock with ConnectionTypeBlocking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ConnectionTypeBlocking always invokes the method through inter-thread message passing, which results in deadlocks if the sender and receiver live in the same thread. The deadlock can easily be avoided by turning the invocation into a direct call in this case. Do so to make ConnectionTypeBlocking easier to use when some of the senders live in the same thread as the receiver while the other senders don't. Extend the object-invoke test to cover this usage. While at it reformat the documentation to avoid long \brief lines. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- test/object-invoke.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/object-invoke.cpp') diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp index 8e2055ca..fa162c83 100644 --- a/test/object-invoke.cpp +++ b/test/object-invoke.cpp @@ -100,6 +100,26 @@ protected: return TestFail; } + /* + * Test that blocking invocation is delivered directly when the + * caller and callee live in the same thread. + */ + object_.reset(); + + object_.invokeMethod(&InvokedObject::method, + ConnectionTypeBlocking, 42); + + switch (object_.status()) { + case InvokedObject::NoCall: + cout << "Method not invoked for main thread (blocking)" << endl; + return TestFail; + case InvokedObject::InvalidThread: + cout << "Method invoked in incorrect thread for main thread (blocking)" << endl; + return TestFail; + default: + break; + } + /* * Move the object to a thread and verify that auto method * invocation is delivered in the correct thread. -- cgit v1.2.1