michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* Small helper class for asserting uses of a class are non-reentrant. */ michael@0: michael@0: #ifndef mozilla_ReentrancyGuard_h michael@0: #define mozilla_ReentrancyGuard_h michael@0: michael@0: #include "mozilla/Assertions.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/GuardObjects.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: /* Useful for implementing containers that assert non-reentrancy */ michael@0: class ReentrancyGuard michael@0: { michael@0: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER michael@0: #ifdef DEBUG michael@0: bool& entered; michael@0: #endif michael@0: michael@0: public: michael@0: template michael@0: #ifdef DEBUG michael@0: ReentrancyGuard(T& obj michael@0: MOZ_GUARD_OBJECT_NOTIFIER_PARAM) michael@0: : entered(obj.entered) michael@0: #else michael@0: ReentrancyGuard(T& michael@0: MOZ_GUARD_OBJECT_NOTIFIER_PARAM) michael@0: #endif michael@0: { michael@0: MOZ_GUARD_OBJECT_NOTIFIER_INIT; michael@0: #ifdef DEBUG michael@0: MOZ_ASSERT(!entered); michael@0: entered = true; michael@0: #endif michael@0: } michael@0: ~ReentrancyGuard() michael@0: { michael@0: #ifdef DEBUG michael@0: entered = false; michael@0: #endif michael@0: } michael@0: michael@0: private: michael@0: ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE; michael@0: void operator=(const ReentrancyGuard&) MOZ_DELETE; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif /* mozilla_ReentrancyGuard_h */