protected static void MakeMoreSlot(TrackingRefManagerThreadWorkInput input, Action <IntPtr> onComplete)
        {
            RawRef r = new RawRef();

            r.SetRef(ref r);
            onComplete?.Invoke(r.Address);

            while (true)
            {
                TrackingRefManagerOp op;
                while (input.Ops.TryDequeue(out op))
                {
                    if (op.IsExit)
                    {
                        throw new ObjectDisposedException("this");
                    }
                    else if (op.IsPop)
                    {
                        return;
                    }
                    else
                    {
                        try
                        {
                            MakeMoreSlot(input, op.OnComplete);
                        }
                        catch (StackOverflowException)
                        {
                            op.OnComplete?.Invoke(IntPtr.Zero);
                        }
                    }
                }
                input.WaitHandle.WaitOne();
            }
        }
Beispiel #2
0
        protected static void ThreadWork(object state)
        {
            TrackingRefManagerThreadWorkInput input = state as TrackingRefManagerThreadWorkInput;

            try
            {
                while (true)
                {
                    input.WaitHandle.WaitOne();
                    TrackingRefManagerOp op;
                    while (input.Ops.TryDequeue(out op))
                    {
                        if (op.IsPop || op.IsExit)
                        {
                            return;
                        }
                        else
                        {
                            MakeMoreSlot(input, op.OnComplete);
                        }
                    }
                }
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            finally
            {
                TrackingRefManagerOp op;
                while (input.Ops.TryDequeue(out op))
                {
                    op.OnComplete?.Invoke(IntPtr.Zero);
                }
                input.WaitHandle.Dispose();
            }
        }