mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
Merge pull request #1145 from birarda/assignment
fix silent node removal thread join bug
This commit is contained in:
commit
32b1fb2e23
1 changed files with 14 additions and 10 deletions
|
@ -767,24 +767,19 @@ void* removeSilentNodes(void *args) {
|
||||||
uint64_t checkTimeUsecs = 0;
|
uint64_t checkTimeUsecs = 0;
|
||||||
int sleepTime = 0;
|
int sleepTime = 0;
|
||||||
|
|
||||||
while (!silentNodeThreadStopFlag) {
|
while (!::silentNodeThreadStopFlag) {
|
||||||
|
|
||||||
checkTimeUsecs = usecTimestampNow();
|
checkTimeUsecs = usecTimestampNow();
|
||||||
|
|
||||||
for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) {
|
for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) {
|
||||||
qDebug() << "Locking node" << node->getUUID() << "\n";
|
|
||||||
node->lock();
|
node->lock();
|
||||||
|
|
||||||
qDebug() << "N:" << usecTimestampNow() << "LH:" << node->getLastHeardMicrostamp() << "\n";
|
|
||||||
qDebug() << "Diff:" << usecTimestampNow() - node->getLastHeardMicrostamp() << "\n";
|
|
||||||
|
|
||||||
if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) {
|
if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) {
|
||||||
// kill this node, don't lock - we already did it
|
// kill this node, don't lock - we already did it
|
||||||
nodeList->killNode(&(*node), false);
|
nodeList->killNode(&(*node), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
node->unlock();
|
node->unlock();
|
||||||
qDebug() << "Unlocking node" << node->getUUID() << "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sleepTime = NODE_SILENCE_THRESHOLD_USECS - (usecTimestampNow() - checkTimeUsecs);
|
sleepTime = NODE_SILENCE_THRESHOLD_USECS - (usecTimestampNow() - checkTimeUsecs);
|
||||||
|
@ -796,7 +791,6 @@ void* removeSilentNodes(void *args) {
|
||||||
#else
|
#else
|
||||||
|
|
||||||
if (sleepTime > 0) {
|
if (sleepTime > 0) {
|
||||||
qDebug() << "Sleeping for" << sleepTime << "\n";
|
|
||||||
usleep(sleepTime);
|
usleep(sleepTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -808,13 +802,23 @@ void* removeSilentNodes(void *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::startSilentNodeRemovalThread() {
|
void NodeList::startSilentNodeRemovalThread() {
|
||||||
pthread_create(&removeSilentNodesThread, NULL, removeSilentNodes, (void*) this);
|
if (!::silentNodeThreadStopFlag) {
|
||||||
|
pthread_create(&removeSilentNodesThread, NULL, removeSilentNodes, (void*) this);
|
||||||
|
} else {
|
||||||
|
qDebug("Refusing to start silent node removal thread from previously failed join.\n");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::stopSilentNodeRemovalThread() {
|
void NodeList::stopSilentNodeRemovalThread() {
|
||||||
silentNodeThreadStopFlag = true;
|
::silentNodeThreadStopFlag = true;
|
||||||
pthread_join(removeSilentNodesThread, NULL);
|
int joinResult = pthread_join(removeSilentNodesThread, NULL);
|
||||||
|
|
||||||
|
if (joinResult == 0) {
|
||||||
|
::silentNodeThreadStopFlag = false;
|
||||||
|
} else {
|
||||||
|
qDebug("Silent node removal thread join failed with %d. Will not restart.\n", joinResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString QSETTINGS_GROUP_NAME = "NodeList";
|
const QString QSETTINGS_GROUP_NAME = "NodeList";
|
||||||
|
|
Loading…
Reference in a new issue