Bug 956899 - Use js::Thread for js::ExclusiveData tests; r=fitzgen

This commit is contained in:
Terrence Cole 2016-05-11 18:02:55 -07:00
parent 069ed68aab
commit 7d0d6daa29

View File

@ -8,6 +8,7 @@
#include "js/Vector.h"
#include "jsapi-tests/tests.h"
#include "threading/ExclusiveData.h"
#include "threading/Thread.h"
// One thread for each bit in our counter.
const static uint8_t NumThreads = 64;
@ -43,10 +44,8 @@ printDiagnosticMessage(uint64_t seen)
}
void
setBitAndCheck(void* arg)
setBitAndCheck(CounterAndBit& counterAndBit)
{
auto& counterAndBit = *static_cast<CounterAndBit*>(arg);
while (true) {
{
// Set our bit. Repeatedly setting it is idempotent.
@ -72,26 +71,17 @@ BEGIN_TEST(testExclusiveData)
{
js::ExclusiveData<uint64_t> counter(0);
js::Vector<PRThread*> threads(cx);
js::Vector<js::Thread> threads(cx);
CHECK(threads.reserve(NumThreads));
for (auto i : mozilla::MakeRange(NumThreads)) {
auto counterAndBit = js_new<CounterAndBit>(i, counter);
CHECK(counterAndBit);
auto thread = PR_CreateThread(PR_USER_THREAD,
setBitAndCheck,
(void *) counterAndBit,
PR_PRIORITY_NORMAL,
PR_LOCAL_THREAD,
PR_JOINABLE_THREAD,
0);
CHECK(thread);
threads.infallibleAppend(thread);
CHECK(threads.emplaceBack(setBitAndCheck, *counterAndBit));
}
for (auto thread : threads) {
CHECK(PR_JoinThread(thread) == PR_SUCCESS);
}
for (auto& thread : threads)
thread.join();
return true;
}