Skip to content

Commit 67dad11

Browse files
committed
Bug 995730 - Convert xpcom/threads/ to Gecko style. r=froydnj
--HG-- extra : rebase_source : 1f6f179f44db87f55ebfe5d855192adfad7d1b74
1 parent 9c80e3c commit 67dad11

25 files changed

+1515
-1180
lines changed

xpcom/threads/BackgroundHangMonitor.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BackgroundHangManager
3838

3939
#ifdef MOZ_NUWA_PROCESS
4040
if (IsNuwaProcess()) {
41-
NS_ASSERTION(NuwaMarkCurrentThread != nullptr,
41+
NS_ASSERTION(NuwaMarkCurrentThread,
4242
"NuwaMarkCurrentThread is undefined!");
4343
NuwaMarkCurrentThread(nullptr, nullptr);
4444
}
@@ -117,9 +117,8 @@ class BackgroundHangThread : public LinkedListElement<BackgroundHangThread>
117117

118118
static void Startup()
119119
{
120-
/* We can tolerate init() failing.
121-
The if block turns off warn_unused_result. */
122-
if (!sTlsKey.init()) {}
120+
/* We can tolerate init() failing. */
121+
(void)!sTlsKey.init();
123122
}
124123

125124
// Hang timeout in ticks
@@ -176,18 +175,14 @@ BackgroundHangManager::BackgroundHangManager()
176175
PR_USER_THREAD, MonitorThread, this,
177176
PR_PRIORITY_LOW, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
178177

179-
MOZ_ASSERT(mHangMonitorThread,
180-
"Failed to create monitor thread");
178+
MOZ_ASSERT(mHangMonitorThread, "Failed to create monitor thread");
181179
}
182180

