Beispiel #1
0
 protected override void Dispose(bool explicitDispose)
 {
     if (explicitDispose)
     {
         _runControl?.Dispose();
         _postingCts?.Dispose();
         var postingQueueSpinLock = _postingQueueSpinLock;
         if (postingQueueSpinLock != null)
         {
             postingQueueSpinLock.Invoke(() => _postingQueue.Fluent().NullCond(x => x.ToList()))
             .Fluent().NullCond(postingQueueCopy => postingQueueCopy.DisposeMany());
             postingQueueSpinLock.Invoke(() => _postingQueue.Fluent().NullCond(x => x.Clear()));
         }
         var subscriptionsSpinLock = _subscriptionsSpinLock;
         if (subscriptionsSpinLock != null)
         {
             subscriptionsSpinLock.Invoke(() => _subscriptionsList.Fluent().NullCond(x => x.ToList()))
             .Fluent().NullCond(subscriptionsListCopy => subscriptionsListCopy.Where(i => (i.State & LocalSubscriptionStates.PublisherOwnsSubscription) == LocalSubscriptionStates.PublisherOwnsSubscription).DisposeMany());
             subscriptionsSpinLock.Invoke(() => _subscriptionsList.Fluent().NullCond(x => x.Clear()));
             subscriptionsSpinLock.Invoke(() => _subscriptionsDictionary.Fluent().NullCond(x => x.Clear()));
         }
         _postingWorkers.DisposeAndClearArray();
     }
     _postingQueue            = null;
     _postingQueueSpinLock    = null;
     _postingWorkers          = null;
     _runningSettings         = null;
     _subscriptionsDictionary = null;
     _subscriptionsList       = null;
     _subscriptionsSpinLock   = null;
     _runControl = null;
     _postingCts = null;
     //
     base.Dispose(explicitDispose);
 }
Beispiel #2
0
 static MetadataPathName()
 {
     __ComponentDelimiterAsString = new string(ComponentDelimiter, 1);
     Regex           = new Regex(pattern: RegexPattern, options: RegexOptions.Compiled);
     __CacheSpinLock = new PrimitiveSpinLock();
     __Cache         = new Dictionary <string, MetadataPathName>(StringComparer.Ordinal);
 }
Beispiel #3
0
 protected override void Dispose(bool explicitDispose)
 {
     if (explicitDispose)
     {
         _newDependencyInstancesDisposeRegistry?.Dispose();
         //
         _runningResolutionsSpinLock?.EnterAndExitLock();
         _runningResolutionsUniqueness?.Clear();
         _runningResolutionsSequence?.Clear();
         //
         _resolutionModelLazy?.Dispose();
         //
         _exporter?.Dispose();
         //
         _outerScopeGetter?.Dispose();
     }
     _newDependencyInstancesDisposeRegistry = null;
     _runningResolutionsUniqueness          = null;
     _runningResolutionsSequence            = null;
     _runningResolutionsSpinLock            = null;
     _resolutionModelLazy = null;
     _exporter            = null;
     _outerScopeGetter    = null;
     _serviceProviderApi  = null;
     _owner = null;
     //
     base.Dispose(explicitDispose);
 }
Beispiel #4
0
 static DependencyScope()
 {
     DefaultOfMaxCountOfRunningResolutions = Math.Min(Math.Max(24, Environment.ProcessorCount), 48);
     DefaultOfMaxCountOfResolutionRedirect = 16;
     __ResolveDependencyInvokeRepoSpinLock = new PrimitiveSpinLock();
     __ResolveDependencyInvokers           = new Dictionary <Type, P_ResolveDependencyInvokerBase>();
 }
Beispiel #5
0
 public DisposeRegistry(int cleanupThreshold = default)
 {
     cleanupThreshold.Arg(nameof(cleanupThreshold)).EnsureNotLessThanZero();
     //
     _disposablesSpinLock      = new PrimitiveSpinLock();
     _disposableWeakReferences = new List <StrictedWeakReference>();
     _cleanupThreshold         = cleanupThreshold == default ? __DefaultCleanupThreshold : cleanupThreshold;
 }
