/// <summary> /// Initializes a new instance of the <see cref="System.Threading.SpinLock"/> struct. /// </summary> /// <param name="enableThreadOwnerTracking">If set to <c>true</c> enable thread owner tracking.</param> /// <description> /// Important: Consumers on AOT must use this constructor to avoid JIT at runtime. /// </description> public SpinLock(bool enableThreadOwnerTracking) { this.isThreadOwnerTrackingEnabled = enableThreadOwnerTracking; this.threadWhoTookLock = 0; this.ticket = new TicketType (); // this.stallTickets = null; // Spicy Pixel: Interlocked.CompareExchange with reference types // tries to JIT on old Mono AOT. The only safe place then to // initialize stallTickets is in the constructor. It doesn't // make sense to use a lock because the lock object would have // to be initialized anyway (and that's the point of this class). // // The solution chosen is to always initialize stallTickets here. // This means: // 1. Slight performance hit because now we do a heap alloc when // it is not always necessary. // 2. AOT has to use this constructor. The default one (which we // can't define on a struct) does not initialize the collection // and we can't do it in Enter without a working CompareExchange. this.stallTickets = new ConcurrentOrderedList<int> (); }
/// <summary> /// Initializes a new instance of the <see cref="System.Threading.SpinLock"/> struct. /// </summary> /// <param name="enableThreadOwnerTracking">If set to <c>true</c> enable thread owner tracking.</param> /// <description> /// Important: Consumers on AOT must use this constructor to avoid JIT at runtime. /// </description> public SpinLock(bool enableThreadOwnerTracking) { this.isThreadOwnerTrackingEnabled = enableThreadOwnerTracking; this.threadWhoTookLock = 0; this.ticket = new TicketType(); // this.stallTickets = null; // Spicy Pixel: Interlocked.CompareExchange with reference types // tries to JIT on old Mono AOT. The only safe place then to // initialize stallTickets is in the constructor. It doesn't // make sense to use a lock because the lock object would have // to be initialized anyway (and that's the point of this class). // // The solution chosen is to always initialize stallTickets here. // This means: // 1. Slight performance hit because now we do a heap alloc when // it is not always necessary. // 2. AOT has to use this constructor. The default one (which we // can't define on a struct) does not initialize the collection // and we can't do it in Enter without a working CompareExchange. this.stallTickets = new ConcurrentOrderedList <int> (); }
public SpinLock (bool enableThreadOwnerTracking) { this.isThreadOwnerTrackingEnabled = enableThreadOwnerTracking; this.threadWhoTookLock = 0; this.ticket = new TicketType (); }
public SpinLock(bool trackId) { this.isThreadOwnerTrackingEnabled = trackId; this.threadWhoTookLock = 0; this.ticket = new TicketType(); }