Bug 1639230: Remove vendor prefix for printing with webdriver r=jgraham,webdriver...
[gecko.git] / dom / worklet / WorkletThread.h
blobebff01b97f85a892b2608ecf1822c4b637f791a9
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_worklet_WorkletThread_h
8 #define mozilla_dom_worklet_WorkletThread_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/CondVar.h"
12 #include "mozilla/RefPtr.h"
13 #include "mozilla/UniquePtr.h"
14 #include "mozilla/dom/WorkletImpl.h"
15 #include "nsThread.h"
17 class nsIRunnable;
19 namespace mozilla {
20 namespace dom {
22 class WorkletThread final : public nsThread, public nsIObserver {
23 public:
24 NS_DECL_ISUPPORTS_INHERITED
25 NS_DECL_NSIOBSERVER
27 static already_AddRefed<WorkletThread> Create(WorkletImpl* aWorkletImpl);
29 // Threads that call EnsureCycleCollectedJSContext must call
30 // DeleteCycleCollectedJSContext::Get() before terminating. Clients of
31 // Create() do not need to do this as Terminate() will ensure this happens.
32 void EnsureCycleCollectedJSContext(JSRuntime* aParentRuntime);
33 static void DeleteCycleCollectedJSContext();
35 static bool IsOnWorkletThread();
37 static void AssertIsOnWorkletThread();
39 nsresult DispatchRunnable(already_AddRefed<nsIRunnable> aRunnable);
41 void Terminate();
43 private:
44 explicit WorkletThread(WorkletImpl* aWorkletImpl);
45 ~WorkletThread();
47 void RunEventLoop();
48 class PrimaryRunnable;
50 void TerminateInternal();
51 class TerminateRunnable;
53 // This should only be called by consumers that have an
54 // nsIEventTarget/nsIThread pointer.
55 NS_IMETHOD
56 Dispatch(already_AddRefed<nsIRunnable> aRunnable, uint32_t aFlags) override;
58 NS_IMETHOD
59 DispatchFromScript(nsIRunnable* aRunnable, uint32_t aFlags) override;
61 NS_IMETHOD
62 DelayedDispatch(already_AddRefed<nsIRunnable>, uint32_t) override;
64 const RefPtr<WorkletImpl> mWorkletImpl;
66 bool mExitLoop; // worklet execution thread
68 bool mIsTerminating; // main thread
71 } // namespace dom
72 } // namespace mozilla
74 #endif // mozilla_dom_worklet_WorkletThread_h