mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 07:45:30 +00:00
Bug 1615921 - Suspend late write checks in Windows vprintf_stderr r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D63216 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
0223215a5b
commit
ef59845575
@ -10,6 +10,7 @@
|
||||
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "mozilla/LateWriteChecks.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/Printf.h"
|
||||
@ -390,6 +391,7 @@ class LogModuleManager {
|
||||
|
||||
void Print(const char* aName, LogLevel aLevel, const TimeStamp* aStart,
|
||||
const char* aFmt, va_list aArgs) MOZ_FORMAT_PRINTF(5, 0) {
|
||||
AutoSuspendLateWriteChecks suspendLateWriteChecks;
|
||||
long pid = static_cast<long>(base::GetCurrentProcId());
|
||||
const size_t kBuffSize = 1024;
|
||||
char buff[kBuffSize];
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifdef XP_WIN
|
||||
# include <io.h>
|
||||
# include <windows.h>
|
||||
# include "mozilla/LateWriteChecks.h"
|
||||
# include "mozilla/UniquePtr.h"
|
||||
#endif
|
||||
|
||||
@ -259,6 +260,7 @@ void vprintf_stderr(const char* aFmt, va_list aArgs) {
|
||||
|
||||
vfprintf(fp, aFmt, aArgs);
|
||||
|
||||
AutoSuspendLateWriteChecks suspend;
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,15 @@
|
||||
|
||||
/*************************** Auxiliary Declarations ***************************/
|
||||
|
||||
static MOZ_THREAD_LOCAL(int) tlsSuspendLateWriteChecks;
|
||||
|
||||
bool SuspendingLateWriteChecksForCurrentThread() {
|
||||
if (!tlsSuspendLateWriteChecks.init()) {
|
||||
return true;
|
||||
}
|
||||
return tlsSuspendLateWriteChecks.get() > 0;
|
||||
}
|
||||
|
||||
// This a wrapper over a file descriptor that provides a Printf method and
|
||||
// computes the sha1 of the data that passes through it.
|
||||
class SHA1Stream {
|
||||
@ -103,6 +112,10 @@ class LateWriteObserver final : public mozilla::IOInterposeObserver {
|
||||
|
||||
void LateWriteObserver::Observe(
|
||||
mozilla::IOInterposeObserver::Observation& aOb) {
|
||||
if (SuspendingLateWriteChecksForCurrentThread()) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
MOZ_CRASH();
|
||||
#endif
|
||||
@ -233,4 +246,20 @@ void StopLateWriteChecks() {
|
||||
}
|
||||
}
|
||||
|
||||
void PushSuspendLateWriteChecks() {
|
||||
if (!tlsSuspendLateWriteChecks.init()) {
|
||||
return;
|
||||
}
|
||||
tlsSuspendLateWriteChecks.set(tlsSuspendLateWriteChecks.get() + 1);
|
||||
}
|
||||
|
||||
void PopSuspendLateWriteChecks() {
|
||||
if (!tlsSuspendLateWriteChecks.init()) {
|
||||
return;
|
||||
}
|
||||
int current = tlsSuspendLateWriteChecks.get();
|
||||
MOZ_ASSERT(current > 0);
|
||||
tlsSuspendLateWriteChecks.set(current - 1);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -54,6 +54,25 @@ void BeginLateWriteChecks();
|
||||
*/
|
||||
void StopLateWriteChecks();
|
||||
|
||||
/**
|
||||
* Temporarily suspend late write checks for the current thread. This is useful
|
||||
* if you're about to perform a write, but it would be fine if this write were
|
||||
* interrupted or skipped during a fast shutdown.
|
||||
*/
|
||||
void PushSuspendLateWriteChecks();
|
||||
|
||||
/**
|
||||
* Resume late write checks for the current thread, assuming an ancestor in the
|
||||
* call stack hasn't also pushed a suspension.
|
||||
*/
|
||||
void PopSuspendLateWriteChecks();
|
||||
|
||||
class MOZ_RAII AutoSuspendLateWriteChecks {
|
||||
public:
|
||||
AutoSuspendLateWriteChecks() { PushSuspendLateWriteChecks(); }
|
||||
~AutoSuspendLateWriteChecks() { PopSuspendLateWriteChecks(); }
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_LateWriteChecks_h
|
||||
|
Loading…
Reference in New Issue
Block a user