Commit 6101e9c2 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[logging] Move first IsEnabled() check into NewMessageBuilder()

IsEnabled() is checked before and after taking the lock. Move the first
check into NewMessageBuilder() to make this more obvious to the reader.

Bug: v8:10315
Change-Id: Iee1000a209f3ae7d07884f1cbb4e0daf43a58a9f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2414227Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69968}
parent 5eeea05d
...@@ -72,11 +72,15 @@ void Log::WriteLogHeader() { ...@@ -72,11 +72,15 @@ void Log::WriteLogHeader() {
} }
std::unique_ptr<Log::MessageBuilder> Log::NewMessageBuilder() { std::unique_ptr<Log::MessageBuilder> Log::NewMessageBuilder() {
// Fast check of IsEnabled() without taking the lock. Bail out immediately if
// logging isn't enabled.
if (!IsEnabled()) return {};
std::unique_ptr<Log::MessageBuilder> result(new Log::MessageBuilder(this)); std::unique_ptr<Log::MessageBuilder> result(new Log::MessageBuilder(this));
// Need to check here whether log is still enabled while the mutex is locked // The first invocation of IsEnabled() might still read an old value. It is
// by Log::MessageBuilder. In case IsEnabled() is checked before locking the // fine if a background thread starts logging a bit later, but we want to
// mutex we could still read an old value. // avoid background threads continue logging after logging was closed.
if (!IsEnabled()) return {}; if (!IsEnabled()) return {};
return result; return result;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment