Use call_once in lazy settings load.

This fixes a test case that accesses settings for the first time in
multiple threads simultaneously.

Fixed: crashpad:417
Change-Id: I6539682f171563f8ff5a1203fdd550ab92afc276
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3711807
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
This commit is contained in:
Justin Cohen 2022-06-22 12:22:26 -04:00 committed by Crashpad LUCI CQ
parent 7c30a508eb
commit 21546d8514
3 changed files with 14 additions and 11 deletions

View File

@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <mutex>
#include <tuple>
#include <utility>
@ -258,15 +259,15 @@ class CrashReportDatabaseGeneric : public CrashReportDatabase {
static bool WriteMetadata(const base::FilePath& path, const Report& report);
Settings& SettingsInternal() {
if (!settings_init_)
std::call_once(settings_init_, [this]() {
settings_.Initialize(base_dir_.Append(kSettings));
settings_init_ = true;
});
return settings_;
}
base::FilePath base_dir_;
Settings settings_;
bool settings_init_ = false;
std::once_flag settings_init_;
InitializationStateDcheck initialized_;
};

View File

@ -27,6 +27,7 @@
#include <array>
#include <iterator>
#include <mutex>
#include <tuple>
#include "base/logging.h"
@ -263,15 +264,15 @@ class CrashReportDatabaseMac : public CrashReportDatabase {
void CleanOrphanedAttachments();
Settings& SettingsInternal() {
if (!settings_init_)
std::call_once(settings_init_, [this]() {
settings_.Initialize(base_dir_.Append(kSettings));
settings_init_ = true;
});
return settings_;
}
base::FilePath base_dir_;
Settings settings_;
bool settings_init_;
std::once_flag settings_init_;
bool xattr_new_names_;
InitializationStateDcheck initialized_;
};
@ -280,7 +281,7 @@ CrashReportDatabaseMac::CrashReportDatabaseMac(const base::FilePath& path)
: CrashReportDatabase(),
base_dir_(path),
settings_(),
settings_init_(false),
settings_init_(),
xattr_new_names_(false),
initialized_() {}

View File

@ -21,6 +21,7 @@
#include <time.h>
#include <wchar.h>
#include <mutex>
#include <tuple>
#include <utility>
@ -663,15 +664,15 @@ class CrashReportDatabaseWin : public CrashReportDatabase {
std::unique_ptr<Metadata> AcquireMetadata();
Settings& SettingsInternal() {
if (!settings_init_)
std::call_once(settings_init_, [this]() {
settings_.Initialize(base_dir_.Append(kSettings));
settings_init_ = true;
});
return settings_;
}
base::FilePath base_dir_;
Settings settings_;
bool settings_init_;
std::once_flag settings_init_;
InitializationStateDcheck initialized_;
};
@ -679,7 +680,7 @@ CrashReportDatabaseWin::CrashReportDatabaseWin(const base::FilePath& path)
: CrashReportDatabase(),
base_dir_(path),
settings_(),
settings_init_(false),
settings_init_(),
initialized_() {}
CrashReportDatabaseWin::~CrashReportDatabaseWin() {