Beispiel #6
0
 public TaskWrap(Task <TResult> task)
 {
     task.EnsureNotNull(nameof(task));
     //
     _innerTask              = task;
     _convertedTasks         = new Dictionary <Type, Task>(capacity: 4);
     _convertedTasksSpinLock = new PrimitiveSpinLock(name: $"{nameof(TaskWrap<TResult>)}[{__ResultType.FullName}]");
 }
Beispiel #7
0
 protected MetadataTreeStructureContainerBase(TOwner ownerComponent)
 {
     ownerComponent.EnsureNotNull(nameof(ownerComponent));
     //
     _ownerComponent    = ownerComponent;
     _innerListSpinLock = new PrimitiveSpinLock();
     _innerList         = new LinkedList <TComponent>();
 }
Beispiel #8
0
 public DisposeRegistry(IEnumerable <IDisposable> disposables, int cleanupThreshold = default)
 {
     cleanupThreshold.Arg(nameof(cleanupThreshold)).EnsureNotLessThanZero();
     //
     _disposablesSpinLock      = new PrimitiveSpinLock();
     _disposableWeakReferences = new List <StrictedWeakReference>(collection: disposables.EmptyIfNull().SkipNull().Select(locItem => new StrictedWeakReference(target: locItem, trackResurrection: false)));
     _cleanupThreshold         = cleanupThreshold == default ? __DefaultCleanupThreshold : cleanupThreshold;
 }
Beispiel #9
0
        static DisposableImplementation()
        {
#if DEBUG
            __Counters         = new Dictionary <Type, P_Counters>();
            __CountersSpinLock = new PrimitiveSpinLock();
#else
            __Counters = new P_Counters();
#endif
        }
Beispiel #10
0
        internal LocalPostingQueueEntry(LocalPostingToken postingToken, IEnumerable <ILocalSubscription> postingSubscriptions)
        {
            postingToken.EnsureNotNull(nameof(postingToken));
            var locPostingSubscriptions = postingSubscriptions.EnsureNotNull(nameof(postingSubscriptions)).EnsureNoNullElements().Value.ToList();

            //
            _postingToken                 = postingToken;
            _postingSubscriptions         = locPostingSubscriptions;
            _postingSubscriptionsSpinLock = new PrimitiveSpinLock();
        }
Beispiel #11
0
 static XFullCorrelationId()
 {
     __ComponentDelimiterAsString = new string(c : ComponentDelimiter, count : 1);
     __CacheSpinLock = new PrimitiveSpinLock();
     __Cache         = new Dictionary <string, XFullCorrelationId>(StringComparer.Ordinal);
     __UseCache      = false;
     RegexPattern    = @"^(([\p{L}\p{Nd}_\-]{1,36}){1}(\.[\p{L}\p{Nd}_\-]{1,36}){0,127})$";
     Regex           = new Regex(pattern: RegexPattern, options: RegexOptions.Compiled);
     AppDomain       = XCorrelationId.New();
 }
Beispiel #12
0
 protected override void Dispose(bool explicitDispose)
 {
     if (explicitDispose)
     {
         _strictedCtxsSpinLock?.EnterAndExitLock();
         _strictedCtxs?.Values.Observe(action: locValue => locValue?.Dispose());
         _strictedCtxs?.Clear();
     }
     _strictedCtxs         = null;
     _strictedCtxsSpinLock = null;
     //
     base.Dispose(explicitDispose);
 }
Beispiel #13
0
 protected override void Dispose(bool explicitDispose)
 {
     if (explicitDispose)
     {
         _exportersSpinLock?.EnterAndExitLock();
         _exporters?.Observe(i => i.Value.Dispose());
         _exporters?.Clear();
     }
     _exporters         = null;
     _exportersSpinLock = null;
     //
     base.Dispose(explicitDispose);
 }
