Bug 1530419 - Move PROFILER_AUTO_THREAD_SLEEP into WinUtils::WaitForMessage from callers - r=mstange

Both `nsAppShell::ProcessNextNativeEvent()` and `MessagePumpForUI::WaitForWork()` have a `PROFILER_AUTO_THREAD_SLEEP` surrounding the `mozilla::widget::WinUtils::WaitForMessage()` call.
However inside `WaitForMessage()` the call to `PeekMessageW()` may trigger a sequence of events (because the system delivers pending messages) that end in the initialization of a new thread, which invokes `ReentrantMonitor::Wait()` where there is a `PROFILER_AUTO_THREAD_SLEEP`.

To avoid this recursion, this patch moves `PROFILER_AUTO_THREAD_SLEEP` from both callers into `WaitForMessage()` to only enclose the actual potentially-sleeping operation `::MsgWaitForMultipleObjectsEx()`.

Differential Revision: https://phabricator.services.mozilla.com/D72850
This commit is contained in:
Gerald Squelart 2020-04-28 16:22:13 +00:00
Родитель 90d2298d89
Коммит 22a7a23613
3 изменённых файлов: 7 добавлений и 5 удалений

Просмотреть файл

@ -248,8 +248,6 @@ void MessagePumpForUI::WaitForWork() {
if (delay < 0) // Negative value means no timers waiting.
delay = INFINITE;
AUTO_PROFILER_THREAD_SLEEP;
mozilla::widget::WinUtils::WaitForMessage(delay);
}

Просмотреть файл

@ -9,6 +9,7 @@
#include <knownfolders.h>
#include <winioctl.h>
#include "GeckoProfiler.h"
#include "gfxPlatform.h"
#include "gfxUtils.h"
#include "nsWindow.h"
@ -736,8 +737,12 @@ void WinUtils::WaitForMessage(DWORD aTimeoutMs) {
if (elapsed >= aTimeoutMs) {
break;
}
DWORD result = ::MsgWaitForMultipleObjectsEx(0, NULL, aTimeoutMs - elapsed,
MOZ_QS_ALLEVENT, waitFlags);
DWORD result;
{
AUTO_PROFILER_THREAD_SLEEP;
result = ::MsgWaitForMultipleObjectsEx(0, NULL, aTimeoutMs - elapsed,
MOZ_QS_ALLEVENT, waitFlags);
}
NS_WARNING_ASSERTION(result != WAIT_FAILED, "Wait failed");
if (result == WAIT_TIMEOUT) {
break;

Просмотреть файл

@ -543,7 +543,6 @@ bool nsAppShell::ProcessNextNativeEvent(bool mayWait) {
mozilla::BackgroundHangMonitor().NotifyWait();
{
AUTO_PROFILER_LABEL("nsAppShell::ProcessNextNativeEvent::Wait", IDLE);
AUTO_PROFILER_THREAD_SLEEP;
WinUtils::WaitForMessage();
}
}