@@ -11,82 +11,80 @@
  * You must not remove this notice, or any other, from this software.
  *
  *
- * ***************************************************************************/
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading;
-using Microsoft.Scripting.Utils;
-
-namespace IronRuby.Runtime {
-    /// <summary>
-    /// TODO: use ReaderWriterLockSlim on CLR4?
-    /// Queryable recursive lock.
-    /// </summary>
-    internal sealed class CheckedMonitor {
-        private int _locked;
-
-        internal void Enter(ref bool lockTaken) {
-            try {
-                MonitorUtils.Enter(this, ref lockTaken);
-            } finally {
-                if (lockTaken) {
-                        _locked++;
-                }
-            }
-        }
-
-        internal void Exit(ref bool lockTaken) {
-            try {
-                MonitorUtils.Exit(this, ref lockTaken);
-            } finally {
-                if (!lockTaken) {
-                    _locked--;
-                }
-            }
-        }
-
-        public bool IsLocked {
-            get { return _locked > 0; }
-        }
-
-        public IDisposable/*!*/ CreateLocker() {
-            return new CheckedMonitorLocker(this);
-        }
-
-        public IDisposable/*!*/ CreateUnlocker() {
-            return new CheckedMonitorUnlocker(this);
-        }
-
-        private struct CheckedMonitorLocker : IDisposable {
-            private readonly CheckedMonitor/*!*/ _monitor;
-            private bool _lockTaken;
-
-            public CheckedMonitorLocker(CheckedMonitor/*!*/ monitor) {
-                _monitor = monitor;
-                _lockTaken = false;
-                monitor.Enter(ref _lockTaken);
-            }
-
-            public void Dispose() {
-                _monitor.Exit(ref _lockTaken);
-            }
-        }
-
-        private struct CheckedMonitorUnlocker : IDisposable {
-            private readonly CheckedMonitor/*!*/ _monitor;
-            private bool _lockTaken;
-
-            public CheckedMonitorUnlocker(CheckedMonitor/*!*/ monitor) {
-                _monitor = monitor;
-                _lockTaken = true;
-                monitor.Exit(ref _lockTaken);
-            }
-
-            public void Dispose() {
-                _monitor.Enter(ref _lockTaken);
-            }
-        }
-    }
-}
+ * ***************************************************************************/
+
+using System;
+using System.Threading;
+using Microsoft.Scripting.Utils;
+
+namespace IronRuby.Runtime {
+    /// <summary>
+    /// TODO: use ReaderWriterLockSlim on CLR4?
+    /// Queryable recursive lock.
+    /// </summary>
+    internal sealed class CheckedMonitor {
+        private int _locked;
+
+        internal void Enter(ref bool lockTaken) {
+            try {
+                MonitorUtils.Enter(this, ref lockTaken);
+            } finally {
+                if (lockTaken) {
+                    Interlocked.Increment(ref _locked);
+                }
+            }
+        }
+
+        internal void Exit(ref bool lockTaken) {
+            try {
+                MonitorUtils.Exit(this, ref lockTaken);
+            } finally {
+                if (!lockTaken) {
+                    Interlocked.Decrement(ref _locked);
+                }
+            }
+        }
+
+        public bool IsLocked {
+            get { return !Interlocked.Equals(_locked, 0); }
+        }
+
+        public IDisposable/*!*/ CreateLocker() {
+            return new CheckedMonitorLocker(this);
+        }
+
+        public IDisposable/*!*/ CreateUnlocker() {
+            return new CheckedMonitorUnlocker(this);
+        }
+
+        private struct CheckedMonitorLocker : IDisposable {
+            private readonly CheckedMonitor/*!*/ _monitor;
+            private bool _lockTaken;
+
+            public CheckedMonitorLocker(CheckedMonitor/*!*/ monitor) {
+                _monitor = monitor;
+                _lockTaken = false;
+                monitor.Enter(ref _lockTaken);
+            }
+
+            public void Dispose() {
+                _monitor.Exit(ref _lockTaken);
+            }
+        }
+
+        private struct CheckedMonitorUnlocker : IDisposable {
+            private readonly CheckedMonitor/*!*/ _monitor;
+            private bool _lockTaken;
+
+            public CheckedMonitorUnlocker(CheckedMonitor/*!*/ monitor) {
+                _monitor = monitor;
+                _lockTaken = true;
+                monitor.Exit(ref _lockTaken);
+            }
+
+            public void Dispose() {
+                _monitor.Enter(ref _lockTaken);
+            }
+        }
+    }
+}