Beispiel #14
0
        public DependencyResolutionContext(IDependencyScope scope, IDependencyResolutionSpecs specs, bool ownsSpecs = default, bool?isAdvancedLoggingEnabled = default)
        {
            scope.EnsureNotNull(nameof(scope));
            specs.EnsureNotNull(nameof(specs));
            //
            _sequentialId            = DependencyUtilities.NextResolutionContextSequentialId();
            _scope                   = scope;
            _specs                   = specs.ToValueHolder(ownsValue: ownsSpecs);
            _involvedHandlerCounters = new Dictionary <IDependencyHandler2, int>(comparer: ReferenceEqualityComparer <IDependencyHandler2> .Instance);
            _involvedHandlerChain    = new List <IDependencyHandler2>();
            _involvedHandlerSpinLock = new PrimitiveSpinLock();
            //
            var resolutionSettings = DependencyUtilities.DefaultResolutionSettings;

            _usageCountLimitPerHandler = resolutionSettings.UsageCountLimitPerHandler;
            _isAdvancedLoggingEnabled  = isAdvancedLoggingEnabled ?? resolutionSettings.IsAdvancedLoggingEnabled;
        }
Beispiel #15
0
 protected override void Dispose(bool explicitDispose)
 {
     if (explicitDispose)
     {
         _specs?.Dispose();
         _involvedHandlerSpinLock?.EnterAndExitLock();
         _involvedHandlerChain?.Clear();
         _involvedHandlerCounters?.Clear();
     }
     _involvedHandlerCounters = null;
     _involvedHandlerChain    = null;
     _involvedHandlerSpinLock = null;
     _scope = null;
     _specs = null;
     //
     base.Dispose(explicitDispose);
 }
Beispiel #16
0
 internal LocalPostingWorker(
     Queue <LocalPostingQueueEntry> queue,
     PrimitiveSpinLock queueSpinLock,
     CancellationToken cancellationToken)
 {
     //
     queue.EnsureNotNull(nameof(queue));
     queueSpinLock.EnsureNotNull(nameof(queueSpinLock));
     cancellationToken.EnsureNotEmpty(nameof(cancellationToken));
     //
     _queue                   = queue;
     _queueSpinLock           = queueSpinLock;
     _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
     _breakLoopIdleEvent      = new AutoResetEvent(initialState: false);
     _isLoopIdling            = 0;
     _isLoopAlive             = 0;
     _runControl              = new RunControl <LocalPostingWorker>(options: RunControlOptions.SingleStart, component: this, start: P_DoStartAsync, stop: P_DoStopAsync);
 }
Beispiel #17
0
 public LocalPublisher(ILocalPublisherSettings settings)
 {
     settings.EnsureNotNull(nameof(settings)).EnsureReadOnly().EnsureValid().EnsureNotDisabled();
     //
     _runningSettings         = settings;
     _subscriptionsSpinLock   = new PrimitiveSpinLock();
     _subscriptionsList       = new List <ILocalSubscription>();
     _subscriptionsDictionary = new Dictionary <ILocalSubscription, P_NewSubscriptionRegistrationState>();
     _postingQueue            = new Queue <LocalPostingQueueEntry>();
     _postingQueueSpinLock    = new PrimitiveSpinLock();
     _postingCts     = new CancellationTokenSource();
     _postingWorkers =
         EnumerableUtilities
         .CreateSequence(
             factory: locIndex => new LocalPostingWorker(queue: _postingQueue, queueSpinLock: _postingQueueSpinLock, cancellationToken: _postingCts.Token),
             length: _runningSettings.PostingDop)
         .ToArray();
     _runControl = new RunControl <LocalPublisher>(options: RunControlOptions.SingleStart, component: this, start: P_DoStartAsync, stop: P_DoStopAsync);
 }
Beispiel #18
0
 void P_CtorInitializer(IDependencyExporter exporter, bool ownsDependencyExporter = default, IServiceProvider outerServiceProvider = default, object owner = default)
 {
     exporter.EnsureNotNull(nameof(exporter));
     //
     _exporter = exporter.ToValueHolder(ownsDependencyExporter);
     _owner    = owner;
     //
     _resolutionModelLazy =
         new DisposableLazy <IDependencyResolutionModel <DependencyScope> >(
             factory: () => new DependencyResolutionModel <DependencyScope>(scope: this, handlerChainSource: ReadDA(ref _exporter, considerDisposeRequest: true).Value.ExportDependencies()),
             ownsValue: true);
     //
     _newDependencyInstancesDisposeRegistry = new DisposeRegistry();
     //
     _runningResolutionsSpinLock   = new PrimitiveSpinLock();
     _runningResolutionsUniqueness = new HashSet <IDependencyResolutionContext>(comparer: ReferenceEqualityComparer <IDependencyResolutionContext> .Instance);
     _runningResolutionsSequence   = new List <IDependencyResolutionContext>();
     //
     _serviceProviderApi = outerServiceProvider ?? new P_ServiceProviderApi(scope: this);
 }
