Merge "logd: add locks around ~SerializedFlushToState"

This commit is contained in:
Tom Cherry 2020-10-05 22:22:52 +00:00 committed by Gerrit Code Review
commit 1bacb2c389
5 changed files with 14 additions and 1 deletions

View file

@ -19,6 +19,7 @@
#include <sys/types.h>
#include <functional>
#include <memory>
#include <log/log.h>
#include <log/log_read.h>
@ -62,6 +63,7 @@ class LogBuffer {
const char* msg, uint16_t len) = 0;
virtual std::unique_ptr<FlushToState> CreateFlushToState(uint64_t start, LogMask log_mask) = 0;
virtual void DeleteFlushToState(std::unique_ptr<FlushToState>) {}
virtual bool FlushTo(
LogWriter* writer, FlushToState& state,
const std::function<FilterResult(log_id_t log_id, pid_t pid, uint64_t sequence,

View file

@ -72,6 +72,7 @@ void LogReaderThread::ThreadFunction() {
[this](log_id_t log_id, pid_t pid, uint64_t sequence, log_time realtime) {
return FilterFirstPass(log_id, pid, sequence, realtime);
});
log_buffer_->DeleteFlushToState(std::move(first_pass_state));
}
bool flush_success = log_buffer_->FlushTo(
writer_.get(), *flush_to_state_,
@ -105,6 +106,10 @@ void LogReaderThread::ThreadFunction() {
}
}
lock.unlock();
log_buffer_->DeleteFlushToState(std::move(flush_to_state_));
lock.lock();
writer_->Release();
auto& log_reader_threads = reader_list_->reader_threads();

View file

@ -53,7 +53,7 @@ class LogReaderThread {
bool IsWatching(log_id_t id) const { return flush_to_state_->log_mask() & (1 << id); }
bool IsWatchingMultiple(LogMask log_mask) const {
return flush_to_state_->log_mask() & log_mask;
return flush_to_state_ && flush_to_state_->log_mask() & log_mask;
}
std::string name() const { return writer_->name(); }

View file

@ -201,6 +201,11 @@ std::unique_ptr<FlushToState> SerializedLogBuffer::CreateFlushToState(uint64_t s
return std::make_unique<SerializedFlushToState>(start, log_mask);
}
void SerializedLogBuffer::DeleteFlushToState(std::unique_ptr<FlushToState> state) {
auto lock = std::unique_lock{lock_};
state.reset();
}
bool SerializedLogBuffer::FlushTo(
LogWriter* writer, FlushToState& abstract_state,
const std::function<FilterResult(log_id_t log_id, pid_t pid, uint64_t sequence,

View file

@ -42,6 +42,7 @@ class SerializedLogBuffer final : public LogBuffer {
int Log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, const char* msg,
uint16_t len) override;
std::unique_ptr<FlushToState> CreateFlushToState(uint64_t start, LogMask log_mask) override;
void DeleteFlushToState(std::unique_ptr<FlushToState> state) override;
bool FlushTo(LogWriter* writer, FlushToState& state,
const std::function<FilterResult(log_id_t log_id, pid_t pid, uint64_t sequence,
log_time realtime)>& filter) override;