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();
 }
Beispiel #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();
        }
Beispiel #3
0
 // プール経由で開放する
 public void Dispose()
 {
     GCHandlePool.Release(handle);
     handle = default;
 }
Beispiel #4
0
 // Pool経由で作成する
 public void Create(T value)
 {
     handle = GCHandlePool.Create(value);
 }