Add all missing sequential layout directives to corlib and system.
[mono.git] / mcs / class / corlib / System.Threading / WaitHandle.cs
index 0c4daaf09ad5d71e60c3dca93d76f7f104140117..81ee13c76d24e3fe77a088857dff8ba1085cde65 100644 (file)
@@ -40,7 +40,13 @@ using System.Runtime.ConstrainedExecution;
 namespace System.Threading
 {
        [ComVisible (true)]
-       public abstract class WaitHandle : MarshalByRefObject, IDisposable
+       [StructLayout (LayoutKind.Sequential)]
+       public abstract class WaitHandle
+#if MOONLIGHT
+               : IDisposable
+#else
+               : MarshalByRefObject, IDisposable
+#endif
        {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private static extern bool WaitAll_internal(WaitHandle[] handles, int ms, bool exitContext);
@@ -115,7 +121,13 @@ namespace System.Threading
                                throw new ArgumentOutOfRangeException ("millisecondsTimeout");
 
                        try {
-                               if (exitContext) SynchronizationAttribute.ExitContext ();
+                               if (exitContext) {
+#if MONOTOUCH
+                                       throw new NotSupportedException ("exitContext == true is not supported");
+#else
+                                       SynchronizationAttribute.ExitContext ();
+#endif
+                               }
                                return(WaitAll_internal(waitHandles, millisecondsTimeout, false));
                        }
                        finally {
@@ -134,7 +146,13 @@ namespace System.Threading
                                throw new ArgumentOutOfRangeException ("timeout");
 
                        try {
-                               if (exitContext) SynchronizationAttribute.ExitContext ();
+                               if (exitContext) {
+#if MONOTOUCH
+                                       throw new NotSupportedException ("exitContext == true is not supported");
+#else
+                                       SynchronizationAttribute.ExitContext ();
+#endif
+                               }
                                return (WaitAll_internal (waitHandles, (int) ms, exitContext));
                        }
                        finally {
@@ -164,7 +182,13 @@ namespace System.Threading
                                throw new ArgumentOutOfRangeException ("millisecondsTimeout");
 
                        try {
-                               if (exitContext) SynchronizationAttribute.ExitContext ();
+                               if (exitContext) {
+#if MONOTOUCH
+                                       throw new NotSupportedException ("exitContext == true is not supported");
+#else
+                                       SynchronizationAttribute.ExitContext ();
+#endif
+                               }
                                return(WaitAny_internal(waitHandles, millisecondsTimeout, exitContext));
                        }
                        finally {
@@ -195,7 +219,13 @@ namespace System.Threading
                                throw new ArgumentOutOfRangeException ("timeout");
 
                        try {
-                               if (exitContext) SynchronizationAttribute.ExitContext ();
+                               if (exitContext) {
+#if MONOTOUCH
+                                       throw new NotSupportedException ("exitContext == true is not supported");
+#else
+                                       SynchronizationAttribute.ExitContext ();
+#endif
+                               }
                                return (WaitAny_internal(waitHandles, (int) ms, exitContext));
                        }
                        finally {
@@ -208,12 +238,12 @@ namespace System.Threading
                        // FIXME
                }
 
-               public virtual void Close() {
+               public virtual void Close ()
+               {
                        Dispose(true);
-                       GC.SuppressFinalize (this);
                }
 
-#if NET_4_0
+#if NET_4_0 || MOBILE || MOONLIGHT
                public void Dispose ()
 #else          
                void IDisposable.Dispose ()
@@ -251,7 +281,6 @@ namespace System.Threading
                protected virtual void Dispose (bool explicitDisposing)
                {
                        if (!disposed){
-                               disposed = true;
 
                                //
                                // This is only the case if the handle was never properly initialized
@@ -261,6 +290,10 @@ namespace System.Threading
                                        return;
 
                                lock (this){
+                                       if (disposed)
+                                               return;
+
+                                       disposed = true;
                                        if (safe_wait_handle != null)
                                                safe_wait_handle.Dispose ();
                                }
@@ -341,8 +374,13 @@ namespace System.Threading
 
                        bool release = false;
                        try {
-                               if (exitContext)
+                               if (exitContext) {
+#if MONOTOUCH
+                                       throw new NotSupportedException ("exitContext == true is not supported");
+#else
                                        SynchronizationAttribute.ExitContext ();
+#endif
+                               }
                                safe_wait_handle.DangerousAddRef (ref release);
                                return (WaitOne_internal(safe_wait_handle.DangerousGetHandle (), millisecondsTimeout, exitContext));
                        } finally {
@@ -372,8 +410,13 @@ namespace System.Threading
 
                        bool release = false;
                        try {
-                               if (exitContext)
+                               if (exitContext) {
+#if MONOTOUCH
+                                       throw new NotSupportedException ("exitContext == true is not supported");
+#else
                                        SynchronizationAttribute.ExitContext ();
+#endif
+                               }
                                safe_wait_handle.DangerousAddRef (ref release);
                                return (WaitOne_internal(safe_wait_handle.DangerousGetHandle (), (int) ms, exitContext));
                        }
@@ -403,9 +446,5 @@ namespace System.Threading
                
                protected static readonly IntPtr InvalidHandle = (IntPtr) (-1);
                bool disposed = false;
-
-               ~WaitHandle() {
-                       Dispose(false);
-               }
        }
 }