1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-16 07:23:07 +01:00

improve logging MT robustness

This commit is contained in:
andreas
2021-11-13 18:15:50 +01:00
parent 6ef75422d8
commit b3f4a11a8e
6 changed files with 62 additions and 18 deletions

View File

@@ -34,7 +34,11 @@ void GwLog::logDebug(int level,const char *fmt,...){
va_start(args,fmt);
xSemaphoreTake(locker, portMAX_DELAY);
vsnprintf(buffer,99,fmt,args);
if (! writer) return;
buffer[99]=0;
if (! writer) {
xSemaphoreGive(locker);
return;
}
writer->write(prefix.c_str());
writer->write(buffer);
writer->write("\n");
@@ -46,3 +50,13 @@ void GwLog::setWriter(GwLogWriter *writer){
this->writer=writer;
xSemaphoreGive(locker);
}
void GwLog::flush(){
xSemaphoreTake(locker, portMAX_DELAY);
if (! this->writer) {
xSemaphoreGive(locker);
return;
}
this->writer->flush();
xSemaphoreGive(locker);
}