mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 22:35:43 +00:00
Bug 956899 - Use js::Thread for js::ExclusiveData tests; r=fitzgen
This commit is contained in:
parent
069ed68aab
commit
7d0d6daa29
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user