зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 2 changesets (bug 1457501) for build bustage. CLOSED TREE
Backed out changeset 911c930bc055 (bug 1457501) Backed out changeset bba71ee5fb46 (bug 1457501)
This commit is contained in:
Родитель
5bf85a2548
Коммит
3748952e99
|
@ -25,61 +25,8 @@ namespace CrashReporter {
|
|||
|
||||
namespace {
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
/*
|
||||
* On the Mac, exception handler callbacks are invoked in a context where all
|
||||
* other threads are paused. As a result, attempting to acquire a mutex is
|
||||
* problematic because 1) the mutex may be held by another thread which is
|
||||
* now suspended and 2) acquiring an unheld mutex can trigger memory allocation
|
||||
* which generally requires allocator locks. This class is a wrapper around a
|
||||
* StaticMutex, providing an IsLocked() method which only makes sense to use
|
||||
* in the Mac exception handling context when other threads are paused.
|
||||
*/
|
||||
class MacCrashReporterLock
|
||||
{
|
||||
public:
|
||||
void Lock()
|
||||
{
|
||||
sInnerMutex.Lock();
|
||||
sIsLocked = true;
|
||||
}
|
||||
void Unlock()
|
||||
{
|
||||
sIsLocked = false;
|
||||
sInnerMutex.Unlock();
|
||||
}
|
||||
/*
|
||||
* Returns true if the lock is held at the time the method is called.
|
||||
* The return value is out-of-date by the time this method returns unless
|
||||
* we have a guarantee that other threads are not running such as in Mac
|
||||
* breadkpad exception handler context.
|
||||
*/
|
||||
bool IsLocked()
|
||||
{
|
||||
return sIsLocked;
|
||||
}
|
||||
void AssertCurrentThreadOwns()
|
||||
{
|
||||
sInnerMutex.AssertCurrentThreadOwns();
|
||||
}
|
||||
private:
|
||||
static StaticMutex sInnerMutex;
|
||||
static bool sIsLocked;
|
||||
};
|
||||
StaticMutex MacCrashReporterLock::sInnerMutex;
|
||||
bool MacCrashReporterLock::sIsLocked;
|
||||
|
||||
// Use MacCrashReporterLock for locking
|
||||
typedef mozilla::BaseAutoLock<MacCrashReporterLock> CrashReporterAutoLock;
|
||||
typedef MacCrashReporterLock CrashReporterLockType;
|
||||
#else /* !XP_MACOSX */
|
||||
// Use StaticMutex for locking
|
||||
typedef StaticMutexAutoLock CrashReporterAutoLock;
|
||||
typedef StaticMutex CrashReporterLockType;
|
||||
#endif /* XP_MACOSX */
|
||||
|
||||
// Protects access to sInitialized and sThreadAnnotations.
|
||||
static MacCrashReporterLock sMutex;
|
||||
static StaticMutex sMutex;
|
||||
|
||||
class ThreadAnnotationSpan {
|
||||
public:
|
||||
|
@ -199,6 +146,21 @@ private:
|
|||
nsTArray<ThreadAnnotationSpan*> mDataSpans;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class DeleteWithLock
|
||||
{
|
||||
public:
|
||||
constexpr DeleteWithLock() {}
|
||||
|
||||
void operator()(T* aPtr) const
|
||||
{
|
||||
static_assert(sizeof(T) > 0, "T must be complete");
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
|
||||
delete aPtr;
|
||||
}
|
||||
};
|
||||
|
||||
static bool sInitialized = false;
|
||||
static UniquePtr<ThreadAnnotationData> sThreadAnnotations;
|
||||
|
||||
|
@ -207,7 +169,7 @@ void ThreadLocalDestructor(void* aUserData)
|
|||
{
|
||||
MOZ_ASSERT(aUserData);
|
||||
|
||||
CrashReporterAutoLock lock(sMutex);
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
|
||||
ThreadAnnotationSpan* aThreadInfo =
|
||||
static_cast<ThreadAnnotationSpan*>(aUserData);
|
||||
|
@ -230,7 +192,7 @@ ThreadAnnotationSpan::~ThreadAnnotationSpan()
|
|||
|
||||
void InitThreadAnnotation()
|
||||
{
|
||||
CrashReporterAutoLock lock(sMutex);
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
|
||||
if (sInitialized) {
|
||||
return;
|
||||
|
@ -255,7 +217,7 @@ void SetCurrentThreadName(const char* aName)
|
|||
PR_SetThreadPrivate(sTLSThreadInfoKey, nullptr);
|
||||
}
|
||||
|
||||
CrashReporterAutoLock lock(sMutex);
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
|
||||
if (!sInitialized) {
|
||||
return;
|
||||
|
@ -268,31 +230,9 @@ void SetCurrentThreadName(const char* aName)
|
|||
PR_SetThreadPrivate(sTLSThreadInfoKey, threadInfo);
|
||||
}
|
||||
|
||||
void GetFlatThreadAnnotation(const std::function<void(const char*)>& aCallback,
|
||||
bool aIsHandlingException)
|
||||
void GetFlatThreadAnnotation(const std::function<void(const char*)>& aCallback)
|
||||
{
|
||||
bool lockNeeded = true;
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
if (aIsHandlingException) {
|
||||
// Don't acquire the lock on Mac because we are
|
||||
// executing in exception context where all other
|
||||
// threads are paused. If the lock is held, skip
|
||||
// thread annotations to avoid deadlock caused by
|
||||
// waiting for a suspended thread. If the lock
|
||||
// isn't held, acquiring it serves no purpose and
|
||||
// can trigger memory allocations.
|
||||
if (sMutex.IsLocked()) {
|
||||
aCallback("");
|
||||
return;
|
||||
}
|
||||
lockNeeded = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (lockNeeded) {
|
||||
sMutex.Lock();
|
||||
}
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
|
||||
if (sThreadAnnotations) {
|
||||
sThreadAnnotations->GetData(aCallback);
|
||||
|
@ -300,15 +240,11 @@ void GetFlatThreadAnnotation(const std::function<void(const char*)>& aCallback,
|
|||
// Maybe already shutdown: call aCallback with empty annotation data.
|
||||
aCallback("");
|
||||
}
|
||||
|
||||
if (lockNeeded) {
|
||||
sMutex.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void ShutdownThreadAnnotation()
|
||||
{
|
||||
CrashReporterAutoLock lock(sMutex);
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
|
||||
sInitialized = false;
|
||||
sThreadAnnotations.reset();
|
||||
|
|
|
@ -16,8 +16,7 @@ void InitThreadAnnotation();
|
|||
|
||||
void ShutdownThreadAnnotation();
|
||||
|
||||
void GetFlatThreadAnnotation(const std::function<void(const char*)>& aCallback,
|
||||
bool aIsHandlingException=false);
|
||||
void GetFlatThreadAnnotation(const std::function<void(const char*)>& aCallback);
|
||||
|
||||
class InitThreadAnnotationRAII {
|
||||
public:
|
||||
|
|
|
@ -1111,7 +1111,7 @@ MinidumpCallback(
|
|||
WriteLiteral(eventFile, "\n");
|
||||
}
|
||||
};
|
||||
GetFlatThreadAnnotation(getThreadAnnotationCB, false);
|
||||
GetFlatThreadAnnotation(getThreadAnnotationCB);
|
||||
}
|
||||
|
||||
if (!doReport) {
|
||||
|
@ -1297,7 +1297,7 @@ PrepareChildExceptionTimeAnnotations(void* context)
|
|||
WriteLiteral(apiData, "\n");
|
||||
}
|
||||
};
|
||||
GetFlatThreadAnnotation(getThreadAnnotationCB, true);
|
||||
GetFlatThreadAnnotation(getThreadAnnotationCB);
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
|
|
Загрузка…
Ссылка в новой задаче