Exemplo n.º 1
0
        void UnregisterLinkedTokens()
        {
            var registrations = CustomInterlocked.Exchange(ref _linkedTokens, null);

            if (registrations == null)
            {
                return;
            }
            foreach (var linked in (CancellationTokenRegistration[])registrations)
            {
                linked.Dispose();
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed.TryRelaxedSet())
            {
                return;
            }

            if (handle != null)
            {
                var tmpHandle = CustomInterlocked.Exchange(ref handle, null);
                if (used > 0)
                {
                    // A tiny wait (just a few cycles normally) before releasing
                    SpinWait wait = new SpinWait();
                    while (used > 0)
                    {
                        wait.SpinOnce();
                    }
                }
                ((IDisposable)tmpHandle).Dispose();
            }
        }