183181
BackgroundHangManager::~BackgroundHangManager()
184182
{
185-
MOZ_ASSERT(mShutdown,
186-
"Destruction without Shutdown call");
187-
MOZ_ASSERT(mHangThreads.isEmpty(),
188-
"Destruction with outstanding monitors");
189-
MOZ_ASSERT(mHangMonitorThread,
190-
"No monitor thread");
183+
MOZ_ASSERT(mShutdown, "Destruction without Shutdown call");
184+
MOZ_ASSERT(mHangThreads.isEmpty(), "Destruction with outstanding monitors");
185+
MOZ_ASSERT(mHangMonitorThread, "No monitor thread");
191186

192187
// PR_CreateThread could have failed above due to resource limitation
193188
if (mHangMonitorThread) {

xpcom/threads/HangMonitor.cpp

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#define REPORT_CHROME_HANGS
2727
#endif
2828

29-
namespace mozilla { namespace HangMonitor {
29+
namespace mozilla {
30+
namespace HangMonitor {
3031

3132
/**
3233
* A flag which may be set from within a debugger to disable the hang
@@ -112,21 +113,22 @@ Crash()
112113

113114
#ifdef REPORT_CHROME_HANGS
114115
static void
115-
ChromeStackWalker(void *aPC, void *aSP, void *aClosure)
116+
ChromeStackWalker(void* aPC, void* aSP, void* aClosure)
116117
{
117118
MOZ_ASSERT(aClosure);
118-
std::vector<uintptr_t> *stack =
119+
std::vector<uintptr_t>* stack =
119120
static_cast<std::vector<uintptr_t>*>(aClosure);
120-
if (stack->size() == MAX_CALL_STACK_PCS)
121+
if (stack->size() == MAX_CALL_STACK_PCS) {
121122
return;
123+
}
122124
MOZ_ASSERT(stack->size() < MAX_CALL_STACK_PCS);
123125
stack->push_back(reinterpret_cast<uintptr_t>(aPC));
124126
}
125127

126128
static void
127-
GetChromeHangReport(Telemetry::ProcessedStack &aStack,
128-
int32_t &aSystemUptime,
129-
int32_t &aFirefoxUptime)
129+
GetChromeHangReport(Telemetry::ProcessedStack& aStack,
130+
int32_t& aSystemUptime,
131+
int32_t& aFirefoxUptime)
130132
{
131133
MOZ_ASSERT(winMainThreadHandle);
132134

@@ -135,14 +137,16 @@ GetChromeHangReport(Telemetry::ProcessedStack &aStack,
135137
std::vector<uintptr_t> rawStack;
136138
rawStack.reserve(MAX_CALL_STACK_PCS);
137139
DWORD ret = ::SuspendThread(winMainThreadHandle);
138-
if (ret == -1)
140+
if (ret == -1) {
139141
return;
142+
}
140143
NS_StackWalk(ChromeStackWalker, /* skipFrames */ 0, /* maxFrames */ 0,
141144
reinterpret_cast<void*>(&rawStack),
142145
reinterpret_cast<uintptr_t>(winMainThreadHandle), nullptr);
143146
ret = ::ResumeThread(winMainThreadHandle);
144-
if (ret == -1)
147+
if (ret == -1) {
145148
return;
149+
}
146150
aStack = Telemetry::GetStackAndModules(rawStack);
147151

148152
// Record system uptime (in minutes) at the time of the hang
@@ -217,8 +221,7 @@ ThreadMain(void*)
217221
}
218222
}
219223
#endif
220-
}
221-
else {
224+
} else {
222225
#ifdef REPORT_CHROME_HANGS
223226
if (waitCount >= 2) {
224227
uint32_t hangDuration = PR_IntervalToSeconds(now - lastTimestamp);
@@ -234,8 +237,7 @@ ThreadMain(void*)
234237
PRIntervalTime timeout;
235238
if (gTimeout <= 0) {
236239
timeout = PR_INTERVAL_NO_TIMEOUT;
237-
}
238-
else {
240+
} else {
239241
timeout = PR_MillisecondsToInterval(gTimeout * 500);
240242
}
241243
lock.Wait(timeout);
@@ -248,8 +250,9 @@ Startup()
248250
// The hang detector only runs in chrome processes. If you change this,
249251
// you must also deal with the threadsafety of AnnotateCrashReport in
250252
// non-chrome processes!
251-
if (GeckoProcessType_Default != XRE_GetProcessType())
253+
if (GeckoProcessType_Default != XRE_GetProcessType()) {
252254
return;
255+
}
253256

254257
MOZ_ASSERT(!gMonitor, "Hang monitor already initialized");
255258
gMonitor = new Monitor("HangMonitor");
@@ -261,8 +264,9 @@ Startup()
261264
Preferences::RegisterCallback(PrefChanged, kTelemetryPrefName, nullptr);
262265
winMainThreadHandle =
263266
OpenThread(THREAD_ALL_ACCESS, FALSE, GetCurrentThreadId());
264-
if (!winMainThreadHandle)
267+
if (!winMainThreadHandle) {
265268
return;
269+
}
266270
#endif
267271

268272
// Don't actually start measuring hangs until we hit the main event loop.
@@ -280,12 +284,14 @@ Startup()
280284
void
281285
Shutdown()
282286
{
283-
if (GeckoProcessType_Default != XRE_GetProcessType())
287+
if (GeckoProcessType_Default != XRE_GetProcessType()) {
284288
return;
289+
}
285290

286291
MOZ_ASSERT(gMonitor, "Hang monitor not started");
287292

288-
{ // Scope the lock we're going to delete later
293+
{
294+
// Scope the lock we're going to delete later
289295
MonitorAutoLock lock(*gMonitor);
290296
gShutdown = true;
291297
lock.Notify();
@@ -307,11 +313,11 @@ IsUIMessageWaiting()
307313
#ifndef XP_WIN
308314
return false;
309315
#else
310-
#define NS_WM_IMEFIRST WM_IME_SETCONTEXT
311-
#define NS_WM_IMELAST WM_IME_KEYUP
316+
#define NS_WM_IMEFIRST WM_IME_SETCONTEXT
317+
#define NS_WM_IMELAST WM_IME_KEYUP
312318
BOOL haveUIMessageWaiting = FALSE;
313319
MSG msg;
314-
haveUIMessageWaiting |= ::PeekMessageW(&msg, nullptr, WM_KEYFIRST,
320+
haveUIMessageWaiting |= ::PeekMessageW(&msg, nullptr, WM_KEYFIRST,
315321
WM_IME_KEYLAST, PM_NOREMOVE);
316322
haveUIMessageWaiting |= ::PeekMessageW(&msg, nullptr, NS_WM_IMEFIRST,
317323
NS_WM_IMELAST, PM_NOREMOVE);
@@ -322,32 +328,32 @@ IsUIMessageWaiting()
322328
}
323329

324330
void
325-
NotifyActivity(ActivityType activityType)
331+
NotifyActivity(ActivityType aActivityType)
326332
{
327333
MOZ_ASSERT(NS_IsMainThread(),
328334
"HangMonitor::Notify called from off the main thread.");
329335

330336
// Determine the activity type more specifically
331-
if (activityType == kGeneralActivity) {
332-
activityType = IsUIMessageWaiting() ? kActivityUIAVail :
333-
kActivityNoUIAVail;
337+
if (aActivityType == kGeneralActivity) {
338+
aActivityType = IsUIMessageWaiting() ? kActivityUIAVail :
339+
kActivityNoUIAVail;
334340
}
335341

336342
// Calculate the cumulative amount of lag time since the last UI message
337343
static uint32_t cumulativeUILagMS = 0;
338-
switch(activityType) {
339-
case kActivityNoUIAVail:
340-
cumulativeUILagMS = 0;
341-
break;
342-
case kActivityUIAVail:
343-
case kUIActivity:
344-
if (gTimestamp != PR_INTERVAL_NO_WAIT) {
345-
cumulativeUILagMS += PR_IntervalToMilliseconds(PR_IntervalNow() -
346-
gTimestamp);
347-
}
348-
break;
349-
default:
350-
break;
344+
switch (aActivityType) {
345+
case kActivityNoUIAVail:
346+
cumulativeUILagMS = 0;
347+
break;
348+
case kActivityUIAVail:
349+
case kUIActivity:
350+
if (gTimestamp != PR_INTERVAL_NO_WAIT) {
351+
cumulativeUILagMS += PR_IntervalToMilliseconds(PR_IntervalNow() -
352+
gTimestamp);
353+
}
354+
break;
355+
default:
356+
break;
351357
}
352358

353359
// This is not a locked activity because PRTimeStamp is a 32-bit quantity
@@ -357,7 +363,7 @@ NotifyActivity(ActivityType activityType)
357363

358364
// If we have UI activity we should reset the timer and report it if it is
359365
// significant enough.
360-
if (activityType == kUIActivity) {
366+
if (aActivityType == kUIActivity) {
361367
// The minimum amount of lag time that we should report for telemetry data.
362368
// Mozilla's UI responsiveness goal is 50ms
363369
static const uint32_t kUIResponsivenessThresholdMS = 50;
@@ -387,4 +393,5 @@ Suspend()
387393
}
388394
}
389395

390-
} } // namespace mozilla::HangMonitor
396+
} // namespace HangMonitor
397+
} // namespace mozilla

xpcom/threads/HangMonitor.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
23
/* This Source Code Form is subject to the terms of the Mozilla Public
34
* License, v. 2.0. If a copy of the MPL was not distributed with this
45
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
56

67
#ifndef mozilla_HangMonitor_h
78
#define mozilla_HangMonitor_h
89

9-
namespace mozilla { namespace HangMonitor {
10+
namespace mozilla {
11+
namespace HangMonitor {
1012

1113
/**
1214
* Signifies the type of activity in question
1315
*/
14-
enum ActivityType {
16+
enum ActivityType
17+
{
1518
/* There is activity and it is known to be UI related activity. */
1619
kUIActivity,
1720

@@ -49,6 +52,7 @@ void NotifyActivity(ActivityType activityType = kGeneralActivity);
4952
*/
5053
void Suspend();
5154

52-
} } // namespace mozilla::HangMonitor
55+
} // namespace HangMonitor
56+
} // namespace mozilla
5357

5458
#endif // mozilla_HangMonitor_h

0 commit comments

Comments
 (0)