public void AddAdditionalAsset(Asset asset, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); LazyInitialization.EnsureInitialized(ref _additionalAssets, s_additionalAssetsCreator); _additionalAssets.TryAdd(asset.Checksum, asset); }
public void AddAdditionalAsset(Asset asset, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); LazyInitialization.EnsureInitialized(ref _additionalAssets, () => new ConcurrentDictionary <Checksum, Asset>(concurrencyLevel: 2, capacity: 10)); _additionalAssets.TryAdd(asset.Checksum, asset); }
public void AddOrReplace(int key, TriviaData triviaInfo) { // PERF: Set the concurrency level to 1 because, while the dictionary has to be thread-safe, // there is very little contention in formatting. A lower concurrency level reduces object // allocations which are used internally by ConcurrentDictionary for locking. var map = LazyInitialization.EnsureInitialized(ref _map, () => new ConcurrentDictionary <int, TriviaData>(concurrencyLevel: 1, capacity: 8)); map[key] = triviaInfo; }
private ProjectId?GetOriginatingProjectIdWorker(ISymbol symbol) { LazyInitialization.EnsureInitialized(ref _unrootedSymbolToProjectId, s_createTable); // Walk up the symbol so we can get to the containing namespace/assembly that will be used to map // back to a project. while (symbol != null) { var result = GetProjectIdDirectly(symbol, _unrootedSymbolToProjectId); if (result != null) { return(result); } symbol = symbol.ContainingSymbol; } return(null); }
private AsyncLazy <TRoot> GetAsyncLazyRoot() { return(LazyInitialization.EnsureInitialized(ref lazyRoot, rootFactory, this)); }
public void AddAdditionalAsset(CustomAsset asset) { LazyInitialization.EnsureInitialized(ref _lazyAdditionalAssets, s_additionalAssetsCreator).TryAdd(asset.Checksum, asset); }
static void Main() { LazyInitialization li = new LazyInitialization(); string s = li.AlsoPopulatedOnDemand; int i = li.PopulatedOnDemand; }