Make adding crash keys thread safe

Bug: chromium:977893
Change-Id: Ibd4be9b9ce13bcb8aca4b6ac6d7a1c56a01e39d9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1676606
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Irina Yatsenko <irinayat@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#62392}
This commit is contained in:
Irina Yatsenko 2019-06-25 10:50:47 -07:00 committed by Commit Bot
parent b2d47f24d2
commit 6056c0dc4a

View File

@ -33,7 +33,9 @@ static CrashKeyInstance crash_keys[] = {
};
void AddCrashKey(int id, const char* name, uintptr_t value) {
static int current = 0;
static std::atomic<int> last{-1};
const int current = ++last;
if (current > kMaxCrashKeysCount) {
return;
}
@ -41,7 +43,6 @@ void AddCrashKey(int id, const char* name, uintptr_t value) {
if (current == kMaxCrashKeysCount) {
static crash_reporter::CrashKeyString<1> over("v8-too-many-keys");
over.Set("1");
current++;
return;
}
@ -50,8 +51,6 @@ void AddCrashKey(int id, const char* name, uintptr_t value) {
std::stringstream stream;
stream << name << " " << id << " 0x" << std::hex << value;
trace_key.Set(stream.str().substr(0, kKeySize));
current++;
}
} // namespace crash