aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/experimental-features.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-10-26 14:29:48 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-10-26 14:29:48 +0200
commit0d9e050ba719515620a2e320a7b6bba35f1d1df6 (patch)
treeb3ea26f0fba4c1ab0e969bffe6ec5a25de6852b1 /src/libutil/experimental-features.cc
parent9ce84c64c5820847a8084f31da5c5e2f549cbbcf (diff)
parseExperimentalFeature(): Initialize atomically
Diffstat (limited to 'src/libutil/experimental-features.cc')
-rw-r--r--src/libutil/experimental-features.cc20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/libutil/experimental-features.cc b/src/libutil/experimental-features.cc
index d1235d8a4..b49f47e1d 100644
--- a/src/libutil/experimental-features.cc
+++ b/src/libutil/experimental-features.cc
@@ -1,4 +1,6 @@
#include "experimental-features.hh"
+#include "util.hh"
+
#include "nlohmann/json.hpp"
namespace nix {
@@ -14,17 +16,19 @@ std::map<ExperimentalFeature, std::string> stringifiedXpFeatures = {
const std::optional<ExperimentalFeature> parseExperimentalFeature(const std::string_view & name)
{
using ReverseXpMap = std::map<std::string_view, ExperimentalFeature>;
- static ReverseXpMap * reverseXpMap;
- if (!reverseXpMap) {
- reverseXpMap = new ReverseXpMap{};
+
+ static auto reverseXpMap = []()
+ {
+ auto reverseXpMap = std::make_unique<ReverseXpMap>();
for (auto & [feature, name] : stringifiedXpFeatures)
(*reverseXpMap)[name] = feature;
- }
+ return reverseXpMap;
+ }();
- auto featureIter = reverseXpMap->find(name);
- if (featureIter == reverseXpMap->end())
+ if (auto feature = get(*reverseXpMap, name))
+ return *feature;
+ else
return std::nullopt;
- return {featureIter->second};
}
std::string_view showExperimentalFeature(const ExperimentalFeature feature)
@@ -45,7 +49,7 @@ std::set<ExperimentalFeature> parseFeatures(const std::set<std::string> & rawFea
MissingExperimentalFeature::MissingExperimentalFeature(ExperimentalFeature feature)
: Error("experimental Nix feature '%1%' is disabled; use '--extra-experimental-features %1%' to override", showExperimentalFeature(feature))
, missingFeature(feature)
- {}
+{}
std::ostream & operator <<(std::ostream & str, const ExperimentalFeature & feature)
{