/work/obj-fuzz/dist/include/mozilla/ThreadEventQueue.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef mozilla_ThreadEventQueue_h |
8 | | #define mozilla_ThreadEventQueue_h |
9 | | |
10 | | #include "mozilla/AbstractEventQueue.h" |
11 | | #include "mozilla/CondVar.h" |
12 | | #include "mozilla/SynchronizedEventQueue.h" |
13 | | #include "nsCOMPtr.h" |
14 | | #include "nsTArray.h" |
15 | | |
16 | | class nsIEventTarget; |
17 | | class nsISerialEventTarget; |
18 | | class nsIThreadObserver; |
19 | | |
20 | | namespace mozilla { |
21 | | |
22 | | class EventQueue; |
23 | | |
24 | | template<typename InnerQueueT> |
25 | | class PrioritizedEventQueue; |
26 | | |
27 | | class LabeledEventQueue; |
28 | | |
29 | | class ThreadEventTarget; |
30 | | |
31 | | // A ThreadEventQueue implements normal monitor-style synchronization over the |
32 | | // InnerQueueT AbstractEventQueue. It also implements PushEventQueue and |
33 | | // PopEventQueue for workers (see the documentation below for an explanation of |
34 | | // those). All threads use a ThreadEventQueue as their event queue. InnerQueueT |
35 | | // is a template parameter to avoid virtual dispatch overhead. |
36 | | template<class InnerQueueT> |
37 | | class ThreadEventQueue final : public SynchronizedEventQueue |
38 | | { |
39 | | public: |
40 | | explicit ThreadEventQueue(UniquePtr<InnerQueueT> aQueue); |
41 | | |
42 | | bool PutEvent(already_AddRefed<nsIRunnable>&& aEvent, |
43 | | EventPriority aPriority) final; |
44 | | |
45 | | already_AddRefed<nsIRunnable> GetEvent(bool aMayWait, |
46 | | EventPriority* aPriority) final; |
47 | | bool HasPendingEvent() final; |
48 | | |
49 | | bool ShutdownIfNoPendingEvents() final; |
50 | | |
51 | 0 | void Disconnect(const MutexAutoLock& aProofOfLock) final {} Unexecuted instantiation: mozilla::ThreadEventQueue<mozilla::EventQueue>::Disconnect(mozilla::BaseAutoLock<mozilla::Mutex&> const&) Unexecuted instantiation: mozilla::ThreadEventQueue<mozilla::PrioritizedEventQueue<mozilla::EventQueue> >::Disconnect(mozilla::BaseAutoLock<mozilla::Mutex&> const&) Unexecuted instantiation: mozilla::ThreadEventQueue<mozilla::PrioritizedEventQueue<mozilla::LabeledEventQueue> >::Disconnect(mozilla::BaseAutoLock<mozilla::Mutex&> const&) |
52 | | |
53 | | void EnableInputEventPrioritization() final; |
54 | | void FlushInputEventPrioritization() final; |
55 | | void SuspendInputEventPrioritization() final; |
56 | | void ResumeInputEventPrioritization() final; |
57 | | |
58 | | /** |
59 | | * This method causes any events currently enqueued on the thread to be |
60 | | * suppressed until PopEventQueue is called, and any event dispatched to this |
61 | | * thread's nsIEventTarget will queue as well. Calls to PushEventQueue may be |
62 | | * nested and must each be paired with a call to PopEventQueue in order to |
63 | | * restore the original state of the thread. The returned nsIEventTarget may |
64 | | * be used to push events onto the nested queue. Dispatching will be disabled |
65 | | * once the event queue is popped. The thread will only ever process pending |
66 | | * events for the innermost event queue. Must only be called on the target |
67 | | * thread. |
68 | | */ |
69 | | already_AddRefed<nsISerialEventTarget> PushEventQueue(); |
70 | | |
71 | | /** |
72 | | * Revert a call to PushEventQueue. When an event queue is popped, any events |
73 | | * remaining in the queue are appended to the elder queue. This also causes |
74 | | * the nsIEventTarget returned from PushEventQueue to stop dispatching events. |
75 | | * Must only be called on the target thread, and with the innermost event |
76 | | * queue. |
77 | | */ |
78 | | void PopEventQueue(nsIEventTarget* aTarget); |
79 | | |
80 | | already_AddRefed<nsIThreadObserver> GetObserver() final; |
81 | | already_AddRefed<nsIThreadObserver> GetObserverOnThread() final; |
82 | | void SetObserver(nsIThreadObserver* aObserver) final; |
83 | | |
84 | 3 | Mutex& MutexRef() { return mLock; } Unexecuted instantiation: mozilla::ThreadEventQueue<mozilla::EventQueue>::MutexRef() mozilla::ThreadEventQueue<mozilla::PrioritizedEventQueue<mozilla::EventQueue> >::MutexRef() Line | Count | Source | 84 | 3 | Mutex& MutexRef() { return mLock; } |
Unexecuted instantiation: mozilla::ThreadEventQueue<mozilla::PrioritizedEventQueue<mozilla::LabeledEventQueue> >::MutexRef() |
85 | | |
86 | | size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; |
87 | | |
88 | | private: |
89 | | class NestedSink; |
90 | | |
91 | | virtual ~ThreadEventQueue(); |
92 | | |
93 | | bool PutEventInternal(already_AddRefed<nsIRunnable>&& aEvent, |
94 | | EventPriority aPriority, |
95 | | NestedSink* aQueue); |
96 | | |
97 | | UniquePtr<InnerQueueT> mBaseQueue; |
98 | | |
99 | | struct NestedQueueItem |
100 | | { |
101 | | UniquePtr<EventQueue> mQueue; |
102 | | RefPtr<ThreadEventTarget> mEventTarget; |
103 | | |
104 | | NestedQueueItem(UniquePtr<EventQueue> aQueue, |
105 | | ThreadEventTarget* aEventTarget) |
106 | | : mQueue(std::move(aQueue)) |
107 | | , mEventTarget(aEventTarget) |
108 | 0 | {} Unexecuted instantiation: mozilla::ThreadEventQueue<mozilla::EventQueue>::NestedQueueItem::NestedQueueItem(mozilla::UniquePtr<mozilla::EventQueue, mozilla::DefaultDelete<mozilla::EventQueue> >, mozilla::ThreadEventTarget*) Unexecuted instantiation: mozilla::ThreadEventQueue<mozilla::PrioritizedEventQueue<mozilla::EventQueue> >::NestedQueueItem::NestedQueueItem(mozilla::UniquePtr<mozilla::EventQueue, mozilla::DefaultDelete<mozilla::EventQueue> >, mozilla::ThreadEventTarget*) Unexecuted instantiation: mozilla::ThreadEventQueue<mozilla::PrioritizedEventQueue<mozilla::LabeledEventQueue> >::NestedQueueItem::NestedQueueItem(mozilla::UniquePtr<mozilla::EventQueue, mozilla::DefaultDelete<mozilla::EventQueue> >, mozilla::ThreadEventTarget*) |
109 | | }; |
110 | | |
111 | | nsTArray<NestedQueueItem> mNestedQueues; |
112 | | |
113 | | Mutex mLock; |
114 | | CondVar mEventsAvailable; |
115 | | |
116 | | bool mEventsAreDoomed = false; |
117 | | nsCOMPtr<nsIThreadObserver> mObserver; |
118 | | }; |
119 | | |
120 | | extern template class ThreadEventQueue<EventQueue>; |
121 | | extern template class ThreadEventQueue<PrioritizedEventQueue<EventQueue>>; |
122 | | extern template class ThreadEventQueue<PrioritizedEventQueue<LabeledEventQueue>>; |
123 | | |
124 | | }; // namespace mozilla |
125 | | |
126 | | #endif // mozilla_ThreadEventQueue_h |