2009-04-12 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mcs / class / corlib / System.Threading / Monitor.cs
index aea57b5b8dda5285aa0b8c0c2564c4543eb514d0..646efeeb9ae6f9e75093aeb7bdb466797ce7894d 100644 (file)
@@ -35,13 +35,20 @@ using System.Runtime.Remoting.Contexts;
 
 #if NET_2_0
 using System.Runtime.ConstrainedExecution;
+using System.Runtime.InteropServices;
 #endif
 
 namespace System.Threading
 {
+#if NET_2_0
+       [ComVisible (true)]
+       public static class Monitor
+       {
+#else
        public sealed class Monitor
        {
                private Monitor () {}
+#endif
 
                // Grabs the mutex on object 'obj', with a maximum
                // wait time 'ms' but doesn't block - if it can't get
@@ -49,34 +56,18 @@ namespace System.Threading
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private extern static bool Monitor_try_enter(object obj, int ms);
 
-               public static void Enter(object obj) {
-                       if(obj==null) {
-                               throw new ArgumentNullException("obj");
-                       }
-                       //if(obj.GetType().IsValueType==true) {
-                       //      throw new ArgumentException("Value type");
-                       //}
-
-                       Monitor_try_enter(obj, Timeout.Infinite);
-               }
+               // Enter/Exit are implemented directly as icalls for performance reasons
 
-               // Releases the mutex on object 'obj'
+               // Acquires the mutex on object 'obj'
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern static void Monitor_exit(object obj);
+               public extern static void Enter(object obj);
 
+               // Releases the mutex on object 'obj'
 #if NET_2_0
                [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
 #endif
-               public static void Exit(object obj) {
-                       if(obj==null) {
-                               throw new ArgumentNullException("obj");
-                       }
-                       //if(obj.GetType().IsValueType==true) {
-                       //      throw new ArgumentException("Value type");
-                       //}
-
-                       Monitor_exit(obj);
-               }
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               public extern static void Exit(object obj);
 
                // Signals one of potentially many objects waiting on
                // object 'obj'