nsWeakReference.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsWeakReference_h__
  6. #define nsWeakReference_h__
  7. // nsWeakReference.h
  8. // See mfbt/WeakPtr.h for a more typesafe C++ implementation of weak references
  9. #include "nsIWeakReferenceUtils.h"
  10. class nsWeakReference;
  11. class nsSupportsWeakReference : public nsISupportsWeakReference
  12. {
  13. public:
  14. nsSupportsWeakReference() : mProxy(0) {}
  15. NS_DECL_NSISUPPORTSWEAKREFERENCE
  16. protected:
  17. inline ~nsSupportsWeakReference();
  18. private:
  19. friend class nsWeakReference;
  20. // Called (only) by an |nsWeakReference| from _its_ dtor.
  21. // The thread safety check is made by the caller.
  22. void NoticeProxyDestruction() { mProxy = nullptr; }
  23. nsWeakReference* MOZ_NON_OWNING_REF mProxy;
  24. protected:
  25. void ClearWeakReferences();
  26. bool HasWeakReferences() const { return !!mProxy; }
  27. };
  28. inline
  29. nsSupportsWeakReference::~nsSupportsWeakReference()
  30. {
  31. ClearWeakReferences();
  32. }
  33. #endif