You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by cc...@apache.org on 2012/04/13 23:10:23 UTC

svn commit: r1325954 - /incubator/lucene.net/trunk/src/core/Support/ThreadLock.cs

Author: ccurrens
Date: Fri Apr 13 21:10:22 2012
New Revision: 1325954

URL: http://svn.apache.org/viewvc?rev=1325954&view=rev
Log:
Missing file from last commit

Added:
    incubator/lucene.net/trunk/src/core/Support/ThreadLock.cs

Added: incubator/lucene.net/trunk/src/core/Support/ThreadLock.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Support/ThreadLock.cs?rev=1325954&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/core/Support/ThreadLock.cs (added)
+++ incubator/lucene.net/trunk/src/core/Support/ThreadLock.cs Fri Apr 13 21:10:22 2012
@@ -0,0 +1,61 @@
+using System.Threading;
+
+namespace Lucene.Net.Support
+{
+    /// <summary>
+    /// Abstract base class that provides a synchronization interface
+    /// for derived lock types
+    /// </summary>
+    public abstract class ThreadLock
+    {
+        public abstract void Enter(object obj);
+        public abstract void Exit(object obj);
+
+        private static readonly ThreadLock _nullLock = new NullThreadLock();
+        private static readonly ThreadLock _monitorLock = new MonitorThreadLock();
+        
+        /// <summary>
+        /// A ThreadLock class that actually does no locking
+        /// Used in ParallelMultiSearcher/MultiSearcher
+        /// </summary>
+        public static ThreadLock NullLock
+        {
+            get { return _nullLock; }
+        }
+
+        /// <summary>
+        /// Wrapper class for the Monitor Enter/Exit methods
+        /// using the <see cref="ThreadLock"/> interface
+        /// </summary>
+        public static ThreadLock MonitorLock
+        {
+            get { return _monitorLock; }
+        }
+
+        private sealed class NullThreadLock : ThreadLock
+        {
+            public override void Enter(object obj)
+            {
+                // Do nothing
+            }
+
+            public override void Exit(object obj)
+            {
+                // Do nothing
+            }
+        }
+
+        private sealed class MonitorThreadLock : ThreadLock
+        {
+            public override void Enter(object obj)
+            {
+                Monitor.Enter(obj);
+            }
+
+            public override void Exit(object obj)
+            {
+                Monitor.Exit(obj);
+            }
+        }
+    }
+}