Backed out 2 changesets (bug 1853057) for causing mda failures on test_video_low_powe...
[gecko.git] / xpcom / base / nsWeakReference.h
blob5303f2d2eafd7777b2cdae44ad0a748fde64874c
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 #ifndef nsWeakReference_h__
8 #define nsWeakReference_h__
10 // nsWeakReference.h
12 // See mfbt/WeakPtr.h for a more typesafe C++ implementation of weak references
14 #include "nsIWeakReferenceUtils.h"
16 class nsWeakReference;
18 class nsSupportsWeakReference : public nsISupportsWeakReference {
19 public:
20 nsSupportsWeakReference() : mProxy(0) {}
22 NS_DECL_NSISUPPORTSWEAKREFERENCE
24 protected:
25 inline ~nsSupportsWeakReference();
27 private:
28 friend class nsWeakReference;
30 // Called (only) by an |nsWeakReference| from _its_ dtor.
31 // The thread safety check is made by the caller.
32 void NoticeProxyDestruction() { mProxy = nullptr; }
34 nsWeakReference* MOZ_NON_OWNING_REF mProxy;
36 protected:
37 void ClearWeakReferences();
38 bool HasWeakReferences() const { return !!mProxy; }
41 inline nsSupportsWeakReference::~nsSupportsWeakReference() {
42 ClearWeakReferences();
45 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_REFERENCE \
46 tmp->ClearWeakReferences();
48 #define NS_IMPL_CYCLE_COLLECTION_WEAK(class_, ...) \
49 NS_IMPL_CYCLE_COLLECTION_CLASS(class_) \
50 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(class_) \
51 NS_IMPL_CYCLE_COLLECTION_UNLINK(__VA_ARGS__) \
52 NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_REFERENCE \
53 NS_IMPL_CYCLE_COLLECTION_UNLINK_END \
54 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(class_) \
55 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(__VA_ARGS__) \
56 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
58 #define NS_IMPL_CYCLE_COLLECTION_WEAK_INHERITED(class_, super_, ...) \
59 NS_IMPL_CYCLE_COLLECTION_CLASS(class_) \
60 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(class_, super_) \
61 NS_IMPL_CYCLE_COLLECTION_UNLINK(__VA_ARGS__) \
62 NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_REFERENCE \
63 NS_IMPL_CYCLE_COLLECTION_UNLINK_END \
64 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(class_, super_) \
65 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(__VA_ARGS__) \
66 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
68 #endif