Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/AbstractEventQueue.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_AbstractEventQueue_h
8
#define mozilla_AbstractEventQueue_h
9
10
#include "mozilla/AlreadyAddRefed.h"
11
#include "mozilla/MemoryReporting.h"
12
#include "mozilla/Mutex.h"
13
14
class nsIRunnable;
15
16
namespace mozilla {
17
18
enum class EventPriority
19
{
20
  High,
21
  Input,
22
  Normal,
23
  Idle,
24
25
  Count
26
};
27
28
// AbstractEventQueue is an abstract base class for all our unsynchronized event
29
// queue implementations:
30
// - EventQueue: A queue of runnables. Used for non-main threads.
31
// - PrioritizedEventQueue: Contains a queue for each priority level.
32
//       Has heuristics to decide which queue to pop from. Events are
33
//       pushed into the queue corresponding to their priority.
34
//       Used for the main thread.
35
//
36
// Since AbstractEventQueue implementations are unsynchronized, they should be
37
// wrapped in an outer SynchronizedEventQueue implementation (like
38
// ThreadEventQueue).
39
//
40
// Subclasses should also define a `static const bool SupportsPrioritization`
41
// member to indicate whether the subclass cares about runnable priorities
42
// implemented through nsIRunnablePriority.
43
class AbstractEventQueue
44
{
45
public:
46
  // Add an event to the end of the queue. Implementors are free to use
47
  // aPriority however they wish.  If the runnable supports nsIRunnablePriority
48
  // and the implementing class supports prioritization, aPriority represents
49
  // the result of calling nsIRunnablePriority::GetPriority().
50
  virtual void PutEvent(already_AddRefed<nsIRunnable>&& aEvent,
51
                        EventPriority aPriority,
52
                        const MutexAutoLock& aProofOfLock) = 0;
53
54
  // Get an event from the front of the queue. aPriority is an out param. If the
55
  // implementation supports priorities, then this should be the same priority
56
  // that the event was pushed with. aPriority may be null. This should return
57
  // null if the queue is non-empty but the event in front is not ready to run.
58
  virtual already_AddRefed<nsIRunnable> GetEvent(EventPriority* aPriority,
59
                                                 const MutexAutoLock& aProofOfLock) = 0;
60
61
  // Returns true if the queue is empty. Implies !HasReadyEvent().
62
  virtual bool IsEmpty(const MutexAutoLock& aProofOfLock) = 0;
63
64
  // Returns true if the queue is non-empty and if the event in front is ready
65
  // to run. Implies !IsEmpty(). This should return true iff GetEvent returns a
66
  // non-null value.
67
  virtual bool HasReadyEvent(const MutexAutoLock& aProofOfLock) = 0;
68
69
  // Returns the number of events in the queue.
70
  virtual size_t Count(const MutexAutoLock& aProofOfLock) const = 0;
71
72
  virtual void EnableInputEventPrioritization(const MutexAutoLock& aProofOfLock) = 0;
73
  virtual void FlushInputEventPrioritization(const MutexAutoLock& aProofOfLock) = 0;
74
  virtual void SuspendInputEventPrioritization(const MutexAutoLock& aProofOfLock) = 0;
75
  virtual void ResumeInputEventPrioritization(const MutexAutoLock& aProofOfLock) = 0;
76
77
  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
78
0
  {
79
0
    return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
80
0
  }
81
82
  virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0;
83
84
0
  virtual ~AbstractEventQueue() {}
85
};
86
87
} // namespace mozilla
88
89
#endif // mozilla_AbstractEventQueue_h