Skip to content

Commit 628d7fb

Browse files
committed
Bug 1523949 - part 2 - switch BlockingResourceBase to MOZ_THREAD_LOCAL; r=erahm,emilio
This change results in somewhat nicer code and should be slightly more performant.
1 parent 0d56a70 commit 628d7fb

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

layout/style/ServoBindings.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ opaque-types = [
380380
# don't align properly on Linux 32-bit
381381
"mozilla::SchedulerGroup", # Non-standard-layout packing of field into superclass
382382
"mozilla::detail::GkAtoms", # https://bugzilla.mozilla.org/show_bug.cgi?id=1517685
383+
"mozilla::detail::ThreadLocal.*",
383384
]
384385

385386
# All cbindgen-types are in mod "structs::root::mozilla".

xpcom/threads/BlockingResourceBase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const char* const BlockingResourceBase::kResourceTypeName[] = {
4444
#ifdef DEBUG
4545

4646
PRCallOnceType BlockingResourceBase::sCallOnce;
47-
unsigned BlockingResourceBase::sResourceAcqnChainFrontTPI = (unsigned)-1;
47+
MOZ_THREAD_LOCAL(BlockingResourceBase*) BlockingResourceBase::sResourceAcqnChainFront;
4848
BlockingResourceBase::DDT* BlockingResourceBase::sDeadlockDetector;
4949

5050
void BlockingResourceBase::StackWalkCallback(uint32_t aFrameNumber, void* aPc,
@@ -230,7 +230,7 @@ size_t BlockingResourceBase::SizeOfDeadlockDetector(
230230
}
231231

232232
PRStatus BlockingResourceBase::InitStatics() {
233-
PR_NewThreadPrivateIndex(&sResourceAcqnChainFrontTPI, 0);
233+
MOZ_ASSERT(sResourceAcqnChainFront.init());
234234
sDeadlockDetector = new DDT();
235235
if (!sDeadlockDetector) {
236236
MOZ_CRASH("can't allocate deadlock detector");

xpcom/threads/BlockingResourceBase.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define mozilla_BlockingResourceBase_h
99

1010
#include "mozilla/Logging.h"
11+
#include "mozilla/ThreadLocal.h"
1112

1213
#include "nscore.h"
1314
#include "nsDebug.h"
@@ -152,8 +153,7 @@ class BlockingResourceBase {
152153
* resource acquired.
153154
*/
154155
static BlockingResourceBase* ResourceChainFront() {
155-
return (BlockingResourceBase*)PR_GetThreadPrivate(
156-
sResourceAcqnChainFrontTPI);
156+
return sResourceAcqnChainFront.get();
157157
}
158158

159159
/**
@@ -175,7 +175,7 @@ class BlockingResourceBase {
175175
*/
176176
void ResourceChainAppend(BlockingResourceBase* aPrev) {
177177
mChainPrev = aPrev;
178-
PR_SetThreadPrivate(sResourceAcqnChainFrontTPI, this);
178+
sResourceAcqnChainFront.set(this);
179179
} // NS_NEEDS_RESOURCE(this)
180180

181181
/**
@@ -186,7 +186,7 @@ class BlockingResourceBase {
186186
*/
187187
void ResourceChainRemove() {
188188
NS_ASSERTION(this == ResourceChainFront(), "not at chain front");
189-
PR_SetThreadPrivate(sResourceAcqnChainFrontTPI, mChainPrev);
189+
sResourceAcqnChainFront.set(mChainPrev);
190190
} // NS_NEEDS_RESOURCE(this)
191191

192192
/**
@@ -280,11 +280,10 @@ class BlockingResourceBase {
280280
static PRCallOnceType sCallOnce;
281281

282282
/**
283-
* sResourceAcqnChainFrontTPI
284-
* Thread-private index to the front of each thread's resource
283+
* Thread-private pointer to the front of each thread's resource
285284
* acquisition chain.
286285
*/
287-
static unsigned sResourceAcqnChainFrontTPI;
286+
static MOZ_THREAD_LOCAL(BlockingResourceBase*) sResourceAcqnChainFront;
288287

289288
/**
290289
* sDeadlockDetector

0 commit comments

Comments
 (0)