Showing the changes to assignment-client/src/AssignmentClient.cpp (1 of 16 files). Show all
Unified · Split
| @@ -62,6 +62,17 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri · 61 unmodified lines | ||
| 62 | 62 | DependencyManager::registerInheritance<EntityActionFactoryInterface, AssignmentActionFactory>(); |
| 63 | 63 | auto actionFactory = DependencyManager::set<AssignmentActionFactory>(); |
| 64 | 64 | |
| 65 | + // setup a thread for the NodeList and its PacketReceiver | |
| 66 | + QThread* nodeThread = new QThread(this); | |
| 67 | + nodeThread->setObjectName("NodeList Thread"); | |
| 68 | + nodeThread->start(); | |
| 69 | + | |
| 70 | + // make sure the node thread is given highest priority | |
| 71 | + nodeThread->setPriority(QThread::TimeCriticalPriority); | |
| 72 | + | |
| 73 | + // put the NodeList on the node thread | |
| 74 | + nodeList->moveToThread(nodeThread); | |
| 75 | + | |
| 65 | 76 | // make up a uuid for this child so the parent can tell us apart. This id will be changed |
| 66 | 77 | // when the domain server hands over an assignment. |
| 67 | 78 | QUuid nodeUUID = QUuid::createUuid(); |
| @@ -124,7 +135,6 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri · 56 unmodified lines | ||
| 124 | 135 | packetReceiver.registerListener(PacketType::CreateAssignment, this, "handleCreateAssignmentPacket"); |
| 125 | 136 | packetReceiver.registerListener(PacketType::StopNode, this, "handleStopNodePacket"); |
| 126 | 137 | } |
| 127 | − | |
| 128 | 138 | void AssignmentClient::stopAssignmentClient() { |
| 129 | 139 | qDebug() << "Forced stop of assignment-client."; |
| 130 | 140 | |
| @@ -150,6 +160,16 @@ void AssignmentClient::stopAssignmentClient() { · 19 unmodified lines | ||
| 150 | 160 | } |
| 151 | 161 | } |
| 152 | 162 | |
| 163 | +AssignmentClient::~AssignmentClient() { | |
| 164 | + QThread* nodeThread = DependencyManager::get<NodeList>()->thread(); | |
| 165 | + | |
| 166 | + // remove the NodeList from the DependencyManager | |
| 167 | + DependencyManager::destroy<NodeList>(); | |
| 168 | + | |
| 169 | + // ask the node thread to quit and wait until it is done | |
| 170 | + nodeThread->quit(); | |
| 171 | + nodeThread->wait(); | |
| 172 | +} | |
| 153 | 173 | |
| 154 | 174 | void AssignmentClient::aboutToQuit() { |
| 155 | 175 | stopAssignmentClient(); |
| @@ -251,9 +271,6 @@ void AssignmentClient::handleCreateAssignmentPacket(QSharedPointer<NLPacket> pac · 95 unmodified lines | ||
| 251 | 271 | |
| 252 | 272 | _currentAssignment->moveToThread(workerThread); |
| 253 | 273 | |
| 254 | − // move the NodeList to the thread used for the _current assignment | |
| 255 | − nodeList->moveToThread(workerThread); | |
| 256 | − | |
| 257 | 274 | // Starts an event loop, and emits workerThread->started() |
| 258 | 275 | workerThread->start(); |
| 259 | 276 | } else { |
| @@ -313,6 +330,9 @@ void AssignmentClient::assignmentCompleted() { · 53 unmodified lines | ||
| 313 | 330 | |
| 314 | 331 | auto nodeList = DependencyManager::get<NodeList>(); |
| 315 | 332 | |
| 333 | + // tell the packet receiver to stop dropping packets | |
| 334 | + nodeList->getPacketReceiver().setShouldDropPackets(false); | |
| 335 | + | |
| 316 | 336 | // reset our NodeList by switching back to unassigned and clearing the list |
| 317 | 337 | nodeList->setOwnerType(NodeType::Unassigned); |
| 318 | 338 | nodeList->reset(); |