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
2727 }
2828
2929 void ThreadedAssignment::setFinished(bool isFinished) {
30− _isFinished = isFinished;
30+ if (_isFinished != isFinished) {
31+ _isFinished = isFinished;
3132
32− if (_isFinished) {
33− if (_domainServerTimer) {
34− _domainServerTimer->stop();
35− delete _domainServerTimer;
36− _domainServerTimer = nullptr;
37− }
38− if (_statsTimer) {
39− _statsTimer->stop();
40− delete _statsTimer;
41− _statsTimer = nullptr;
42− }
33+ if (_isFinished) {
34+
35+ qDebug() << "Somebody set us finished";
36+
37+ if (_domainServerTimer) {
38+ _domainServerTimer->stop();
39+ }
40+
41+ if (_statsTimer) {
42+ _statsTimer->stop();
43+ }
4344
44− aboutToFinish();
45−
46− auto nodeList = DependencyManager::get<NodeList>();
47−
48− // 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 NodeList
50−
51− if (_datagramProcessingThread) {
52− // 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->wait();
45+ aboutToFinish();
46+
47+ auto nodeList = DependencyManager::get<NodeList>();
48+
49+ // if we have a datagram processing thread, quit it and wait on it to make sure that
50+ // the node socket is back on the same thread as the NodeList
51+
52+ if (_datagramProcessingThread) {
53+ // tell the datagram processing thread to quit and wait until it is done, then return the node socket to the NodeList
54+ _datagramProcessingThread->quit();
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());
5563
56− // set node socket parent back to NodeList
57− nodeList->getNodeSocket().setParent(nodeList.data());
64+ emit finished();
5865 }
59−
60− // move the NodeList back to the QCoreApplication instance's thread
61− nodeList->moveToThread(QCoreApplication::instance()->thread());
62−
63− emit finished();
6466 }
6567 }
6668