Merge pull request #2338 from BogdanovKirill/httpwritefix3
[mono.git] / mcs / class / Mono.Posix / Mono.Unix / UnixSignal.cs
index 6e85796dfbae8c1c7903c2094f3e9efda57c4fa7..8e4eb5b84639c63cc417ce8b43634c484e3c7d2e 100644 (file)
@@ -39,6 +39,11 @@ namespace Mono.Unix {
                private int signum;
                private IntPtr signal_info;
 
+               static UnixSignal ()
+               {
+                       Stdlib.VersionCheck ();
+               }
+
                public UnixSignal (Signum signum)
                {
                        this.signum = NativeConvert.FromSignum (signum);
@@ -94,9 +99,18 @@ namespace Mono.Unix {
                                EntryPoint="Mono_Unix_UnixSignal_uninstall")]
                private static extern int uninstall (IntPtr info);
 
+               [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
+               delegate int Mono_Posix_RuntimeIsShuttingDown ();
+               static Mono_Posix_RuntimeIsShuttingDown ShuttingDown = RuntimeShuttingDownCallback;
+               
+               static int RuntimeShuttingDownCallback ()
+               {
+                       return Environment.HasShutdownStarted ? 1 : 0;
+               }
+
                [DllImport (Stdlib.MPH, CallingConvention=CallingConvention.Cdecl,
                                EntryPoint="Mono_Unix_UnixSignal_WaitAny")]
-               private static extern int WaitAny (IntPtr[] infos, int count, int timeout);
+               private static extern int WaitAny (IntPtr[] infos, int count, int timeout, Mono_Posix_RuntimeIsShuttingDown shutting_down);
 
                [DllImport (Stdlib.MPH, CallingConvention=CallingConvention.Cdecl,
                                 EntryPoint="Mono_Posix_SIGRTMIN")]
@@ -136,10 +150,12 @@ namespace Mono.Unix {
                        set {Interlocked.Exchange (ref Info->count, value);}
                }
 
+               // signum, count, write_fd, pipecnt, and pipelock are read from a signal handler thread
+               // count and pipelock are both read and written from the signal handler thread
                [Map]
                struct SignalInfo {
-                       public int signum, count, read_fd, write_fd, have_handler;
-                       public IntPtr handler;
+                       public int signum, count, read_fd, write_fd, pipecnt, pipelock, have_handler;
+                       public IntPtr handler; // Backed-up handler to restore when signal unregistered
                }
 
                #region WaitHandle overrides
@@ -187,6 +203,7 @@ namespace Mono.Unix {
                        return WaitAny (signals, (int) ms);
                }
 
+                       
                public static unsafe int WaitAny (UnixSignal[] signals, int millisecondsTimeout)
                {
                        if (signals == null)
@@ -199,7 +216,7 @@ namespace Mono.Unix {
                                if (infos [i] == IntPtr.Zero)
                                        throw new InvalidOperationException ("Disposed UnixSignal");
                        }
-                       return WaitAny (infos, infos.Length, millisecondsTimeout);
+                       return WaitAny (infos, infos.Length, millisecondsTimeout, ShuttingDown);
                }
        }
 }