Bug 1550519 - Show a translucent parent highlight when a subgrid is highlighted....
[gecko.git] / dom / workers / WorkerThread.h
blob8b09001e61d87420d5349cbe88afcd7356f489e0
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_workers_WorkerThread_h__
8 #define mozilla_dom_workers_WorkerThread_h__
10 #include "mozilla/Attributes.h"
11 #include "mozilla/CondVar.h"
12 #include "mozilla/DebugOnly.h"
13 #include "nsISupportsImpl.h"
14 #include "mozilla/RefPtr.h"
15 #include "nsThread.h"
17 class nsIRunnable;
19 namespace mozilla {
20 namespace dom {
22 class WorkerRunnable;
23 class WorkerPrivate;
24 template <class>
25 class WorkerPrivateParent;
27 namespace workerinternals {
28 class RuntimeService;
31 // This class lets us restrict the public methods that can be called on
32 // WorkerThread to RuntimeService and WorkerPrivate without letting them gain
33 // full access to private methods (as would happen if they were simply friends).
34 class WorkerThreadFriendKey {
35 friend class workerinternals::RuntimeService;
36 friend class WorkerPrivate;
37 friend class WorkerPrivateParent<WorkerPrivate>;
39 WorkerThreadFriendKey();
40 ~WorkerThreadFriendKey();
43 class WorkerThread final : public nsThread {
44 class Observer;
46 Mutex mLock;
47 CondVar mWorkerPrivateCondVar;
49 // Protected by nsThread::mLock.
50 WorkerPrivate* mWorkerPrivate;
52 // Only touched on the target thread.
53 RefPtr<Observer> mObserver;
55 // Protected by nsThread::mLock and waited on with mWorkerPrivateCondVar.
56 uint32_t mOtherThreadsDispatchingViaEventTarget;
58 #ifdef DEBUG
59 // Protected by nsThread::mLock.
60 bool mAcceptingNonWorkerRunnables;
61 #endif
63 public:
64 static already_AddRefed<WorkerThread> Create(
65 const WorkerThreadFriendKey& aKey);
67 void SetWorker(const WorkerThreadFriendKey& aKey,
68 WorkerPrivate* aWorkerPrivate);
70 nsresult DispatchPrimaryRunnable(const WorkerThreadFriendKey& aKey,
71 already_AddRefed<nsIRunnable> aRunnable);
73 nsresult DispatchAnyThread(const WorkerThreadFriendKey& aKey,
74 already_AddRefed<WorkerRunnable> aWorkerRunnable);
76 uint32_t RecursionDepth(const WorkerThreadFriendKey& aKey) const;
78 PerformanceCounter* GetPerformanceCounter(nsIRunnable* aEvent) override;
80 NS_INLINE_DECL_REFCOUNTING_INHERITED(WorkerThread, nsThread)
82 private:
83 WorkerThread();
84 ~WorkerThread();
86 // This should only be called by consumers that have an
87 // nsIEventTarget/nsIThread pointer.
88 NS_IMETHOD
89 Dispatch(already_AddRefed<nsIRunnable> aRunnable, uint32_t aFlags) override;
91 NS_IMETHOD
92 DispatchFromScript(nsIRunnable* aRunnable, uint32_t aFlags) override;
94 NS_IMETHOD
95 DelayedDispatch(already_AddRefed<nsIRunnable>, uint32_t) override;
97 void IncrementDispatchCounter();
100 } // namespace dom
101 } // namespace mozilla
103 #endif // mozilla_dom_workers_WorkerThread_h__