Example #1
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);
Example #2
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);
 }