зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1763593 - Bypass NS_DispatchToMainThread's assert while handling the leak. r=TravisLong
Differential Revision: https://phabricator.services.mozilla.com/D144175
This commit is contained in:
Родитель
bb93306954
Коммит
e3d4d5098d
|
@ -14,6 +14,7 @@ Jinja2 template is not. Pleas file bugs! #}
|
|||
{% if probe_type == "Scalar" %}
|
||||
#include "mozilla/Tuple.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsTHashMap.h"
|
||||
{% endif %}
|
||||
#include "nsThreadUtils.h"
|
||||
|
@ -52,10 +53,15 @@ static inline Maybe<TimerToStampMutex::AutoLock> GetTimerIdToStartsLock() {
|
|||
// In that event we leak. Grab a pointer so we have something to NS_RELEASE
|
||||
// in that case.
|
||||
nsIRunnable* temp = cleanupFn.get();
|
||||
if (NS_FAILED(NS_DispatchToMainThread(cleanupFn.forget()))) {
|
||||
nsCOMPtr<nsIThread> mainThread;
|
||||
if (NS_FAILED(NS_GetMainThread(getter_AddRefs(mainThread)))
|
||||
|| NS_FAILED(mainThread->Dispatch(cleanupFn.forget(), nsIThread::DISPATCH_NORMAL))
|
||||
) {
|
||||
// Failed to dispatch cleanup routine.
|
||||
// First, un-leak the runnable:
|
||||
NS_RELEASE(temp);
|
||||
// First, un-leak the runnable (but only if we actually attempted dispatch)
|
||||
if (!cleanupFn) {
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
// Next, cleanup immediately, and allow metrics to try again later.
|
||||
*lock = nullptr;
|
||||
return Nothing();
|
||||
|
@ -93,10 +99,15 @@ static inline Maybe<SubmetricToMirrorMutex::AutoLock> GetLabeledMirrorLock() {
|
|||
// In that event we leak. Grab a pointer so we have something to NS_RELEASE
|
||||
// in that case.
|
||||
nsIRunnable* temp = cleanupFn.get();
|
||||
if (NS_FAILED(NS_DispatchToMainThread(cleanupFn.forget()))) {
|
||||
nsCOMPtr<nsIThread> mainThread;
|
||||
if (NS_FAILED(NS_GetMainThread(getter_AddRefs(mainThread)))
|
||||
|| NS_FAILED(mainThread->Dispatch(cleanupFn.forget(), nsIThread::DISPATCH_NORMAL))
|
||||
) {
|
||||
// Failed to dispatch cleanup routine.
|
||||
// First, un-leak the runnable:
|
||||
NS_RELEASE(temp);
|
||||
// First, un-leak the runnable (but only if we actually attempted dispatch)
|
||||
if (!cleanupFn) {
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
// Next, cleanup immediately, and allow metrics to try again later.
|
||||
*lock = nullptr;
|
||||
return Nothing();
|
||||
|
@ -154,10 +165,15 @@ static inline Maybe<TimesToStartsMutex::AutoLock> GetTimesToStartsLock() {
|
|||
// In that event we leak. Grab a pointer so we have something to NS_RELEASE
|
||||
// in that case.
|
||||
nsIRunnable* temp = cleanupFn.get();
|
||||
if (NS_FAILED(NS_DispatchToMainThread(cleanupFn.forget()))) {
|
||||
nsCOMPtr<nsIThread> mainThread;
|
||||
if (NS_FAILED(NS_GetMainThread(getter_AddRefs(mainThread)))
|
||||
|| NS_FAILED(mainThread->Dispatch(cleanupFn.forget(), nsIThread::DISPATCH_NORMAL))
|
||||
) {
|
||||
// Failed to dispatch cleanup routine.
|
||||
// First, un-leak the runnable:
|
||||
NS_RELEASE(temp);
|
||||
// First, un-leak the runnable (but only if we actually attempted dispatch)
|
||||
if (!cleanupFn) {
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
// Next, cleanup immediately, and allow metrics to try again later.
|
||||
*lock = nullptr;
|
||||
return Nothing();
|
||||
|
|
|
@ -44,10 +44,15 @@ static inline Maybe<TimerToStampMutex::AutoLock> GetTimerIdToStartsLock() {
|
|||
// In that event we leak. Grab a pointer so we have something to NS_RELEASE
|
||||
// in that case.
|
||||
nsIRunnable* temp = cleanupFn.get();
|
||||
if (NS_FAILED(NS_DispatchToMainThread(cleanupFn.forget()))) {
|
||||
nsCOMPtr<nsIThread> mainThread;
|
||||
if (NS_FAILED(NS_GetMainThread(getter_AddRefs(mainThread)))
|
||||
|| NS_FAILED(mainThread->Dispatch(cleanupFn.forget(), nsIThread::DISPATCH_NORMAL))
|
||||
) {
|
||||
// Failed to dispatch cleanup routine.
|
||||
// First, un-leak the runnable:
|
||||
NS_RELEASE(temp);
|
||||
// First, un-leak the runnable (but only if we actually attempted dispatch)
|
||||
if (!cleanupFn) {
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
// Next, cleanup immediately, and allow metrics to try again later.
|
||||
*lock = nullptr;
|
||||
return Nothing();
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/DataMutex.h"
|
||||
#include "mozilla/Tuple.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsTHashMap.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
|
@ -50,10 +51,15 @@ static inline Maybe<SubmetricToMirrorMutex::AutoLock> GetLabeledMirrorLock() {
|
|||
// In that event we leak. Grab a pointer so we have something to NS_RELEASE
|
||||
// in that case.
|
||||
nsIRunnable* temp = cleanupFn.get();
|
||||
if (NS_FAILED(NS_DispatchToMainThread(cleanupFn.forget()))) {
|
||||
nsCOMPtr<nsIThread> mainThread;
|
||||
if (NS_FAILED(NS_GetMainThread(getter_AddRefs(mainThread)))
|
||||
|| NS_FAILED(mainThread->Dispatch(cleanupFn.forget(), nsIThread::DISPATCH_NORMAL))
|
||||
) {
|
||||
// Failed to dispatch cleanup routine.
|
||||
// First, un-leak the runnable:
|
||||
NS_RELEASE(temp);
|
||||
// First, un-leak the runnable (but only if we actually attempted dispatch)
|
||||
if (!cleanupFn) {
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
// Next, cleanup immediately, and allow metrics to try again later.
|
||||
*lock = nullptr;
|
||||
return Nothing();
|
||||
|
@ -111,10 +117,15 @@ static inline Maybe<TimesToStartsMutex::AutoLock> GetTimesToStartsLock() {
|
|||
// In that event we leak. Grab a pointer so we have something to NS_RELEASE
|
||||
// in that case.
|
||||
nsIRunnable* temp = cleanupFn.get();
|
||||
if (NS_FAILED(NS_DispatchToMainThread(cleanupFn.forget()))) {
|
||||
nsCOMPtr<nsIThread> mainThread;
|
||||
if (NS_FAILED(NS_GetMainThread(getter_AddRefs(mainThread)))
|
||||
|| NS_FAILED(mainThread->Dispatch(cleanupFn.forget(), nsIThread::DISPATCH_NORMAL))
|
||||
) {
|
||||
// Failed to dispatch cleanup routine.
|
||||
// First, un-leak the runnable:
|
||||
NS_RELEASE(temp);
|
||||
// First, un-leak the runnable (but only if we actually attempted dispatch)
|
||||
if (!cleanupFn) {
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
// Next, cleanup immediately, and allow metrics to try again later.
|
||||
*lock = nullptr;
|
||||
return Nothing();
|
||||
|
|
Загрузка…
Ссылка в новой задаче