FileHandleCommon.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  3. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef mozilla_dom_FileHandleCommon_h
  5. #define mozilla_dom_FileHandleCommon_h
  6. #include "nscore.h"
  7. #ifdef DEBUG
  8. #define DEBUGONLY(...) __VA_ARGS__
  9. #else
  10. #define DEBUGONLY(...) /* nothing */
  11. #endif
  12. struct PRThread;
  13. namespace mozilla {
  14. namespace dom {
  15. class RefCountedObject
  16. {
  17. public:
  18. NS_IMETHOD_(MozExternalRefCountType)
  19. AddRef() = 0;
  20. NS_IMETHOD_(MozExternalRefCountType)
  21. Release() = 0;
  22. protected:
  23. virtual ~RefCountedObject()
  24. { }
  25. };
  26. class ThreadObject
  27. {
  28. DEBUGONLY(PRThread* mOwningThread;)
  29. public:
  30. explicit ThreadObject(DEBUGONLY(PRThread* aOwningThread))
  31. DEBUGONLY(: mOwningThread(aOwningThread))
  32. { }
  33. virtual ~ThreadObject()
  34. { }
  35. #ifdef DEBUG
  36. void
  37. AssertIsOnOwningThread() const;
  38. PRThread*
  39. OwningThread() const;
  40. #else
  41. void
  42. AssertIsOnOwningThread() const
  43. { }
  44. #endif
  45. };
  46. class RefCountedThreadObject
  47. : public RefCountedObject
  48. , public ThreadObject
  49. {
  50. public:
  51. explicit RefCountedThreadObject(DEBUGONLY(PRThread* aOwningThread))
  52. : ThreadObject(DEBUGONLY(aOwningThread))
  53. { }
  54. };
  55. } // namespace dom
  56. } // namespace mozilla
  57. #endif // mozilla_dom_FileHandleCommon_h