зеркало из https://github.com/mozilla/gecko-dev.git
Bug 891177 - Add ReentrancyGuard.h as a helper class for asserting that use of a class is non-reentrant. r=terrence
--HG-- extra : rebase_source : 3751e523c0b0315697cb6e005dfd8ee625f6dd58
This commit is contained in:
Родитель
5ccfb193c6
Коммит
7a5c915ff2
|
@ -14,6 +14,7 @@
|
|||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/PodOperations.h"
|
||||
#include "mozilla/ReentrancyGuard.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
#include "mozilla/Util.h"
|
||||
|
||||
|
@ -879,7 +880,7 @@ class HashTable : private AllocPolicy
|
|||
# define METER(x)
|
||||
#endif
|
||||
|
||||
friend class js::ReentrancyGuard;
|
||||
friend class mozilla::ReentrancyGuard;
|
||||
mutable mozilla::DebugOnly<bool> entered;
|
||||
mozilla::DebugOnly<uint64_t> mutationCount;
|
||||
|
||||
|
@ -1355,7 +1356,7 @@ class HashTable : private AllocPolicy
|
|||
|
||||
Ptr lookup(const Lookup &l) const
|
||||
{
|
||||
ReentrancyGuard g(*this);
|
||||
mozilla::ReentrancyGuard g(*this);
|
||||
HashNumber keyHash = prepareHash(l);
|
||||
return Ptr(lookup(l, keyHash, 0));
|
||||
}
|
||||
|
@ -1368,7 +1369,7 @@ class HashTable : private AllocPolicy
|
|||
|
||||
AddPtr lookupForAdd(const Lookup &l) const
|
||||
{
|
||||
ReentrancyGuard g(*this);
|
||||
mozilla::ReentrancyGuard g(*this);
|
||||
HashNumber keyHash = prepareHash(l);
|
||||
Entry &entry = lookup(l, keyHash, sCollisionBit);
|
||||
AddPtr p(entry, keyHash);
|
||||
|
@ -1379,7 +1380,7 @@ class HashTable : private AllocPolicy
|
|||
template <class U>
|
||||
bool add(AddPtr &p, const U &rhs)
|
||||
{
|
||||
ReentrancyGuard g(*this);
|
||||
mozilla::ReentrancyGuard g(*this);
|
||||
JS_ASSERT(mutationCount == p.mutationCount);
|
||||
JS_ASSERT(table);
|
||||
JS_ASSERT(!p.found());
|
||||
|
@ -1440,7 +1441,7 @@ class HashTable : private AllocPolicy
|
|||
{
|
||||
p.mutationCount = mutationCount;
|
||||
{
|
||||
ReentrancyGuard g(*this);
|
||||
mozilla::ReentrancyGuard g(*this);
|
||||
p.entry_ = &lookup(l, p.keyHash, sCollisionBit);
|
||||
}
|
||||
return p.found() || add(p, u);
|
||||
|
@ -1449,7 +1450,7 @@ class HashTable : private AllocPolicy
|
|||
void remove(Ptr p)
|
||||
{
|
||||
JS_ASSERT(table);
|
||||
ReentrancyGuard g(*this);
|
||||
mozilla::ReentrancyGuard g(*this);
|
||||
JS_ASSERT(p.found());
|
||||
remove(*p.entry_);
|
||||
checkUnderloaded();
|
||||
|
@ -1458,7 +1459,7 @@ class HashTable : private AllocPolicy
|
|||
void rekey(Ptr p, const Lookup &l, const Key &k)
|
||||
{
|
||||
JS_ASSERT(table);
|
||||
ReentrancyGuard g(*this);
|
||||
mozilla::ReentrancyGuard g(*this);
|
||||
JS_ASSERT(p.found());
|
||||
typename HashTableEntry<T>::NonConstT t(mozilla::Move(*p));
|
||||
HashPolicy::setKey(t, const_cast<Key &>(k));
|
||||
|
|
|
@ -564,38 +564,6 @@ SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits)
|
|||
|
||||
namespace js {
|
||||
|
||||
/* Useful for implementing containers that assert non-reentrancy */
|
||||
class ReentrancyGuard
|
||||
{
|
||||
/* ReentrancyGuard is not copyable. */
|
||||
ReentrancyGuard(const ReentrancyGuard &);
|
||||
void operator=(const ReentrancyGuard &);
|
||||
|
||||
#ifdef DEBUG
|
||||
bool &entered;
|
||||
#endif
|
||||
public:
|
||||
template <class T>
|
||||
#ifdef DEBUG
|
||||
ReentrancyGuard(T &obj)
|
||||
: entered(obj.entered)
|
||||
#else
|
||||
ReentrancyGuard(T &/*obj*/)
|
||||
#endif
|
||||
{
|
||||
#ifdef DEBUG
|
||||
JS_ASSERT(!entered);
|
||||
entered = true;
|
||||
#endif
|
||||
}
|
||||
~ReentrancyGuard()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
entered = false;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
JS_ALWAYS_INLINE static void
|
||||
Swap(T &t, T &u)
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/ReentrancyGuard.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
|
||||
#include "js/TemplateLib.h"
|
||||
|
@ -261,7 +262,7 @@ class Vector : private AllocPolicy
|
|||
mozilla::AlignedStorage<sInlineBytes> storage;
|
||||
|
||||
#ifdef DEBUG
|
||||
friend class ReentrancyGuard;
|
||||
friend class mozilla::ReentrancyGuard;
|
||||
bool entered;
|
||||
#endif
|
||||
|
||||
|
@ -524,7 +525,7 @@ class Vector : private AllocPolicy
|
|||
|
||||
/* This does the re-entrancy check plus several other sanity checks. */
|
||||
#define REENTRANCY_GUARD_ET_AL \
|
||||
ReentrancyGuard g(*this); \
|
||||
mozilla::ReentrancyGuard g(*this); \
|
||||
MOZ_ASSERT_IF(usingInlineStorage(), mCapacity == sInlineCapacity); \
|
||||
MOZ_ASSERT(reserved() <= mCapacity); \
|
||||
MOZ_ASSERT(mLength <= reserved()); \
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/* Small helper class for asserting uses of a class are non-reentrant. */
|
||||
|
||||
#ifndef mozilla_ReentrancyGuard_h_
|
||||
#define mozilla_ReentrancyGuard_h_
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/GuardObjects.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
/* Useful for implementing containers that assert non-reentrancy */
|
||||
class ReentrancyGuard
|
||||
{
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
#ifdef DEBUG
|
||||
bool& entered;
|
||||
#endif
|
||||
|
||||
public:
|
||||
template<class T>
|
||||
#ifdef DEBUG
|
||||
ReentrancyGuard(T& obj
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: entered(obj.entered)
|
||||
#else
|
||||
ReentrancyGuard(T&
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
#endif
|
||||
{
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
#ifdef DEBUG
|
||||
MOZ_ASSERT(!entered);
|
||||
entered = true;
|
||||
#endif
|
||||
}
|
||||
~ReentrancyGuard()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
entered = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE;
|
||||
void operator=(const ReentrancyGuard&) MOZ_DELETE;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_ReentrancyGuard_h_
|
|
@ -38,6 +38,7 @@ EXPORTS_mozilla += \
|
|||
Poison.h \
|
||||
Range.h \
|
||||
RangedPtr.h \
|
||||
ReentrancyGuard.h \
|
||||
RefPtr.h \
|
||||
Scoped.h \
|
||||
SHA1.h \
|
||||
|
|
Загрузка…
Ссылка в новой задаче