about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-07-04T14·26+0200
committerEelco Dolstra <edolstra@gmail.com>2017-07-04T14·26+0200
commitb7203e853e3b928e1a7fb081fce379f023e935bb (patch)
tree3f84414efd9ea2a00e392aad9e636a56c575b14d
parent6cf23c3e8fa12e6bf297ca87d1b47889bf115d52 (diff)
getDefaultSubstituters(): Simplify initialisation
As shlevy pointed out, static variables in C++11 have thread-safe
initialisation.
-rw-r--r--src/libstore/store-api.cc34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index d7b784cfbc20..db2e023ab0bf 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -795,33 +795,27 @@ static RegisterStoreImplementation regStore([](
 
 std::list<ref<Store>> getDefaultSubstituters()
 {
-    struct State {
-        bool done = false;
+    static auto stores([]() {
         std::list<ref<Store>> stores;
-    };
-    static Sync<State> state_;
-
-    auto state(state_.lock());
 
-    if (state->done) return state->stores;
+        StringSet done;
 
-    StringSet done;
-
-    auto addStore = [&](const std::string & uri) {
-        if (done.count(uri)) return;
-        done.insert(uri);
-        state->stores.push_back(openStore(uri));
-    };
+        auto addStore = [&](const std::string & uri) {
+            if (done.count(uri)) return;
+            done.insert(uri);
+            stores.push_back(openStore(uri));
+        };
 
-    for (auto uri : settings.substituters.get())
-        addStore(uri);
+        for (auto uri : settings.substituters.get())
+            addStore(uri);
 
-    for (auto uri : settings.extraSubstituters.get())
-        addStore(uri);
+        for (auto uri : settings.extraSubstituters.get())
+            addStore(uri);
 
-    state->done = true;
+        return stores;
+    } ());
 
-    return state->stores;
+    return stores;
 }