Reordered error downgrading, order of going offline, and renamed locks

checksum-failure-logging
EricLiu2000 2019-08-06 10:32:19 -04:00
parent 01c62b6445
commit 3358241abe
5 changed files with 12 additions and 12 deletions

View File

@ -156,14 +156,15 @@ void Communication::readTask() {
std::lock_guard<std::mutex> lk(messageCallbacksLock);
// We want callbacks to be able to access errors
EventManager::GetInstance().cancelErrorDowngradingOnCurrentThread();
for(auto& cb : messageCallbacks) {
if(!closing) { // We might have closed while reading or processing
// We want callbacks to be able to access errors
EventManager::GetInstance().cancelErrorDowngradingOnCurrentThread();
cb.second.callIfMatch(msg);
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
}
}
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
}
}
}

View File

@ -113,14 +113,14 @@ void MultiChannelCommunication::readTask() {
continue;
}
// We want callbacks to be able to access errors
EventManager::GetInstance().cancelErrorDowngradingOnCurrentThread();
for(auto& cb : messageCallbacks) { // We might have closed while reading or processing
if(!closing) {
// We want callbacks to be able to access errors
EventManager::GetInstance().cancelErrorDowngradingOnCurrentThread();
cb.second.callIfMatch(msg);
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
}
}
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
}
}

View File

@ -203,14 +203,14 @@ bool Device::close() {
return false;
}
if(isOnline())
goOffline();
if(internalHandlerCallbackID)
com->removeMessageCallback(internalHandlerCallbackID);
internalHandlerCallbackID = 0;
if(isOnline())
goOffline();
return com->close();
}

View File

@ -58,7 +58,7 @@ public:
eventsLock.unlock();
runCallbacks(event);
} else {
std::lock_guard<std::mutex> lk(errorsMutex);
std::lock_guard<std::mutex> errorsLock(errorsMutex);
add_internal_error(event);
}
} else {

View File

@ -293,7 +293,6 @@ void STM32::readTask() {
if(bytesRead > 0)
readQueue.enqueue_bulk(readbuf, bytesRead);
}
EventManager::GetInstance().cancelErrorDowngradingOnCurrentThread();
}
void STM32::writeTask() {