зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1207696 Part 4a - Make recording optional in mozilla::RefCounted, r=ehsan.
--HG-- extra : rebase_source : 4bf53b557247ac82933f4da70cccddafa6c2c7b2
This commit is contained in:
Родитель
be2b98186b
Коммит
19be0573fa
|
@ -91,7 +91,7 @@ enum RefCountAtomicity
|
|||
NonAtomicRefCount
|
||||
};
|
||||
|
||||
template<typename T, RefCountAtomicity Atomicity>
|
||||
template<typename T, RefCountAtomicity Atomicity, recordreplay::Behavior Recording>
|
||||
class RC
|
||||
{
|
||||
public:
|
||||
|
@ -108,11 +108,11 @@ private:
|
|||
T mValue;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class RC<T, AtomicRefCount>
|
||||
template<typename T, recordreplay::Behavior Recording>
|
||||
class RC<T, AtomicRefCount, Recording>
|
||||
{
|
||||
public:
|
||||
explicit RC(T aCount) : mValue(aCount) {}
|
||||
explicit RC(T aCount) : mValue(aCount) { }
|
||||
|
||||
T operator++()
|
||||
{
|
||||
|
@ -124,6 +124,7 @@ public:
|
|||
// first increment on that thread. The necessary memory
|
||||
// synchronization is done by the mechanism that transfers the
|
||||
// pointer between threads.
|
||||
AutoRecordAtomicAccess<Recording> record;
|
||||
return mValue.fetch_add(1, std::memory_order_relaxed) + 1;
|
||||
}
|
||||
|
||||
|
@ -133,6 +134,7 @@ public:
|
|||
// release semantics so that prior writes on this thread are visible
|
||||
// to the thread that destroys the object when it reads mValue with
|
||||
// acquire semantics.
|
||||
AutoRecordAtomicAccess<Recording> record;
|
||||
T result = mValue.fetch_sub(1, std::memory_order_release) - 1;
|
||||
if (result == 0) {
|
||||
// We're going to destroy the object on this thread, so we need
|
||||
|
@ -146,12 +148,16 @@ public:
|
|||
|
||||
// This method is only called in debug builds, so we're not too concerned
|
||||
// about its performance.
|
||||
void operator=(const T& aValue) { mValue.store(aValue, std::memory_order_seq_cst); }
|
||||
void operator=(const T& aValue) {
|
||||
AutoRecordAtomicAccess<Recording> record;
|
||||
mValue.store(aValue, std::memory_order_seq_cst);
|
||||
}
|
||||
|
||||
operator T() const
|
||||
{
|
||||
// Use acquire semantics since we're not sure what the caller is
|
||||
// doing.
|
||||
AutoRecordAtomicAccess<Recording> record;
|
||||
return mValue.load(std::memory_order_acquire);
|
||||
}
|
||||
|
||||
|
@ -159,7 +165,8 @@ private:
|
|||
std::atomic<T> mValue;
|
||||
};
|
||||
|
||||
template<typename T, RefCountAtomicity Atomicity>
|
||||
template<typename T, RefCountAtomicity Atomicity,
|
||||
recordreplay::Behavior Recording = recordreplay::Behavior::Preserve>
|
||||
class RefCounted
|
||||
{
|
||||
protected:
|
||||
|
@ -220,7 +227,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
mutable RC<MozRefCountType, Atomicity> mRefCnt;
|
||||
mutable RC<MozRefCountType, Atomicity, Recording> mRefCnt;
|
||||
};
|
||||
|
||||
#ifdef MOZ_REFCOUNTED_LEAK_CHECKING
|
||||
|
@ -262,9 +269,9 @@ namespace external {
|
|||
* NOTE: Please do not use this class, use NS_INLINE_DECL_THREADSAFE_REFCOUNTING
|
||||
* instead.
|
||||
*/
|
||||
template<typename T>
|
||||
template<typename T, recordreplay::Behavior Recording = recordreplay::Behavior::Preserve>
|
||||
class AtomicRefCounted :
|
||||
public mozilla::detail::RefCounted<T, mozilla::detail::AtomicRefCount>
|
||||
public mozilla::detail::RefCounted<T, mozilla::detail::AtomicRefCount, Recording>
|
||||
{
|
||||
public:
|
||||
~AtomicRefCounted()
|
||||
|
|
Загрузка…
Ссылка в новой задаче