public ConcurrentPool(Func <T> itemFactory, int capacity, int counterApproximationFactor) { Capacity = capacity; _count = new StochasticCounter(counterApproximationFactor); _queue = new ConcurrentQueue <T>(); _itemFactory = itemFactory ?? throw new ArgumentNullException(nameof(itemFactory)); }
public ReplicaRegistry(Options?options = null) { options ??= new Options(); _handles = new ConcurrentDictionary <PublicationRef, GCHandle>(options.ConcurrencyLevel, options.InitialCapacity); _opCounter = new StochasticCounter(1); _gcHandlePool = options.GCHandlePool ?? new GCHandlePool(GCHandleType.Weak); if (_gcHandlePool.HandleType != GCHandleType.Weak) { throw new ArgumentOutOfRangeException( $"{nameof(options)}.{nameof(options.GCHandlePool)}.{nameof(_gcHandlePool.HandleType)}"); } UpdatePruneCounterThreshold(); }
public ComputedRegistry(Options?options = null) { options = options.OrDefault(); _storage = new ConcurrentDictionary <ComputedInput, GCHandle>(options.ConcurrencyLevel, options.InitialCapacity); var locksProvider = options.LocksProvider; if (locksProvider == null) { var locks = new AsyncLockSet <ComputedInput>(ReentryMode.CheckedFail); locksProvider = _ => locks; } _locksProvider = locksProvider; _gcHandlePool = options.GCHandlePool ?? new GCHandlePool(GCHandleType.Weak); if (_gcHandlePool.HandleType != GCHandleType.Weak) { throw new ArgumentOutOfRangeException( $"{nameof(options)}.{nameof(options.GCHandlePool)}.{nameof(_gcHandlePool.HandleType)}"); } _opCounter = new StochasticCounter(); UpdatePruneCounterThreshold(); }