From 240063823f824aa26627ae6fea361bfdfa623b22 Mon Sep 17 00:00:00 2001 From: "scc%netscape.com" Date: Tue, 21 Sep 1999 20:20:04 +0000 Subject: [PATCH] Made a protected method for severing weak references early git-svn-id: svn://10.0.0.236/trunk@48602 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/base/nsWeakReference.h | 27 ++++++++++++++++++++++++--- mozilla/xpcom/glue/nsWeakReference.h | 27 ++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/mozilla/xpcom/base/nsWeakReference.h b/mozilla/xpcom/base/nsWeakReference.h index 1664b84dcad..16632d4dc0c 100644 --- a/mozilla/xpcom/base/nsWeakReference.h +++ b/mozilla/xpcom/base/nsWeakReference.h @@ -51,6 +51,10 @@ class NS_COM nsSupportsWeakReference : public nsISupportsWeakReference } nsWeakReference* mProxy; + + protected: + + inline void ClearWeakReferences(); }; class NS_COM nsWeakReference : public nsIWeakReference @@ -93,10 +97,27 @@ class NS_COM nsWeakReference : public nsIWeakReference nsSupportsWeakReference* mReferent; }; -inline nsSupportsWeakReference::~nsSupportsWeakReference() +inline +void +nsSupportsWeakReference::ClearWeakReferences() + /* + Usually being called from |nsSupportsWeakReference::~nsSupportsWeakReference| + will be good enough, but you may have a case where you need to call disconnect + your weak references in an outer destructor (to prevent some client holding a + weak reference from re-entering your destructor). + */ + { + if ( mProxy ) + { + mProxy->NoticeReferentDestruction(); + mProxy = 0; + } + } + +inline +nsSupportsWeakReference::~nsSupportsWeakReference() { - if ( mProxy ) - mProxy->NoticeReferentDestruction(); + ClearWeakReferences(); } #endif diff --git a/mozilla/xpcom/glue/nsWeakReference.h b/mozilla/xpcom/glue/nsWeakReference.h index 1664b84dcad..16632d4dc0c 100644 --- a/mozilla/xpcom/glue/nsWeakReference.h +++ b/mozilla/xpcom/glue/nsWeakReference.h @@ -51,6 +51,10 @@ class NS_COM nsSupportsWeakReference : public nsISupportsWeakReference } nsWeakReference* mProxy; + + protected: + + inline void ClearWeakReferences(); }; class NS_COM nsWeakReference : public nsIWeakReference @@ -93,10 +97,27 @@ class NS_COM nsWeakReference : public nsIWeakReference nsSupportsWeakReference* mReferent; }; -inline nsSupportsWeakReference::~nsSupportsWeakReference() +inline +void +nsSupportsWeakReference::ClearWeakReferences() + /* + Usually being called from |nsSupportsWeakReference::~nsSupportsWeakReference| + will be good enough, but you may have a case where you need to call disconnect + your weak references in an outer destructor (to prevent some client holding a + weak reference from re-entering your destructor). + */ + { + if ( mProxy ) + { + mProxy->NoticeReferentDestruction(); + mProxy = 0; + } + } + +inline +nsSupportsWeakReference::~nsSupportsWeakReference() { - if ( mProxy ) - mProxy->NoticeReferentDestruction(); + ClearWeakReferences(); } #endif