Bumping manifests a=b2g-bump
[gecko.git] / mfbt / ReentrancyGuard.h
blob557c61015eb536384ec90df642095932c2eb54f2
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 /* Small helper class for asserting uses of a class are non-reentrant. */
9 #ifndef mozilla_ReentrancyGuard_h
10 #define mozilla_ReentrancyGuard_h
12 #include "mozilla/Assertions.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/GuardObjects.h"
16 namespace mozilla {
18 /* Useful for implementing containers that assert non-reentrancy */
19 class ReentrancyGuard
21 MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
22 #ifdef DEBUG
23 bool& mEntered;
24 #endif
26 public:
27 template<class T>
28 #ifdef DEBUG
29 ReentrancyGuard(T& aObj
30 MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
31 : mEntered(aObj.mEntered)
32 #else
33 ReentrancyGuard(T&
34 MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
35 #endif
37 MOZ_GUARD_OBJECT_NOTIFIER_INIT;
38 #ifdef DEBUG
39 MOZ_ASSERT(!mEntered);
40 mEntered = true;
41 #endif
43 ~ReentrancyGuard()
45 #ifdef DEBUG
46 mEntered = false;
47 #endif
50 private:
51 ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE;
52 void operator=(const ReentrancyGuard&) MOZ_DELETE;
55 } // namespace mozilla
57 #endif /* mozilla_ReentrancyGuard_h */