History

standardize cleanup of ThreadedAssignments

Stephen Birarda committed 11 years ago

Commit d75d2041 parent b7b62c813 files · +90 −131Browse files

Showing the changes to libraries/networking/src/ThreadedAssignment.cpp (1 of 13 files). Show all

Unified · Split

libraries/networking/src/ThreadedAssignment.cpp+32−30
@@ -27,40 +27,42 @@ ThreadedAssignment::ThreadedAssignment(const QByteArray& packet) : · 26 unmodified lines
27}27}
28 28
29void ThreadedAssignment::setFinished(bool isFinished) {29void ThreadedAssignment::setFinished(bool isFinished) {
30 _isFinished = isFinished;30 if (_isFinished != isFinished) {
31 _isFinished = isFinished;
31 32
32 if (_isFinished) {33 if (_isFinished) {
33 if (_domainServerTimer) {34
34 _domainServerTimer->stop();35 qDebug() << "Somebody set us finished";
35 delete _domainServerTimer;36
36 _domainServerTimer = nullptr;37 if (_domainServerTimer) {
37 }38 _domainServerTimer->stop();
38 if (_statsTimer) {39 }
39 _statsTimer->stop();40
40 delete _statsTimer;41 if (_statsTimer) {
41 _statsTimer = nullptr;42 _statsTimer->stop();
42 }43 }
43 44
44 aboutToFinish();45 aboutToFinish();
45 46
46 auto nodeList = DependencyManager::get<NodeList>();47 auto nodeList = DependencyManager::get<NodeList>();
47 48
48 // if we have a datagram processing thread, quit it and wait on it to make sure that49 // if we have a datagram processing thread, quit it and wait on it to make sure that
49 // the node socket is back on the same thread as the NodeList50 // the node socket is back on the same thread as the NodeList
50 51
51 if (_datagramProcessingThread) {52 if (_datagramProcessingThread) {
52 // tell the datagram processing thread to quit and wait until it is done, then return the node socket to the NodeList53 // tell the datagram processing thread to quit and wait until it is done, then return the node socket to the NodeList
53 _datagramProcessingThread->quit();54 _datagramProcessingThread->quit();
54 _datagramProcessingThread->wait();55 _datagramProcessingThread->wait();
56
57 // set node socket parent back to NodeList
58 nodeList->getNodeSocket().setParent(nodeList.data());
59 }
60
61 // move the NodeList back to the QCoreApplication instance's thread
62 nodeList->moveToThread(QCoreApplication::instance()->thread());
55 63
56 // set node socket parent back to NodeList64 emit finished();
57 nodeList->getNodeSocket().setParent(nodeList.data());
58 }65 }
59
60 // move the NodeList back to the QCoreApplication instance's thread
61 nodeList->moveToThread(QCoreApplication::instance()->thread());
62
63 emit finished();
64 }66 }
65}67}
66 68