Beispiel #1
0
        public bool TryGetNextCompletion(out TCompletion continuation)
        {
            continuation = null;

            if (single != null && (continuation = AotInterlocked.Exchange(ref single, null)) != null)
            {
                return(true);
            }

            return(completed != null && completed.TryPop(out continuation));
        }
Beispiel #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed.TryRelaxedSet())
            {
                return;
            }

            if (handle != null)
            {
                var tmpHandle = AotInterlocked.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();
                    }
                }
                // Spicy Pixel: Must use the public interface (e.g. Close)
                tmpHandle.Close();
                // tmpHandle.Dispose ();
            }
        }
Beispiel #3
0
        public bool Exchange(bool newVal)
        {
            int newTemp = newVal ? Set : UnSet;

            return(AotInterlocked.Exchange(ref flag, newTemp) == Set);
        }