예제 #1
0
		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");
		}
예제 #2
0
 /// <summary>
 /// Releases the lock. Subsequent calls to this method do nothing.
 /// </summary>
 public void Dispose()
 {
     if (parent == null)
     {
         return;
     }
     parent.Unlock();
     parent = null;
 }
예제 #3
0
		/// <summary>
		/// Releases the lock. Subsequent calls to this method do nothing.
		/// </summary>
		public void Dispose()
		{
			if (parent==null)
			{
				return;
			}
			parent.Unlock();
			parent = null;
		}
예제 #4
0
 /// <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;
 }
예제 #5
0
		public void Setup()
		{
			subject = new SyncLock("Test", Timeout.Infinite);
		}
예제 #6
0
		public void NamePreserved()
		{
			string name = "Hello";
			subject = new SyncLock(name);
			Assert.AreEqual(name, subject.Name);
		}
예제 #7
0
		/// <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;
		}