mirror of
https://github.com/chromium/crashpad.git
synced 2025-01-14 09:17:57 +08:00
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:
parent
7c30a508eb
commit
21546d8514
@ -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_;
|
||||
};
|
||||
|
||||
|
@ -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_() {}
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user