示例#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;
		}