From b7203e853e3b928e1a7fb081fce379f023e935bb Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 4 Jul 2017 16:26:48 +0200 Subject: getDefaultSubstituters(): Simplify initialisation As shlevy pointed out, static variables in C++11 have thread-safe initialisation. --- src/libstore/store-api.cc | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'src/libstore/store-api.cc') diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index d7b784cfb..db2e023ab 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -795,33 +795,27 @@ static RegisterStoreImplementation regStore([]( std::list> getDefaultSubstituters() { - struct State { - bool done = false; + static auto stores([]() { std::list> stores; - }; - static Sync 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; } -- cgit v1.2.3