From 13f5e5c6b2c320c33dd0b9305de410bef1b3c2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Kosobucki?= Date: Sat, 11 Nov 2017 21:05:39 +0100 Subject: Improve QObject::moveToThread doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change mentions of parameter value being "zero" to nullptr. Clarify that when nullptr is passed to moveToThread() event processing is stopped because the object is no longer associated with any thread. Also, reitarete this fact in the paragraph about processing of new events. There's an exception to the rule that QObjects cannot be "pulled" by moveToThread that is buried in the implementation and not mentioned in the doc. This information is worth noting explicitly. Change-Id: I816ff737c48d8057b39e36b566079710aeb8e690 Reviewed-by: André Hartmann Reviewed-by: Edward Welbourne --- src/corelib/kernel/qobject.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/corelib/kernel/qobject.cpp') diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index a791d2e8b3..2a05f7f383 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1445,8 +1445,9 @@ QThread *QObject::thread() const \snippet code/src_corelib_kernel_qobject.cpp 7 - If \a targetThread is zero, all event processing for this object - and its children stops. + If \a targetThread is \nullptr, all event processing for this object + and its children stops, as they are no longer associated with any + thread. Note that all active timers for the object will be reset. The timers are first stopped in the current thread and restarted (with @@ -1457,13 +1458,18 @@ QThread *QObject::thread() const A QEvent::ThreadChange event is sent to this object just before the thread affinity is changed. You can handle this event to perform any special processing. Note that any new events that are - posted to this object will be handled in the \a targetThread. + posted to this object will be handled in the \a targetThread, + provided it is non-null: when it is \nullptr, no event processing + for this object or its children can happen, as they are no longer + associated with any thread. \warning This function is \e not thread-safe; the current thread must be same as the current thread affinity. In other words, this function can only "push" an object from the current thread to another thread, it cannot "pull" an object from any arbitrary - thread to the current thread. + thread to the current thread. There is one exception to this rule + however: objects with no thread affinity can be "pulled" to the + current thread. \sa thread() */ -- cgit v1.2.3 From e5eaae100b35d97f22a388831a5b9cd712053f3f Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Fri, 26 Apr 2019 15:16:18 +0200 Subject: Refactor QMetaObject::activate tracepoints Use Q_TRACE_SCOPE and the corresponding naming scheme. Additionally, don't change the behavior of the code when tracing is enabled, i.e. continue to return early if possible. Change-Id: I9ba9679869db1541a19bc832beede902224c52f2 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qobject.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/corelib/kernel/qobject.cpp') diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 2a05f7f383..68c5460b6a 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -3664,19 +3664,18 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i if (sender->d_func()->blockSig) return; + Q_TRACE_SCOPE(QMetaObject_activate, sender, signal_index); + if (sender->d_func()->isDeclarativeSignalConnected(signal_index) && QAbstractDeclarativeData::signalEmitted) { - Q_TRACE(QMetaObject_activate_begin_declarative_signal, sender, signal_index); + Q_TRACE_SCOPE(QMetaObject_activate_declarative_signal, sender, signal_index); QAbstractDeclarativeData::signalEmitted(sender->d_func()->declarativeData, sender, signal_index, argv); - Q_TRACE(QMetaObject_activate_end_declarative_signal, sender, signal_index); } if (!sender->d_func()->isSignalConnected(signal_index, /*checkDeclarative =*/ false) && !qt_signal_spy_callback_set.signal_begin_callback - && !qt_signal_spy_callback_set.signal_end_callback - && !Q_TRACE_ENABLED(QMetaObject_activate_begin_signal) - && !Q_TRACE_ENABLED(QMetaObject_activate_end_signal)) { + && !qt_signal_spy_callback_set.signal_end_callback) { // The possible declarative connection is done, and nothing else is connected, so: return; } @@ -3686,7 +3685,6 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i qt_signal_spy_callback_set.signal_begin_callback(sender, signal_index, argv ? argv : empty_argv); } - Q_TRACE(QMetaObject_activate_begin_signal, sender, signal_index); { QMutexLocker locker(signalSlotLock(sender)); @@ -3717,7 +3715,6 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i locker.unlock(); if (qt_signal_spy_callback_set.signal_end_callback != 0) qt_signal_spy_callback_set.signal_end_callback(sender, signal_index); - Q_TRACE(QMetaObject_activate_end_signal, sender, signal_index); return; } @@ -3778,9 +3775,11 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i c->slotObj->ref(); QScopedPointer obj(c->slotObj); locker.unlock(); - Q_TRACE(QMetaObject_activate_begin_slot_functor, obj.data()); - obj->call(receiver, argv ? argv : empty_argv); - Q_TRACE(QMetaObject_activate_end_slot_functor, obj.data()); + + { + Q_TRACE_SCOPE(QMetaObject_activate_slot_functor, obj.data()); + obj->call(receiver, argv ? argv : empty_argv); + } // Make sure the slot object gets destroyed before the mutex is locked again, as the // destructor of the slot object might also lock a mutex from the signalSlotLock() mutex pool, @@ -3796,11 +3795,12 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i locker.unlock(); if (qt_signal_spy_callback_set.slot_begin_callback != 0) qt_signal_spy_callback_set.slot_begin_callback(receiver, methodIndex, argv ? argv : empty_argv); - Q_TRACE(QMetaObject_activate_begin_slot, receiver, methodIndex); - callFunction(receiver, QMetaObject::InvokeMetaMethod, method_relative, argv ? argv : empty_argv); + { + Q_TRACE_SCOPE(QMetaObject_activate_slot, receiver, methodIndex); + callFunction(receiver, QMetaObject::InvokeMetaMethod, method_relative, argv ? argv : empty_argv); + } - Q_TRACE(QMetaObject_activate_end_slot, receiver, methodIndex); if (qt_signal_spy_callback_set.slot_end_callback != 0) qt_signal_spy_callback_set.slot_end_callback(receiver, methodIndex); locker.relock(); @@ -3813,11 +3813,12 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i method, argv ? argv : empty_argv); } - Q_TRACE(QMetaObject_activate_begin_slot, receiver, method); - metacall(receiver, QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv); + { + Q_TRACE_SCOPE(QMetaObject_activate_slot, receiver, method); + metacall(receiver, QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv); + } - Q_TRACE(QMetaObject_activate_end_slot, receiver, method); if (qt_signal_spy_callback_set.slot_end_callback != 0) qt_signal_spy_callback_set.slot_end_callback(receiver, method); @@ -3838,7 +3839,6 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i if (qt_signal_spy_callback_set.signal_end_callback != 0) qt_signal_spy_callback_set.signal_end_callback(sender, signal_index); - Q_TRACE(QMetaObject_activate_end_signal, sender, signal_index); } /*! -- cgit v1.2.3