Bug 834882: move InParallelSection() out of ForkJoinSlice and rename Initialize() to InitializeTLS() r=billm

This commit is contained in:
Nicholas D. Matsakis 2013-01-25 13:54:53 -08:00
parent d5dc1a93b2
commit 777ac77877
8 changed files with 23 additions and 21 deletions

View File

@ -882,7 +882,9 @@ DisplayName(JSContext *cx, unsigned argc, jsval *vp)
JSBool
js::testingFunc_inParallelSection(JSContext *cx, unsigned argc, jsval *vp)
{
JS_ASSERT(!ForkJoinSlice::InParallelSection());
// If we were actually *in* a parallel section, then this function
// would be inlined to TRUE in ion-generated code.
JS_ASSERT(!InParallelSection());
JS_SET_RVAL(cx, vp, JSVAL_FALSE);
return true;
}

View File

@ -203,7 +203,7 @@ ion::ParCompareStrings(JSString *str1, JSString *str2)
void
ion::ParallelAbort(JSScript *script)
{
JS_ASSERT(ForkJoinSlice::InParallelSection());
JS_ASSERT(InParallelSection());
ForkJoinSlice *slice = ForkJoinSlice::Current();
@ -216,7 +216,7 @@ ion::ParallelAbort(JSScript *script)
void
ion::ParCallToUncompiledScript(JSFunction *func)
{
JS_ASSERT(ForkJoinSlice::InParallelSection());
JS_ASSERT(InParallelSection());
#ifdef DEBUG
RawScript script = func->nonLazyScript();

View File

@ -1119,7 +1119,7 @@ JS_NewRuntime(uint32_t maxbytes, JSUseHelperThreads useHelperThreads)
return NULL;
#endif
if (!ForkJoinSlice::Initialize())
if (!ForkJoinSlice::InitializeTLS())
return NULL;
if (!rt->init(maxbytes)) {

View File

@ -1416,7 +1416,7 @@ js::array_sort(JSContext *cx, unsigned argc, Value *vp)
}
} else {
/* array.sort() cannot currently be used from parallel code */
JS_ASSERT(!ForkJoinSlice::InParallelSection());
JS_ASSERT(!InParallelSection());
FastInvokeGuard fig(cx, fval);
if (!MergeSort(vec.begin(), n, vec.begin() + n,
SortComparatorFunction(cx, fval, fig))) {
@ -2205,7 +2205,7 @@ array_map(JSContext *cx, unsigned argc, Value *vp)
/* Step 8. */
RootedValue kValue(cx);
JS_ASSERT(!ForkJoinSlice::InParallelSection());
JS_ASSERT(!InParallelSection());
FastInvokeGuard fig(cx, ObjectValue(*callable));
InvokeArgsGuard &ag = fig.args();
while (k < len) {
@ -2286,7 +2286,7 @@ array_filter(JSContext *cx, unsigned argc, Value *vp)
uint32_t to = 0;
/* Step 9. */
JS_ASSERT(!ForkJoinSlice::InParallelSection());
JS_ASSERT(!InParallelSection());
FastInvokeGuard fig(cx, ObjectValue(*callable));
InvokeArgsGuard &ag = fig.args();
RootedValue kValue(cx);

View File

@ -1493,7 +1493,7 @@ RunLastDitchGC(JSContext *cx, JS::Zone *zone, AllocKind thingKind)
* In parallel sections, we do not attempt to refill the free list
* and hence do not encounter last ditch GC.
*/
JS_ASSERT(!ForkJoinSlice::InParallelSection());
JS_ASSERT(!InParallelSection());
PrepareZoneForGC(zone);
@ -4413,7 +4413,7 @@ Collect(JSRuntime *rt, bool incremental, int64_t budget,
JSGCInvocationKind gckind, gcreason::Reason reason)
{
/* GC shouldn't be running in parallel execution mode */
JS_ASSERT(!ForkJoinSlice::InParallelSection());
JS_ASSERT(!InParallelSection());
JS_AbortIfWrongThread(rt);

View File

@ -1124,7 +1124,7 @@ class FastInvokeGuard
, useIon_(ion::IsEnabled(cx))
#endif
{
JS_ASSERT(!ForkJoinSlice::InParallelSection());
JS_ASSERT(!InParallelSection());
initFunction(fval);
}

View File

@ -524,7 +524,7 @@ ForkJoinSlice::check()
}
bool
ForkJoinSlice::Initialize()
ForkJoinSlice::InitializeTLS()
{
#ifdef JS_THREADSAFE
if (!TLSInitialized) {
@ -623,7 +623,7 @@ js::ExecuteForkJoinOp(JSContext *cx, ForkJoinOp &op)
{
#ifdef JS_THREADSAFE
// Recursive use of the ThreadPool is not supported.
JS_ASSERT(!ForkJoinSlice::InParallelSection());
JS_ASSERT(!InParallelSection());
AutoEnterParallelSection enter(cx);

View File

@ -199,16 +199,16 @@ struct ForkJoinSlice
// Check the current state of parallel execution.
static inline ForkJoinSlice *Current();
static inline bool InParallelSection();
static bool Initialize();
// Initializes the thread-local state.
static bool InitializeTLS();
private:
friend class AutoRendezvous;
friend class AutoSetForkJoinSlice;
#ifdef JS_THREADSAFE
// Initialized by Initialize()
// Initialized by InitializeTLS()
static unsigned ThreadPrivateIndex;
static bool TLSInitialized;
#endif
@ -235,6 +235,12 @@ struct ForkJoinOp
virtual bool parallel(ForkJoinSlice &slice) = 0;
};
static inline bool
InParallelSection()
{
return ForkJoinSlice::Current() != NULL;
}
} // namespace js
/* static */ inline js::ForkJoinSlice *
@ -247,10 +253,4 @@ js::ForkJoinSlice::Current()
#endif
}
/* static */ inline bool
js::ForkJoinSlice::InParallelSection()
{
return Current() != NULL;
}
#endif // ForkJoin_h__