Skip to content

Commit

Permalink
Fix a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Nov 3, 2023
1 parent 9b7dc5c commit 68a34ae
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions wpiutil/src/main/native/cpp/DataLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,6 @@ struct DataLog::WriterThreadState {
void DataLog::StartLogFile(WriterThreadState& state) {
std::error_code ec;

{
std::scoped_lock lock{m_mutex};
state.filename = std::move(m_newFilename);
m_newFilename.clear();
}

if (state.filename.empty()) {
state.filename = MakeRandomFilename();
}
Expand Down Expand Up @@ -390,10 +384,15 @@ void DataLog::StartLogFile(WriterThreadState& state) {
void DataLog::WriterThreadMain(std::string_view dir) {
std::chrono::duration<double> periodTime{m_period};

std::error_code ec;
WriterThreadState state{dir};
{
std::scoped_lock lock{m_mutex};
state.filename = std::move(m_newFilename);
m_newFilename.clear();
}
StartLogFile(state);

std::error_code ec;
std::vector<Buffer> toWrite;
int freeSpaceCount = 0;
bool blocked = false;
Expand Down Expand Up @@ -421,6 +420,8 @@ void DataLog::WriterThreadMain(std::string_view dir) {
lock.lock();
if (!ec && !exists) {
state.Close();
WPI_INFO(m_msglog, "Log file '{}' deleted, recreating as fresh log",
state.filename);
doStart = true;
}

Expand All @@ -431,6 +432,8 @@ void DataLog::WriterThreadMain(std::string_view dir) {
state.filename = fmt::format("{}.{}.{}", path.stem().string(),
++segmentCount, path.extension().string());
state.path = state.dirPath / state.filename;
WPI_INFO(m_msglog, "Log file reached 1.8 GB, starting new file '{}'",
state.filename);
doStart = true;
}

Expand Down

0 comments on commit 68a34ae

Please sign in to comment.