Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/CondVar.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_CondVar_h
8
#define mozilla_CondVar_h
9
10
#include "mozilla/BlockingResourceBase.h"
11
#include "mozilla/PlatformConditionVariable.h"
12
#include "mozilla/Mutex.h"
13
14
#ifdef MOZILLA_INTERNAL_API
15
#include "GeckoProfiler.h"
16
#endif //MOZILLA_INTERNAL_API
17
18
namespace mozilla {
19
20
/**
21
 * Similarly to OffTheBooksMutex, OffTheBooksCondvar is identical to CondVar,
22
 * except that OffTheBooksCondVar doesn't include leak checking.  Sometimes
23
 * you want to intentionally "leak" a CondVar until shutdown; in these cases,
24
 * OffTheBooksCondVar is for you.
25
 */
26
class OffTheBooksCondVar : BlockingResourceBase
27
{
28
public:
29
  /**
30
   * OffTheBooksCondVar
31
   *
32
   * The CALLER owns |aLock|.
33
   *
34
   * @param aLock A Mutex to associate with this condition variable.
35
   * @param aName A name which can reference this monitor
36
   * @returns If failure, nullptr.
37
   *          If success, a valid Monitor* which must be destroyed
38
   *          by Monitor::DestroyMonitor()
39
   **/
40
  OffTheBooksCondVar(OffTheBooksMutex& aLock, const char* aName)
41
    : BlockingResourceBase(aName, eCondVar)
42
    , mLock(&aLock)
43
81
  {
44
81
  }
45
46
  /**
47
   * ~OffTheBooksCondVar
48
   * Clean up after this OffTheBooksCondVar, but NOT its associated Mutex.
49
   **/
50
  ~OffTheBooksCondVar()
51
0
  {
52
0
  }
53
54
  /**
55
   * Wait
56
   * @see prcvar.h
57
   **/
58
#ifndef DEBUG
59
  void Wait()
60
17
  {
61
17
#ifdef MOZILLA_INTERNAL_API
62
17
    AUTO_PROFILER_THREAD_SLEEP;
63
17
#endif //MOZILLA_INTERNAL_API
64
17
    mImpl.wait(*mLock);
65
17
  }
66
67
  CVStatus Wait(TimeDuration aDuration)
68
180
  {
69
180
#ifdef MOZILLA_INTERNAL_API
70
180
    AUTO_PROFILER_THREAD_SLEEP;
71
180
#endif //MOZILLA_INTERNAL_API
72
180
    return mImpl.wait_for(*mLock, aDuration);
73
180
  }
74
#else
75
  // NOTE: debug impl is in BlockingResourceBase.cpp
76
  void Wait();
77
  CVStatus Wait(TimeDuration aDuration);
78
#endif
79
80
  /**
81
   * Notify
82
   * @see prcvar.h
83
   **/
84
  nsresult Notify()
85
284
  {
86
284
    mImpl.notify_one();
87
284
    return NS_OK;
88
284
  }
89
90
  /**
91
   * NotifyAll
92
   * @see prcvar.h
93
   **/
94
  nsresult NotifyAll()
95
3
  {
96
3
    mImpl.notify_all();
97
3
    return NS_OK;
98
3
  }
99
100
#ifdef DEBUG
101
  /**
102
   * AssertCurrentThreadOwnsMutex
103
   * @see Mutex::AssertCurrentThreadOwns
104
   **/
105
  void AssertCurrentThreadOwnsMutex()
106
  {
107
    mLock->AssertCurrentThreadOwns();
108
  }
109
110
  /**
111
   * AssertNotCurrentThreadOwnsMutex
112
   * @see Mutex::AssertNotCurrentThreadOwns
113
   **/
114
  void AssertNotCurrentThreadOwnsMutex()
115
  {
116
    mLock->AssertNotCurrentThreadOwns();
117
  }
118
119
#else
120
0
  void AssertCurrentThreadOwnsMutex() {}
121
0
  void AssertNotCurrentThreadOwnsMutex() {}
122
123
#endif  // ifdef DEBUG
124
125
private:
126
  OffTheBooksCondVar();
127
  OffTheBooksCondVar(const OffTheBooksCondVar&) = delete;
128
  OffTheBooksCondVar& operator=(const OffTheBooksCondVar&) = delete;
129
130
  OffTheBooksMutex* mLock;
131
  detail::ConditionVariableImpl mImpl;
132
};
133
134
/**
135
 * CondVar
136
 * Vanilla condition variable.  Please don't use this unless you have a
137
 * compelling reason --- Monitor provides a simpler API.
138
 */
139
class CondVar : public OffTheBooksCondVar
140
{
141
public:
142
  CondVar(OffTheBooksMutex& aLock, const char* aName)
143
    : OffTheBooksCondVar(aLock, aName)
144
81
  {
145
81
    MOZ_COUNT_CTOR(CondVar);
146
81
  }
147
148
  ~CondVar()
149
0
  {
150
0
    MOZ_COUNT_DTOR(CondVar);
151
0
  }
152
153
private:
154
  CondVar();
155
  CondVar(const CondVar&);
156
  CondVar& operator=(const CondVar&);
157
};
158
159
} // namespace mozilla
160
161
162
#endif  // ifndef mozilla_CondVar_h