Skip to content

Commit

Permalink
Save channel group headers right after saving data
Browse files Browse the repository at this point in the history
If the program generating the MDF file was interrupted to never recover again, the current measurement would be completely lost, even though data was being periodically written to the file.
The problem was that the channel group header was not being written to the file to reflect the updated number of samples.
This function appears to be called sporadically enough that these writes shouldn't be a problem.
  • Loading branch information
tiagoporsch committed Jun 24, 2024
1 parent e300448 commit a3c7247
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mdflib/src/mdfwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,14 @@ void MdfWriter::SaveQueue(std::unique_lock<std::mutex>& lock) {
lock.lock();
}

// Update channel group headers to reflect the new number of samples
lock.unlock();
for (const auto& cg3 : dg3->Cg3()) {
if (cg3 != nullptr) {
cg3->Write(file);
}
}

fclose(file);
lock.lock();
}
Expand Down Expand Up @@ -970,4 +977,4 @@ void MdfWriter::CreateCanOverloadFrameChannel(IChannelGroup& group) {

}

} // namespace mdf
} // namespace mdf

0 comments on commit a3c7247

Please sign in to comment.