Beispiel #19
0
 protected override void Dispose(bool explicitDispose)
 {
     if (explicitDispose)
     {
         _innerListSpinLock?.EnterAndExitLock();
         //
         var innerList = _innerList;
         if (innerList != null)
         {
             var innerListNode = innerList.First;
             for (; innerListNode != null;)
             {
                 innerListNode.Value?.Dispose();
                 innerListNode = innerListNode.Next;
             }
         }
         _innerList?.Clear();
     }
     _innerList         = null;
     _innerListSpinLock = null;
     _ownerComponent    = null;
     //
     base.Dispose(explicitDispose);
 }
Beispiel #20
0
 public GarbageCollectionTracking()
 {
     _referencesRepo         = new ConditionalWeakTable <TInstance, P_DestroyHnd>();
     _referencesRepoSpinLock = new PrimitiveSpinLock();
     _registeredCounter      = 0L;
 }
Beispiel #21
0
 static Leasable()
 {
     __CollectionRepo         = new List <WeakReference <Leasable> >();
     __CollectionRepoSpinLock = new PrimitiveSpinLock();
 }
Beispiel #22
0
 public DefaultDescriptionPackageService()
 {
     _loadedPackagesSpinLock = new PrimitiveSpinLock();
     _loadedPackages         = new Dictionary <DescriptionPackageLocator, P_LoadedPackageState>(comparer: DescriptionPackageLocator.PackageNameEqualityComparer);
 }
Beispiel #23
0
 static ValueHolderUtilities()
 {
     __VhFactoriesSpinLock = new PrimitiveSpinLock();
     __VhFactories         = new Dictionary <Type, Delegate>();
 }
Beispiel #24
0
 static DisposableLazy()
 {
     __ValueCreationCallCounters         = new Dictionary <object, P_ValueCreationCallCounterState>(comparer: ReferenceEqualityComparer <object> .Instance);
     __ValueCreationCallCountersSpinLock = new PrimitiveSpinLock();
 }
Beispiel #25
0
        public static TValue GetOrDefault <TKey, TValue>(this IDictionary <TKey, TValue> dictionary, PrimitiveSpinLock spinLock, TKey key)
        {
            dictionary.EnsureNotNull(nameof(dictionary));
            spinLock.EnsureNotNull(nameof(spinLock));
            //
            var value = default(TValue);

            return(spinLock.Invoke(() => dictionary.TryGetValue(key, out value)) ? value : default);
Beispiel #26
0
 static NewInstanceDependencyTarget()
 {
     __DefaultHandlersSpinLock = new PrimitiveSpinLock();
     __DefaultHandlers         = new Dictionary <TypeTubple6, DisposableLazy <IFactoryDependencyHandler> >();
 }
Beispiel #27
0
 static EnumUtilities()
 {
     __EnumTypeApiCache         = new Dictionary <Type, P_EnumTypeApi>();
     __EnumTypeApiCacheSpinLock = new PrimitiveSpinLock();
 }
Beispiel #28
0
 public MetadataDependencyExporterBuilder()
 {
     _exporters         = new Dictionary <IMetadata, P_MetadataDependencyExporter>();
     _exportersSpinLock = new PrimitiveSpinLock();
 }
Beispiel #29
0
 public CompiledLambdaExpressionCache()
 {
     _spinLock = new PrimitiveSpinLock();
     _methodCallCacheEntries = new Dictionary <MethodInfo, P_CacheEntryBase>();
 }
Beispiel #30
0
 static ResourceUtilities()
 {
     __StringResourcesRepoSpinLock = new PrimitiveSpinLock();
     __StringResourcesRepo         = new Dictionary <StringResourcesRepoKey, DisposableLazy <string> >();
 }