mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 02:36:16 +02:00
Simplify getRootCgroup()
Static local initializers are atomic in C++.
This commit is contained in:
parent
4c88deef38
commit
03484641a1
1 changed files with 2 additions and 15 deletions
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <mutex>
|
||||
#include <regex>
|
||||
#include <unordered_set>
|
||||
#include <thread>
|
||||
|
@ -158,22 +157,10 @@ std::string getCurrentCgroup()
|
|||
return ourCgroup;
|
||||
}
|
||||
|
||||
static std::optional<std::string> rootCgroup;
|
||||
static std::mutex rootCgroupMutex;
|
||||
|
||||
std::string getRootCgroup()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(rootCgroupMutex);
|
||||
if (rootCgroup)
|
||||
return *rootCgroup;
|
||||
}
|
||||
auto current = getCurrentCgroup();
|
||||
std::lock_guard<std::mutex> guard(rootCgroupMutex);
|
||||
if (rootCgroup)
|
||||
return *rootCgroup;
|
||||
rootCgroup = current;
|
||||
return current;
|
||||
static std::string rootCgroup = getCurrentCgroup();
|
||||
return rootCgroup;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue