Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/dom/webscheduling/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 3 kB image not shown  

Quelle  WebTaskSchedulerWorker.cpp

  Sprache: C
 

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "WebTaskSchedulerWorker.h"
#include "mozilla/dom/WorkerScope.h"
#include "mozilla/dom/TimeoutManager.h"

namespace mozilla::dom {

WebTaskWorkerRunnable::WebTaskWorkerRunnable(
    WorkerPrivate* aWorkerPrivate, WebTaskSchedulerWorker* aSchedulerWorker)
    : WorkerSameThreadRunnable("WebTaskWorkerRunnable"),
      mSchedulerWorker(aSchedulerWorker) {
  MOZ_ASSERT(mSchedulerWorker);
}

RefPtr<WebTaskSchedulerWorker> WebTaskSchedulerWorker::Create(
    WorkerPrivate* aWorkerPrivate) {
  MOZ_ASSERT(aWorkerPrivate);
  aWorkerPrivate->AssertIsOnWorkerThread();

  RefPtr<WebTaskSchedulerWorker> scheduler =
      MakeRefPtr<WebTaskSchedulerWorker>(aWorkerPrivate);

  scheduler->mWorkerRef = StrongWorkerRef::Create(
      aWorkerPrivate, "WebTaskSchedulerWorker", [scheduler]() {
        // Set mWorkerIsShuttingDown as true here to avoid dispatching tasks
        // to worker thread.
        scheduler->mWorkerIsShuttingDown = true;
      });
  if (!scheduler->mWorkerRef) {
    NS_WARNING("Create WebTaskScheduler when Worker is shutting down");
    scheduler->mWorkerIsShuttingDown = true;
  }
  return scheduler;
}

WebTaskSchedulerWorker::WebTaskSchedulerWorker(WorkerPrivate* aWorkerPrivate)
    : WebTaskScheduler(aWorkerPrivate->GlobalScope()) {}

bool WebTaskWorkerRunnable::WorkerRun(JSContext* aCx,
                                      WorkerPrivate* aWorkerPrivate) {
  aWorkerPrivate->AssertIsOnWorkerThread();

  if (mSchedulerWorker) {
    RefPtr<WebTask> task = mSchedulerWorker->GetNextTask();
    if (task) {
      task->Run();
    }
  }
  return true;
}

nsresult WebTaskSchedulerWorker::SetTimeoutForDelayedTask(WebTask* aTask,
                                                          uint64_t aDelay) {
  if (mWorkerIsShuttingDown) {
    return NS_ERROR_ABORT;
  }

  if (!mWorkerRef) {
    return NS_ERROR_UNEXPECTED;
  }

  WorkerPrivate* workerPrivate = mWorkerRef->Private();
  MOZ_ASSERT(workerPrivate);
  workerPrivate->AssertIsOnWorkerThread();

  JSContext* cx = nsContentUtils::GetCurrentJSContext();
  if (!cx) {
    return NS_ERROR_UNEXPECTED;
  }
  RefPtr<DelayedWebTaskHandler> handler =
      new DelayedWebTaskHandler(cx, this, aTask);
  ErrorResult rv;

  int32_t delay = aDelay > INT32_MAX ? INT32_MAX : (int32_t)aDelay;
  workerPrivate->SetTimeout(cx, handler, delay,
                            /* aIsInterval */ false,
                            Timeout::Reason::eDelayedWebTaskTimeout, rv);
  return rv.StealNSResult();
}

bool WebTaskSchedulerWorker::DispatchEventLoopRunnable() {
  if (mWorkerIsShuttingDown) {
    return false;
  }

  if (!mWorkerRef) {
    return false;
  }
  MOZ_ASSERT(mWorkerRef->Private());
  mWorkerRef->Private()->AssertIsOnWorkerThread();

  RefPtr<WebTaskWorkerRunnable> runnable =
      new WebTaskWorkerRunnable(mWorkerRef->Private(), this);
  return runnable->Dispatch(mWorkerRef->Private());
}

void WebTaskSchedulerWorker::Disconnect() {
  if (mWorkerRef) {
    mWorkerRef = nullptr;
  }
  WebTaskScheduler::Disconnect();
}
}  // namespace mozilla::dom

Messung V0.5 in Prozent
C=87 H=92 G=89

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.