logd: track SerializedFlushToState instances within SerializedLogChunk
Previously, NotifyReadersOfPrune() would iterate through the list of
reader_threads_ to find SerializedFlushToState instances, but that
misses some instances, which leads to violating important CHECK()'s.
This change 'attaches' a SerializedFlushToState instance to a
SerializedLogChunk instance when it begins reading from it and
'detaches' it when it has finished with it. This allows a new
SerializedLogChunk::NotifyReadersOfPrune() function to notify exactly
those SerializedFlushToState instances that are currently 'attached'
to it.
Bug: 169736426
Bug: 172279637
Test: logging unit tests
Change-Id: I0ab4979c8fe2b84a0e23fc5ea5fb6dd54fadc691
diff --git a/logd/SerializedLogBuffer.cpp b/logd/SerializedLogBuffer.cpp
index 09e44d9..5f1a77b 100644
--- a/logd/SerializedLogBuffer.cpp
+++ b/logd/SerializedLogBuffer.cpp
@@ -137,14 +137,6 @@
chunk.DecReaderRefCount();
}
-void SerializedLogBuffer::NotifyReadersOfPrune(
- log_id_t log_id, const std::list<SerializedLogChunk>::iterator& chunk) {
- for (const auto& reader_thread : reader_list_->reader_threads()) {
- auto& state = reinterpret_cast<SerializedFlushToState&>(reader_thread->flush_to_state());
- state.Prune(log_id, chunk);
- }
-}
-
void SerializedLogBuffer::Prune(log_id_t log_id, size_t bytes_to_free, uid_t uid) {
auto& log_buffer = logs_[log_id];
auto it = log_buffer.begin();
@@ -180,7 +172,7 @@
// Readers may have a reference to the chunk to track their last read log_position.
// Notify them to delete the reference.
- NotifyReadersOfPrune(log_id, it_to_prune);
+ it_to_prune->NotifyReadersOfPrune(log_id);
if (uid != 0) {
// Reorder the log buffer to remove logs from the given UID. If there are no logs left