Ejemplo n.º 1
0
        private void DropTimed()
        {
            var top = TopTimed;
            var n   = Merge(top.Next as WorkTimed, top.Right);

            TopTimed = n;
            if (null != n)
            {
                Scheduler.Signal(this.Scheduler);
            }
        }
Ejemplo n.º 2
0
        internal void SynchronizedPushTimed(WorkTimed x)
        {
            this.Lock.Enter();
            var o = TopTimed;
            var n = Merge(TopTimed, x);

            TopTimed = n;
            if (o != n)
            {
                Scheduler.Signal(this.Scheduler);
            }
            this.Lock.Exit();
        }
Ejemplo n.º 3
0
        internal static void SynchronizedPushTimed(ref Worker wr, WorkTimed x)
        {
            SpinlockTTAS.Enter(ref Scheduler.Lock);
            var h = TopTimed;

            if (null == h)
            {
                TopTimed = x;
                x.Up     = x;
                x.Next   = x;
                var waiter = Waiters;
                if (0 <= Waiters)
                {
                    Events[waiter].Set();
                }
            }
            else if (x.Ticks - h.Ticks < 0)
            {
                x.Next   = h.Up;
                h.Up     = x;
                x.Up     = x;
                TopTimed = x;
                var waiter = Waiters;
                if (0 <= Waiters)
                {
                    Events[waiter].Set();
                }
            }
            else if (x.Ticks - h.Up.Ticks > 0)
            {
                x.Up   = h.Up;
                h.Up   = x;
                x.Next = x;
            }
            else
            {
                var  y = h.Up;
                Work z = h.Up;
                while (x.Ticks - y.Up.Ticks < 0)
                {
                    var t = y.Next;
                    y.Next = z;
                    z      = t;
                }
                x.Up   = y.Up;
                x.Next = z;
                y.Up   = x;
                h.Up   = x;
            }
            SpinlockTTAS.Exit(ref Scheduler.Lock);
        }
Ejemplo n.º 4
0
        private static int IsAbandoned(WorkTimed x)
        {
            if (null == x)
            {
                return(0);
            }
            var pk = x.Pick;

            if (null == pk)
            {
                return(0);
            }
            return(pk.State);
        }
Ejemplo n.º 5
0
        private void DropTimed()
        {
            // XXX This implementation requires keys to be unique - must analyze and fix this properly to allow duplicates.
            var h = this.TopTimed;

            if (null == h)
            {
                return;
            }
            var y1 = h.Up;
            var y2 = h.Next as WorkTimed;

            if (y1.Ticks - y2.Ticks < 0)
            {
                var t = y1;
                y1 = y2;
                y2 = t;
            }
            if (y1.Ticks == h.Ticks)
            {
                this.TopTimed = null;
                return;
            }
            WorkTimed x;
            var       h3 = y1;

            y1    = y1.Up;
            h3.Up = h3;
            while (true)
            {
                if (y1.Ticks - y2.Ticks < 0)
                {
                    var t = y1;
                    y1 = y2;
                    y2 = t;
                }
                if (y1.Ticks == h.Ticks)
                {
                    this.TopTimed = h3;
                    return;
                }
                x      = y1;
                y1     = y1.Up;
                x.Up   = x.Next as WorkTimed;
                x.Next = h3.Up;
                h3.Up  = x;
                h3     = x;
            }
        }
Ejemplo n.º 6
0
        internal static void DropTimed()
        {
            var h = TopTimed;

            if (null == h)
            {
                return;
            }
            var y1 = h.Up;
            var y2 = h.Next as WorkTimed;

            if (y1.Ticks - y2.Ticks < 0)
            {
                var t = y1;
                y1 = y2;
                y2 = t;
            }
            if (y1 == h)
            {
                TopTimed = null;
                return;
            }
            WorkTimed x;
            var       h3 = y1;

            y1    = y1.Up;
            h3.Up = h3;
            while (true)
            {
                if (y1.Ticks - y2.Ticks < 0)
                {
                    var t = y1;
                    y1 = y2;
                    y2 = t;
                }
                if (y1 == h)
                {
                    TopTimed = h3;
                    return;
                }
                x      = y1;
                y1     = y1.Up;
                x.Up   = x.Next as WorkTimed;
                x.Next = h3.Up;
                h3.Up  = x;
                h3     = x;
            }
        }
Ejemplo n.º 7
0
        internal void SynchronizedPushTimed(WorkTimed x)
        {
            this.Lock.Enter();
            var tag = this.unique;

            x.Ticks    |= tag; // XXX: Kludge to make sure Ticks are unique.
            this.unique = tag + 1;
            var h = this.TopTimed;

            if (null == h)
            {
                this.TopTimed = x;
                x.Up          = x;
                x.Next        = x;
                Scheduler.Signal(this.Scheduler);
            }
            else if (x.Ticks - h.Ticks < 0)
            {
                x.Next        = h.Up;
                h.Up          = x;
                x.Up          = x;
                this.TopTimed = x;
                Scheduler.Signal(this.Scheduler);
            }
            else if (x.Ticks - h.Up.Ticks > 0)
            {
                x.Up   = h.Up;
                h.Up   = x;
                x.Next = x;
            }
            else
            {
                var  y = h.Up;
                Work z = y;
                while (x.Ticks - y.Up.Ticks < 0)
                {
                    y = y.Up;
                    var t = y.Next;
                    y.Next = z;
                    z      = t;
                }
                x.Up   = y.Up;
                x.Next = z;
                y.Up   = x;
                h.Up   = x;
            }
            this.Lock.Exit();
        }
Ejemplo n.º 8
0
        private static WorkTimed Merge(WorkTimed x, WorkTimed y)
        {
            if (IsAbandoned(x) > 0)
            {
                x = Merge(x.Next as WorkTimed, x.Right);
            }
            if (IsAbandoned(y) > 0)
            {
                y = Merge(y.Next as WorkTimed, y.Right);
            }

            if (null == x)
            {
                return(y);
            }
            if (null == y)
            {
                return(x);
            }

            if (x.Ticks - y.Ticks > 0)
            {
                var t = x; x = y; y = t;
            }

            x.Right = Merge(x.Right, y);

            if (null == x.Next)
            {
                x.Next  = x.Right;
                x.Right = null;
            }
            else if (null != x.Right)
            {
                var x_Next = x.Next as WorkTimed;
                if (x_Next.Rank < x.Right.Rank)
                {
                    var t = x_Next;
                    x.Next  = x.Right;
                    x.Right = t;
                }
                x.Rank = x.Right.Rank + 1;
            }
            return(x);
        }
Ejemplo n.º 9
0
        private void DropTimed()
        {
            var top = TopTimed;

            TopTimed = Merge(top.Next as WorkTimed, top.Right);
        }