Ejemplo n.º 1
0
 public Entry(AsyncLockSet <TKey> owner, TKey key)
 {
     _owner     = owner;
     _key       = key;
     _lease     = owner._lockPool.Rent();
     _asyncLock = _lease.Resource;
 }
Ejemplo n.º 2
0
        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();
        }