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()
 | 
					std::list<ref<Store>> getDefaultSubstituters()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    struct State {
 | 
					    static auto stores([]() {
 | 
				
			||||||
        bool done = false;
 | 
					 | 
				
			||||||
        std::list<ref<Store>> 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) {
 | 
					        auto addStore = [&](const std::string & uri) {
 | 
				
			||||||
            if (done.count(uri)) return;
 | 
					            if (done.count(uri)) return;
 | 
				
			||||||
            done.insert(uri);
 | 
					            done.insert(uri);
 | 
				
			||||||
        state->stores.push_back(openStore(uri));
 | 
					            stores.push_back(openStore(uri));
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (auto uri : settings.substituters.get())
 | 
					        for (auto uri : settings.substituters.get())
 | 
				
			||||||
| 
						 | 
					@ -819,9 +812,10 @@ std::list<ref<Store>> getDefaultSubstituters()
 | 
				
			||||||
        for (auto uri : settings.extraSubstituters.get())
 | 
					        for (auto uri : settings.extraSubstituters.get())
 | 
				
			||||||
            addStore(uri);
 | 
					            addStore(uri);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    state->done = true;
 | 
					        return stores;
 | 
				
			||||||
 | 
					    } ());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return state->stores;
 | 
					    return stores;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue