From ec62df2ad739fd4a6c72f16188c2363b6c240cdb Mon Sep 17 00:00:00 2001 From: Andrew Bell Date: Tue, 19 Oct 2021 13:32:05 -0400 Subject: [PATCH] We we try to write an empty buffer, replace it in the buffer cache. --- epf/Cell.cpp | 2 ++ epf/Writer.cpp | 6 ++++++ epf/Writer.hpp | 1 + 3 files changed, 9 insertions(+) diff --git a/epf/Cell.cpp b/epf/Cell.cpp index bb0d1c7..b8324b2 100644 --- a/epf/Cell.cpp +++ b/epf/Cell.cpp @@ -41,6 +41,8 @@ void Cell::write() size_t size = m_pos - m_buf->data(); if (size) m_writer->enqueue(m_key, std::move(m_buf), size); + else + m_writer->replace(std::move(m_buf)); } void Cell::advance() diff --git a/epf/Writer.cpp b/epf/Writer.cpp index 61aae47..0690508 100644 --- a/epf/Writer.cpp +++ b/epf/Writer.cpp @@ -78,6 +78,12 @@ void Writer::enqueue(const VoxelKey& key, DataVecPtr data, size_t dataSize) m_available.notify_one(); } +void Writer::replace(DataVecPtr data) +{ + std::lock_guard lock(m_mutex); + m_bufferCache.replace(std::move(data)); +} + void Writer::stop() { { diff --git a/epf/Writer.hpp b/epf/Writer.hpp index 2dde14f..05cc425 100644 --- a/epf/Writer.hpp +++ b/epf/Writer.hpp @@ -40,6 +40,7 @@ class Writer public: Writer(const std::string& directory, int numThreads, size_t pointSize); + void replace(DataVecPtr data); void enqueue(const VoxelKey& key, DataVecPtr data, size_t dataSize); void stop(); const Totals& totals()