mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 10:46:15 +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 <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <mutex>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
@ -158,22 +157,10 @@ std::string getCurrentCgroup()
|
||||||
return ourCgroup;
|
return ourCgroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::optional<std::string> rootCgroup;
|
|
||||||
static std::mutex rootCgroupMutex;
|
|
||||||
|
|
||||||
std::string getRootCgroup()
|
std::string getRootCgroup()
|
||||||
{
|
{
|
||||||
{
|
static std::string rootCgroup = getCurrentCgroup();
|
||||||
std::lock_guard<std::mutex> guard(rootCgroupMutex);
|
return rootCgroup;
|
||||||
if (rootCgroup)
|
|
||||||
return *rootCgroup;
|
|
||||||
}
|
|
||||||
auto current = getCurrentCgroup();
|
|
||||||
std::lock_guard<std::mutex> guard(rootCgroupMutex);
|
|
||||||
if (rootCgroup)
|
|
||||||
return *rootCgroup;
|
|
||||||
rootCgroup = current;
|
|
||||||
return current;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue