getDefaultSubstituters(): Simplify initialisation

As shlevy pointed out, static variables in C++11 have thread-safe
initialisation.
This commit is contained in:
Eelco Dolstra 2017-07-04 16:26:48 +02:00
parent 6cf23c3e8f
commit b7203e853e
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -795,22 +795,15 @@ 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;
auto addStore = [&](const std::string & uri) {
if (done.count(uri)) return;
done.insert(uri);
state->stores.push_back(openStore(uri));
stores.push_back(openStore(uri));
};
for (auto uri : settings.substituters.get())
@ -819,9 +812,10 @@ std::list<ref<Store>> getDefaultSubstituters()
for (auto uri : settings.extraSubstituters.get())
addStore(uri);
state->done = true;
return stores;
} ());
return state->stores;
return stores;
}