1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_WorkerEventTarget_h
8 #define mozilla_dom_WorkerEventTarget_h
10 #include "nsISerialEventTarget.h"
11 #include "mozilla/Mutex.h"
18 class WorkerEventTarget final
: public nsISerialEventTarget
{
20 // The WorkerEventTarget supports different dispatch behaviors:
22 // * Hybrid targets will attempt to dispatch as a normal runnable,
23 // but fallback to a control runnable if that fails. This is
24 // often necessary for code that wants normal dispatch order, but
25 // also needs to execute while the worker is shutting down (possibly
26 // with a holder in place.)
28 // * ControlOnly targets will simply dispatch a control runnable.
29 enum class Behavior
: uint8_t { Hybrid
, ControlOnly
};
32 mozilla::Mutex mMutex
;
33 WorkerPrivate
* mWorkerPrivate
;
34 const Behavior mBehavior
;
36 ~WorkerEventTarget() = default;
39 WorkerEventTarget(WorkerPrivate
* aWorkerPrivate
, Behavior aBehavior
);
41 void ForgetWorkerPrivate(WorkerPrivate
* aWorkerPrivate
);
43 NS_DECL_THREADSAFE_ISUPPORTS
44 NS_DECL_NSIEVENTTARGET
45 NS_DECL_NSISERIALEVENTTARGET
49 } // namespace mozilla
51 #endif // mozilla_dom_WorkerEventTarget_h