public StParker(IParkSpot parkSpot) : this(1, parkSpot) { }
public StParker(int releasers, IParkSpot parkSpot) : this(releasers) { this.parkSpot = parkSpot; }
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; }
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); }