#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
[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'