summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/include/message.h1
-rw-r--r--src/libcamera/message.cpp2
-rw-r--r--src/libcamera/object.cpp12
3 files changed, 15 insertions, 0 deletions
diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h
index 92717e31..1cfde566 100644
--- a/src/libcamera/include/message.h
+++ b/src/libcamera/include/message.h
@@ -23,6 +23,7 @@ public:
enum Type {
None = 0,
InvokeMessage = 1,
+ ThreadMoveMessage = 2,
UserMessage = 1000,
};
diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp
index f6c39d40..efafb655 100644
--- a/src/libcamera/message.cpp
+++ b/src/libcamera/message.cpp
@@ -47,6 +47,8 @@ std::atomic_uint Message::nextUserType_{ Message::UserMessage };
* \brief Invalid message type
* \var Message::InvokeMessage
* \brief Asynchronous method invocation across threads
+ * \var Message::ThreadMoveMessage
+ * \brief Object is being moved to a different thread
* \var Message::UserMessage
* \brief First value available for user-defined messages
*/
diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp
index 7d70ce21..bbb28f26 100644
--- a/src/libcamera/object.cpp
+++ b/src/libcamera/object.cpp
@@ -135,6 +135,10 @@ void Object::invokeMethod(BoundMethodBase *method, void *args)
* This method moves the object from the current thread to the new \a thread.
* It shall be called from the thread in which the object currently lives,
* otherwise the behaviour is undefined.
+ *
+ * Before the object is moved, a Message::ThreadMoveMessage message is sent to
+ * it. The message() method can be reimplement in derived classes to be notified
+ * of the upcoming thread move and perform any required processing.
*/
void Object::moveToThread(Thread *thread)
{
@@ -143,9 +147,17 @@ void Object::moveToThread(Thread *thread)
if (thread_ == thread)
return;
+ notifyThreadMove();
+
thread->moveObject(this);
}
+void Object::notifyThreadMove()
+{
+ Message msg(Message::ThreadMoveMessage);
+ message(&msg);
+}
+
void Object::connect(SignalBase *signal)
{
signals_.push_back(signal);