| 275 | } |
| 276 | |
| 277 | void Probe::createProbe(bool findExisting) |
| 278 | { |
| 279 | Q_ASSERT(qApp); |
| 280 | Q_ASSERT(!isInitialized()); |
| 281 | |
| 282 | // first create the probe and its children |
| 283 | // we must not hold the object lock here as otherwise we can deadlock |
| 284 | // with other QObject's we create and other threads are using. One |
| 285 | // example are QAbstractSocketEngine. |
| 286 | IF_DEBUG(cout << "setting up new probe instance" << endl;) |
| 287 | Probe *probe = nullptr; |
| 288 | { |
| 289 | ProbeGuard guard; |
| 290 | probe = new Probe; |
| 291 | } |
| 292 | IF_DEBUG(cout << "done setting up new probe instance" << endl;) |
| 293 | |
| 294 | connect(qApp, &QCoreApplication::aboutToQuit, probe, &Probe::shutdown); |
| 295 | |
| 296 | // Our safety net, if there's no call to QCoreApplication::exec() we'll never receive the aboutToQuit() signal |
| 297 | // Make sure we still cleanup safely after the application instance got destroyed |
| 298 | connect(qApp, &QObject::destroyed, probe, &Probe::shutdown); |
| 299 | |
| 300 | // now we can get the lock and add items which where added before this point in time |
| 301 | { |
| 302 | QMutexLocker lock(s_lock()); |
| 303 | // now we set the instance while holding the lock, |
| 304 | // all future calls to object{Added,Removed} will |
| 305 | // act directly on the data structures there instead |
| 306 | // of using addedBeforeProbeInstance |
| 307 | // this will only happen _after_ the object lock above is released though |
| 308 | Q_ASSERT(!instance()); |
| 309 | |
| 310 | s_instance = QAtomicPointer<Probe>(probe); |
| 311 | |
| 312 | // add objects to the probe that were tracked before its creation |
| 313 | foreach (QObject *obj, s_listener()->addedBeforeProbeInstance) { |
| 314 | objectAdded(obj); |
| 315 | } |
| 316 | s_listener()->addedBeforeProbeInstance.clear(); |
| 317 | |
| 318 | // try to find existing objects by other means |
| 319 | if (findExisting) |
| 320 | probe->findExistingObjects(); |
| 321 | } |
| 322 | |
| 323 | // eventually initialize the rest |
| 324 | QMetaObject::invokeMethod(probe, "delayedInit", Qt::QueuedConnection); |
| 325 | } |
| 326 | |
| 327 | void Probe::resendServerAddress() |
| 328 | { |
nothing calls this directly
no test coverage detected