[libcamera-devel,v2,02/18] libcamera: thread: Wake up target thread when moving objects

Message ID 20190817152104.10834-3-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Object & Thread enhancements
Related show

Commit Message

Laurent Pinchart Aug. 17, 2019, 3:20 p.m. UTC
When moving an object to a different thread, messages posted for the
object are moved to the message queue of the new thread. Wake up the new
thread to ensure it processes the moved messages.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/libcamera/thread.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

Patch

diff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp
index 5d46eeb8d3a5..6f86e4a90a05 100644
--- a/src/libcamera/thread.cpp
+++ b/src/libcamera/thread.cpp
@@ -464,6 +464,8 @@  void Thread::moveObject(Object *object)
 
 	/* Move pending messages to the message queue of the new thread. */
 	if (object->pendingMessages_) {
+		unsigned int movedMessages = 0;
+
 		for (std::unique_ptr<Message> &msg : currentData->messages_.list_) {
 			if (!msg)
 				continue;
@@ -471,6 +473,14 @@  void Thread::moveObject(Object *object)
 				continue;
 
 			targetData->messages_.list_.push_back(std::move(msg));
+			movedMessages++;
+		}
+
+		if (movedMessages) {
+			EventDispatcher *dispatcher =
+				targetData->dispatcher_.load(std::memory_order_acquire);
+			if (dispatcher)
+				dispatcher->interrupt();
 		}
 	}