Bug 1252382 - Get rid of PR_Sleep in the terminator;r?froydnj draft
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Tue, 01 Mar 2016 09:01:22 +0100
changeset 335802 da8831154f575776d4dd66334317dd82af953900
parent 335409 9da51cb4974e03cdd8fa45a34086fe1033abfeaf
child 515217 a52c8c5b11ee1c1d6193f99ceb6e04edb47b8b1f
push id11877
push userdteller@mozilla.com
push dateTue, 01 Mar 2016 15:21:23 +0000
reviewersfroydnj
bugs1252382
milestone47.0a1
Bug 1252382 - Get rid of PR_Sleep in the terminator;r?froydnj The terminator currently makes use of PR_Sleep. As it turns out, late in shutdown, this can cause infinite recursions and finally exit(-11) . This patch replaces PR_Sleep with usleep(3) and Sleep(). MozReview-Commit-ID: 3SybinpQUVl
toolkit/components/terminator/nsTerminator.cpp
--- a/toolkit/components/terminator/nsTerminator.cpp
+++ b/toolkit/components/terminator/nsTerminator.cpp
@@ -28,16 +28,22 @@
 #include "nsAppDirectoryServiceDefs.h"
 
 #include "nsIObserverService.h"
 #include "nsIPrefService.h"
 #if defined(MOZ_CRASHREPORTER)
 #include "nsExceptionHandler.h"
 #endif
 
+#if defined(XP_WIN)
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/MemoryChecking.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/unused.h"
@@ -122,29 +128,32 @@ RunWatchdog(void* arg)
 
   // Let's copy and deallocate options, that's one less leak to worry
   // about.
   UniquePtr<Options> options((Options*)arg);
   uint32_t crashAfterTicks = options->crashAfterTicks;
   options = nullptr;
 
   const uint32_t timeToLive = crashAfterTicks;
-  const PRIntervalTime ticksDuration = PR_MillisecondsToInterval(1000);
   while (true) {
     //
     // We do not want to sleep for the entire duration,
     // as putting the computer to sleep would suddenly
     // cause us to timeout on wakeup.
     //
     // Rather, we prefer sleeping for at most 1 second
     // at a time. If the computer sleeps then wakes up,
     // we have lost at most one second, which is much
     // more reasonable.
     //
-    PR_Sleep(ticksDuration);
+#if defined(XP_WIN)
+    Sleep(1000 /* ms */);
+#else
+    usleep(1000000 /* usec */);
+#endif
 
     if (gHeartbeat++ < timeToLive) {
       continue;
     }
 
     // Shutdown is apparently dead. Crash the process.
     MOZ_CRASH("Shutdown too long, probably frozen, causing a crash.");
   }