public void Initial() { object monitor = new object(); DateTime start = DateTime.UtcNow; for (int i=0; i < Iterations; i++) { lock (monitor) { } } DateTime end = DateTime.UtcNow; TimeSpan nativeTime = end-start; SyncLock syncLock = new SyncLock(Timeout.Infinite); start = DateTime.UtcNow; for (int i=0; i < Iterations; i++) { using (syncLock.Lock()) { } } end = DateTime.UtcNow; TimeSpan syncLockTime = end-start; double factor = syncLockTime.TotalMilliseconds / nativeTime.TotalMilliseconds; Console.WriteLine ("Performance of SyncLock (initial acquisition):"); Console.WriteLine ("Native: {0}", nativeTime); Console.WriteLine ("SyncLock: {0}", syncLockTime); Console.WriteLine ("Performance penalty factor: {0:0.00}", factor); Console.WriteLine(); Assert.IsTrue (factor < 10, "SyncLock must not be ridiculously slow"); }
/// <summary> /// Releases the lock. Subsequent calls to this method do nothing. /// </summary> public void Dispose() { if (parent == null) { return; } parent.Unlock(); parent = null; }
/// <summary> /// Releases the lock. Subsequent calls to this method do nothing. /// </summary> public void Dispose() { if (parent==null) { return; } parent.Unlock(); parent = null; }
/// <summary> /// Constructs a new lock token for the specified lock. /// </summary> /// <param name="parent">The internal monitor used for locking.</param> internal LockToken(SyncLock parent) { this.parent = parent; }
public void Setup() { subject = new SyncLock("Test", Timeout.Infinite); }
public void NamePreserved() { string name = "Hello"; subject = new SyncLock(name); Assert.AreEqual(name, subject.Name); }
/// <summary> /// Constructs a new lock token for the specified lock. /// </summary> /// <param name="parent">The internal monitor used for locking.</param> internal LockToken (SyncLock parent) { this.parent = parent; }