Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="ConcurrentDictionary{TKey,TValue}"/>
        /// class that is empty, has the default concurrency level, has the default initial capacity, and
        /// uses the default comparer for the key type.
        /// </summary>
        public ConcurrentDictionary(IEqualityComparer <TKey> comparer = null)
        {
            int concurrencyLevel = NativeMethodsShared.GetLogicalCoreCount();
            int capacity         = DefaultCapacity;

            // The capacity should be at least as large as the concurrency level. Otherwise, we would have locks that don't guard
            // any buckets.
            if (capacity < concurrencyLevel)
            {
                capacity = concurrencyLevel;
            }

            object[] locks = new object[concurrencyLevel];
            for (int i = 0; i < locks.Length; i++)
            {
                locks[i] = new object();
            }

            int[]  countPerLock = new int[locks.Length];
            Node[] buckets      = new Node[capacity];
            _tables = new Tables(buckets, locks, countPerLock);

            _comparer      = comparer ?? EqualityComparer <TKey> .Default;
            _growLockArray = true;
            _budget        = buckets.Length / locks.Length;
        }
Пример #2
0
 public ProjectGraph(
     IEnumerable <ProjectGraphEntryPoint> entryPoints,
     ProjectCollection projectCollection,
     ProjectInstanceFactoryFunc projectInstanceFactory)
     : this(
         entryPoints,
         projectCollection,
         projectInstanceFactory,
         NativeMethodsShared.GetLogicalCoreCount(),
         CancellationToken.None)
 {
 }
Пример #3
0
        private void SetResolverState(int submissionId, SdkResolver resolver, object state)
        {
            // Do not set state for resolution requests that are not associated with a valid build submission ID
            if (submissionId != BuildEventContext.InvalidSubmissionId)
            {
                ConcurrentDictionary <SdkResolver, object> resolverState = _resolverStateBySubmission.GetOrAdd(
                    submissionId,
                    _ => new ConcurrentDictionary <SdkResolver, object>(NativeMethodsShared.GetLogicalCoreCount(), _resolvers.Count));

                resolverState.AddOrUpdate(resolver, state, (sdkResolver, obj) => state);
            }
        }
Пример #4
0
        private void SetResolverState(int submissionId, SdkResolver resolver, object state)
        {
            // Do not set state for resolution requests that are not associated with a valid build submission ID
            if (submissionId != BuildEventContext.InvalidSubmissionId)
            {
                ConcurrentDictionary <SdkResolver, object> resolverState = _resolverStateBySubmission.GetOrAdd(
                    submissionId,
                    _ => new ConcurrentDictionary <SdkResolver, object>(
                        NativeMethodsShared.GetLogicalCoreCount(),
                        ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_4) ? _specificResolversManifestsRegistry.Count + _generalResolversManifestsRegistry.Count : _resolversList.Count));

                resolverState.AddOrUpdate(resolver, state, (sdkResolver, obj) => state);
            }
        }
Пример #5
0
        public void Translate(ITranslator translator)
        {
            IDictionary <int, BuildResult> localReference = _resultsByConfiguration;

            translator.TranslateDictionary(
                ref localReference,
                (ITranslator aTranslator, ref int i) => aTranslator.Translate(ref i),
                (ITranslator aTranslator, ref BuildResult result) => aTranslator.Translate(ref result),
                capacity => new ConcurrentDictionary <int, BuildResult>(NativeMethodsShared.GetLogicalCoreCount(), capacity));

            if (translator.Mode == TranslationDirection.ReadFromStream)
            {
                _resultsByConfiguration = (ConcurrentDictionary <int, BuildResult>)localReference;
            }
        }
 public WeakStringCache()
 {
     _stringsByHashCode = new ConcurrentDictionary <int, StringWeakHandle>(NativeMethodsShared.GetLogicalCoreCount(), _initialCapacity);
 }