< Summary

Information
Class: CounterpointCollective.Collections.CoalescingQueueNode<T1, T2>
Assembly: CounterpointCollective.CoalescingQueue
File(s): /builds/counterpointcollective/prestoprimitives/CoalescingQueue/Collections/CoalescingQueueNode.cs
Line coverage
91%
Covered lines: 11
Uncovered lines: 1
Coverable lines: 12
Total lines: 72
Line coverage: 91.6%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
MarkForDispatch()100%11100%
get_Value()100%11100%
Dispose()75%4485.71%

File(s)

/builds/counterpointcollective/prestoprimitives/CoalescingQueue/Collections/CoalescingQueueNode.cs

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2
 3namespace CounterpointCollective.Collections
 4{
 5    /// <summary>
 6    /// Represents a node in a <see cref="CoalescingQueue"/> for an item of type <typeparamref name="TValue"/>.
 7    /// </summary>
 8    /// <typeparam name="TValue">The type of the item managed by this queue node.</typeparam>
 9    public readonly ref struct CoalescingQueueNode<TContainer, TValue> where TContainer : struct
 10    {
 11        private readonly ref QueueEntry<TContainer> _entry;
 12        private readonly RawValueProvider<TContainer, TValue> _valueProvider;
 13
 14        internal CoalescingQueueNode(StructQueue<QueueEntry<TContainer>>.Handle inner, RawValueProvider<TContainer, TVal
 15        {
 119983416            _valueProvider = valueProvider;
 119983417            _entry = ref inner.GetRef();
 119983418        }
 19
 20        /// <summary>
 21        /// Causes the value to be dispatched after <see cref="Dispose"/> is called.
 22        /// </summary>
 23        public void MarkForDispatch()
 209921124            => _entry.MarkedForDispatch = true;
 25
 26        /// <returns>
 27        /// An instance of <typeparamref name="TValue"/> representing the node's value.
 28        /// </returns>
 200000729        public ref TValue Value => ref _valueProvider(ref _entry);
 30
 31        /// <summary>
 32        /// Marks this node as completed.
 33        /// </summary>
 34        /// <remarks>
 35        /// If the node's value has been claimed, calling <see cref="Dispose"/> will eventually dispatch it.
 36        /// If the value has not been claimed, nothing is dispatched.
 37        /// </remarks>
 38        public void Dispose()
 39        {
 40            //Save the reference. In case this gets recycled by the dispatcher before we hit the onCompleted call.
 119983341            var handle = _entry.Handle;
 119983342            var v = _entry.UnRef();
 119983343            if (v == 0)
 44            {
 119983145                handle.OnNodeCompleted();
 46            }
 247            else if (v < 0)
 48            {
 49#pragma warning disable CA1065 // Do not raise exceptions in unexpected locations
 050                throw new InvalidOperationException("Call Dispose exactly once on a CoalescingQueueNode");
 51#pragma warning restore CA1065 // Do not raise exceptions in unexpected locations
 52            }
 253        }
 54    }
 55
 56
 57    public struct HeapSafeCoalescingQueueNode<TContainer, TValue> where TContainer : struct
 58    {
 59        private readonly StructQueue<QueueEntry<TContainer>>.Handle _handle;
 60        private readonly RawValueProvider<TContainer, TValue> _valueProvider;
 61
 62        internal HeapSafeCoalescingQueueNode(StructQueue<QueueEntry<TContainer>>.Handle handle, RawValueProvider<TContai
 63        {
 64            _handle = handle;
 65            _valueProvider = valueProvider;
 66        }
 67
 68        public CoalescingQueueNode<TContainer, TValue> Open()
 69            => new(_handle, _valueProvider);
 70    }
 71
 72}