Пример #1
0
 public StParker(IParkSpot parkSpot) : this(1, parkSpot) { }
Пример #2
0
 public StParker(int releasers, IParkSpot parkSpot) : this(releasers) {
     this.parkSpot = parkSpot;   
 }
Пример #3
0
        public int Park(int spinCount, StCancelArgs cargs) {
            do {
                if (state == 0) {
                    return waitStatus;
                }
                if (cargs.Alerter != null && cargs.Alerter.IsSet && TryCancel()) {
                    return StParkStatus.Alerted;
                }
                if (spinCount-- <= 0) {
                    break;
                }
                Platform.SpinWait(1);
            } while (true);

            if (parkSpot == null) {
                parkSpot = ThreadExtensions.ForCurrentThread.ParkSpotFactory.Create();
            }

            //
            // Try to clear the wait-in-progress bit. If the bit was already
            // cleared, the thread is unparked. 
            //

            if (!TestAndClearInProgress()) {
                return waitStatus;
            }

            //
            // If an alerter was specified, we register the parker with
            // the alerter before blocking the thread on the park spot.
            //

            bool unregister = false;
            if (cargs.Alerter != null) {
                if (!(unregister = cargs.Alerter.RegisterParker(this))) {

                    //
                    // The alerter is already set. So, we try to cancel the parker.
                    //

                    if (TryCancel()) {
                        return StParkStatus.Alerted;
                    }

                    //
                    // We can't cancel the parker because someone else acquired 
                    // the count down lock. We must wait unconditionally until
                    // the park spot is set.
                    //

                    cargs = StCancelArgs.None;
                }
            }

            parkSpot.Wait(this, cargs);

            if (unregister) {
                cargs.Alerter.DeregisterParker(this);
            }
            return waitStatus;
        }
Пример #4
0
 public StParker(IParkSpot parkSpot) : this(1, parkSpot)
 {
 }
Пример #5
0
 public StParker(int releasers, IParkSpot parkSpot) : this(releasers) {
     this.parkSpot = parkSpot;
 }
Пример #6
0
        public int Park(int spinCount, StCancelArgs cargs)
        {
            do
            {
                if (state == 0)
                {
                    return(waitStatus);
                }
                if (cargs.Alerter != null && cargs.Alerter.IsSet && TryCancel())
                {
                    return(StParkStatus.Alerted);
                }
                if (spinCount-- <= 0)
                {
                    break;
                }
                Platform.SpinWait(1);
            } while (true);

            if (parkSpot == null)
            {
                parkSpot = ThreadExtensions.ForCurrentThread.ParkSpotFactory.Create();
            }

            //
            // Try to clear the wait-in-progress bit. If the bit was already
            // cleared, the thread is unparked.
            //

            if (!TestAndClearInProgress())
            {
                return(waitStatus);
            }

            //
            // If an alerter was specified, we register the parker with
            // the alerter before blocking the thread on the park spot.
            //

            bool unregister = false;

            if (cargs.Alerter != null)
            {
                if (!(unregister = cargs.Alerter.RegisterParker(this)))
                {
                    //
                    // The alerter is already set. So, we try to cancel the parker.
                    //

                    if (TryCancel())
                    {
                        return(StParkStatus.Alerted);
                    }

                    //
                    // We can't cancel the parker because someone else acquired
                    // the count down lock. We must wait unconditionally until
                    // the park spot is set.
                    //

                    cargs = StCancelArgs.None;
                }
            }

            parkSpot.Wait(this, cargs);

            if (unregister)
            {
                cargs.Alerter.DeregisterParker(this);
            }
            return(waitStatus);
        }