mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-17 03:37:35 +08:00
logger: remove _log_buffer from Logger, initialize it in the writer instead
it's not used in the logger, so don't store it there. It is accessed via LogWriter::write. This also makes sure the buffer size is >= _min_write_chunk and handles allocation failure properly.
This commit is contained in:
@@ -2,15 +2,15 @@
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mathlib/mathlib.h>
|
||||
|
||||
namespace px4
|
||||
{
|
||||
namespace logger
|
||||
{
|
||||
|
||||
LogWriter::LogWriter(uint8_t *buffer, size_t buffer_size) :
|
||||
_buffer(buffer),
|
||||
_buffer_size(buffer_size),
|
||||
_min_write_chunk(4096)
|
||||
LogWriter::LogWriter(size_t buffer_size) :
|
||||
_buffer_size(math::max(buffer_size, _min_write_chunk))
|
||||
{
|
||||
pthread_mutex_init(&_mtx, nullptr);
|
||||
pthread_cond_init(&_cv, nullptr);
|
||||
@@ -19,6 +19,24 @@ LogWriter::LogWriter(uint8_t *buffer, size_t buffer_size) :
|
||||
perf_fsync = perf_alloc(PC_ELAPSED, "sd fsync");
|
||||
}
|
||||
|
||||
bool LogWriter::init()
|
||||
{
|
||||
if (_buffer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
_buffer = new uint8_t[_buffer_size];
|
||||
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
LogWriter::~LogWriter()
|
||||
{
|
||||
if (_buffer) {
|
||||
delete[] _buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void LogWriter::start_log(const char *filename)
|
||||
{
|
||||
::strncpy(_filename, filename, sizeof(_filename));
|
||||
|
||||
Reference in New Issue
Block a user