Bug 1308655 - Remove js::Thread's infallible constructor. r=froydnj

This commit is contained in:
Jan de Mooij 2016-10-12 11:38:14 +02:00
Родитель 83c01fe1ce
Коммит 84813b6a9d
5 изменённых файлов: 24 добавлений и 21 удалений

Просмотреть файл

@ -68,7 +68,8 @@ BEGIN_TEST(testSharedImmutableStringsCache)
for (auto i : mozilla::MakeRange(NUM_THREADS)) {
auto cacheAndIndex = js_new<CacheAndIndex>(&cache, i);
CHECK(cacheAndIndex);
threads.infallibleEmplaceBack(getString, cacheAndIndex);
threads.infallibleEmplaceBack();
CHECK(threads.back().init(getString, cacheAndIndex));
}
for (auto& thread : threads)

Просмотреть файл

@ -77,7 +77,8 @@ BEGIN_TEST(testExclusiveData)
for (auto i : mozilla::MakeRange(NumThreads)) {
auto counterAndBit = js_new<CounterAndBit>(i, counter);
CHECK(counterAndBit);
CHECK(threads.emplaceBack(setBitAndCheck, counterAndBit));
CHECK(threads.emplaceBack());
CHECK(threads.back().init(setBitAndCheck, counterAndBit));
}
for (auto& thread : threads)

Просмотреть файл

@ -18,7 +18,8 @@
BEGIN_TEST(testThreadingThreadJoin)
{
bool flag = false;
js::Thread thread([](bool* flagp){*flagp = true;}, &flag);
js::Thread thread;
CHECK(thread.init([](bool* flagp){*flagp = true;}, &flag));
CHECK(thread.joinable());
thread.join();
CHECK(flag);
@ -32,7 +33,8 @@ BEGIN_TEST(testThreadingThreadDetach)
// We are going to detach this thread. Unlike join, we can't have it pointing at the stack
// because it might do the write after we have returned and pushed a new frame.
bool* flag = js_new<bool>(false);
js::Thread thread([](bool* flag){*flag = true; js_delete(flag);}, mozilla::Move(flag));
js::Thread thread;
CHECK(thread.init([](bool* flag){*flag = true; js_delete(flag);}, mozilla::Move(flag)));
CHECK(thread.joinable());
thread.detach();
CHECK(!thread.joinable());
@ -43,7 +45,8 @@ END_TEST(testThreadingThreadDetach)
BEGIN_TEST(testThreadingThreadSetName)
{
js::Thread thread([](){js::ThisThread::SetName("JSAPI Test Thread");});
js::Thread thread;
CHECK(thread.init([](){js::ThisThread::SetName("JSAPI Test Thread");}));
thread.detach();
return true;
}
@ -53,7 +56,8 @@ BEGIN_TEST(testThreadingThreadId)
{
CHECK(js::Thread::Id() == js::Thread::Id());
js::Thread::Id fromOther;
js::Thread thread([](js::Thread::Id* idp){*idp = js::ThisThread::GetId();}, &fromOther);
js::Thread thread;
CHECK(thread.init([](js::Thread::Id* idp){*idp = js::ThisThread::GetId();}, &fromOther));
js::Thread::Id fromMain = thread.get_id();
thread.join();
CHECK(fromOther == fromMain);
@ -67,7 +71,8 @@ BEGIN_TEST(testThreadingThreadVectorMoveConstruct)
mozilla::Atomic<int> count(0);
mozilla::Vector<js::Thread, 0, js::SystemAllocPolicy> v;
for (auto i : mozilla::MakeRange(N)) {
CHECK(v.emplaceBack([](mozilla::Atomic<int>* countp){(*countp)++;}, &count));
CHECK(v.emplaceBack());
CHECK(v.back().init([](mozilla::Atomic<int>* countp){(*countp)++;}, &count));
CHECK(v.length() == i + 1);
}
for (auto& th : v)
@ -88,7 +93,8 @@ BEGIN_TEST(testThreadingThreadArgCopy)
{
for (size_t i = 0; i < 10000; ++i) {
bool b = true;
js::Thread thread([](bool bb){MOZ_RELEASE_ASSERT(bb);}, b);
js::Thread thread;
CHECK(thread.init([](bool bb){MOZ_RELEASE_ASSERT(bb);}, b));
b = false;
thread.join();
}

Просмотреть файл

@ -3533,7 +3533,10 @@ ScheduleWatchdog(JSContext* cx, double t)
LockGuard<Mutex> guard(sc->watchdogLock);
if (!sc->watchdogThread) {
MOZ_ASSERT(!sc->watchdogTimeout);
sc->watchdogThread.emplace(WatchdogMain, cx);
sc->watchdogThread.emplace();
AutoEnterOOMUnsafeRegion oomUnsafe;
if (!sc->watchdogThread->init(WatchdogMain, cx))
oomUnsafe.crash("watchdogThread.init");
} else if (!sc->watchdogTimeout || timeout < sc->watchdogTimeout.value()) {
sc->watchdogWakeup.notify_one();
}

Просмотреть файл

@ -99,20 +99,12 @@ public:
, options_(mozilla::Forward<O>(options))
{ }
// Start a thread of execution at functor |f| with parameters |args|. Note
// that the arguments must be either POD or rvalue references (mozilla::Move).
// Attempting to pass a reference will result in the value being copied, which
// may not be the intended behavior. See the comment below on
// ThreadTrampoline::args for an explanation.
template <typename F, typename... Args>
explicit Thread(F&& f, Args&&... args) {
MOZ_RELEASE_ASSERT(init(mozilla::Forward<F>(f),
mozilla::Forward<Args>(args)...));
}
// Start a thread of execution at functor |f| with parameters |args|. This
// method will return false if thread creation fails. This Thread must not
// already have been created.
// already have been created. Note that the arguments must be either POD or
// rvalue references (mozilla::Move). Attempting to pass a reference will
// result in the value being copied, which may not be the intended behavior.
// See the comment below on ThreadTrampoline::args for an explanation.
template <typename F, typename... Args>
MOZ_MUST_USE bool init(F&& f, Args&&... args) {
MOZ_RELEASE_ASSERT(!joinable());