Bug 1503016 - Use TraceableFifo for JSContext::jobQueue. r=sfink

Differential Revision: https://phabricator.services.mozilla.com/D10361

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jason Orendorff 2018-11-01 17:19:06 +00:00
Родитель 25751f87e6
Коммит 8804208609
3 изменённых файлов: 9 добавлений и 19 удалений

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

@ -39,7 +39,7 @@ class TraceableFifo : public js::Fifo<T, MinInlineCapacity, AllocPolicy>
explicit TraceableFifo(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {}
TraceableFifo(TraceableFifo&& rhs) : Base(std::move(rhs)) { }
TraceableFifo& operator=(TraceableFifo&& rhs) { return Base::operator=(std::move(rhs)); }
TraceableFifo& operator=(TraceableFifo&& rhs) = default;
TraceableFifo(const TraceableFifo&) = delete;
TraceableFifo& operator=(const TraceableFifo&) = delete;

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

@ -1143,7 +1143,7 @@ InternalEnqueuePromiseJobCallback(JSContext* cx, JS::HandleObject promise,
{
MOZ_ASSERT(job);
JS::JobQueueMayNotBeEmpty(cx);
if (!cx->jobQueue->append(job)) {
if (!cx->jobQueue->pushBack(job)) {
ReportOutOfMemory(cx);
return false;
}
@ -1178,7 +1178,7 @@ js::EnqueueJob(JSContext* cx, JS::HandleObject job)
{
MOZ_ASSERT(cx->jobQueue);
JS::JobQueueMayNotBeEmpty(cx);
if (!cx->jobQueue->append(job)) {
if (!cx->jobQueue->pushBack(job)) {
ReportOutOfMemory(cx);
return false;
}
@ -1216,30 +1216,19 @@ js::RunJobs(JSContext* cx)
RootedValue rval(cx);
// Execute jobs in a loop until we've reached the end of the queue.
// Since executing a job can trigger enqueuing of additional jobs,
// it's crucial to re-check the queue length during each iteration.
for (size_t i = 0; i < cx->jobQueue->length(); i++) {
while (!cx->jobQueue->empty()) {
// A previous job might have set this flag. E.g., the js shell
// sets it if the `quit` builtin function is called.
if (cx->stopDrainingJobQueue) {
break;
}
job = cx->jobQueue->get()[i];
// It's possible that queue draining was interrupted prematurely,
// leaving the queue partly processed. In that case, slots for
// already-executed entries will contain nullptrs, which we should
// just skip.
if (!job) {
continue;
}
cx->jobQueue->get()[i] = nullptr;
job = cx->jobQueue->front();
cx->jobQueue->popFront();
// If the next job is the last job in the job queue, allow
// skipping the standard job queuing behavior.
if (i == cx->jobQueue->length() - 1) {
if (cx->jobQueue->empty()) {
JS::JobQueueIsEmpty(cx);
}

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

@ -11,6 +11,7 @@
#include "mozilla/MemoryReporting.h"
#include "ds/TraceableFifo.h"
#include "js/CharacterEncoding.h"
#include "js/GCVector.h"
#include "js/Result.h"
@ -70,7 +71,7 @@ struct AutoResolving;
struct HelperThread;
using JobQueue = GCVector<JSObject*, 0, SystemAllocPolicy>;
using JobQueue = TraceableFifo<JSObject*, 0, SystemAllocPolicy>;
class AutoLockScriptData;