getDefaultSubstituters(): Simplify initialisation
As shlevy pointed out, static variables in C++11 have thread-safe initialisation.
This commit is contained in:
parent
6cf23c3e8f
commit
b7203e853e
1 changed files with 14 additions and 20 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue