Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3632)

Unified Diff: base/process/process_linux.cc

Issue 2736393004: base: Remove LazyInstance with AtExit from process_linux.cc (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_linux.cc
diff --git a/base/process/process_linux.cc b/base/process/process_linux.cc
index bcba9b53ca98a5b75f4711fbcd31623513016874..f98bb4c05546f9e6c1fc377826b9db1e47ba2460 100644
--- a/base/process/process_linux.cc
+++ b/base/process/process_linux.cc
@@ -60,10 +60,12 @@ struct CGroups {
foreground_type == FILE_SYSTEM_CGROUP &&
background_type == FILE_SYSTEM_CGROUP;
}
-};
-base::LazyInstance<CGroups>::DestructorAtExit g_cgroups =
- LAZY_INSTANCE_INITIALIZER;
+ static CGroups& Get() {
+ static auto& groups = *new CGroups;
+ return groups;
+ }
+};
#else
const int kBackgroundPriority = 5;
#endif // defined(OS_CHROMEOS)
@@ -87,7 +89,7 @@ struct CheckForNicePermission {
// static
bool Process::CanBackgroundProcesses() {
#if defined(OS_CHROMEOS)
- if (g_cgroups.Get().enabled)
+ if (CGroups::Get().enabled)
return true;
#endif // defined(OS_CHROMEOS)
@@ -100,7 +102,7 @@ bool Process::IsProcessBackgrounded() const {
DCHECK(IsValid());
#if defined(OS_CHROMEOS)
- if (g_cgroups.Get().enabled) {
+ if (CGroups::Get().enabled) {
// Used to allow reading the process priority from proc on thread launch.
base::ThreadRestrictions::ScopedAllowIO allow_io;
std::string proc;
@@ -119,11 +121,10 @@ bool Process::SetProcessBackgrounded(bool background) {
DCHECK(IsValid());
#if defined(OS_CHROMEOS)
- if (g_cgroups.Get().enabled) {
+ if (CGroups::Get().enabled) {
std::string pid = IntToString(process_);
- const base::FilePath file =
- background ?
- g_cgroups.Get().background_file : g_cgroups.Get().foreground_file;
+ const base::FilePath file = background ? CGroups::Get().background_file
+ : CGroups::Get().foreground_file;
return base::WriteFile(file, pid.c_str(), pid.size()) > 0;
}
#endif // defined(OS_CHROMEOS)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698