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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user