ShutdownTracker.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* -*- Mode: C++; tab-width: 2; 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. /**
  6. * ShutdownTracker is an imagelib-global service that allows callers to check
  7. * whether shutdown has started.
  8. */
  9. #ifndef mozilla_image_ShutdownTracker_h
  10. #define mozilla_image_ShutdownTracker_h
  11. namespace mozilla {
  12. namespace image {
  13. /**
  14. * ShutdownTracker is an imagelib-global service that allows callers to check
  15. * whether shutdown has started. It exists to avoid the need for registering
  16. * many 'xpcom-will-shutdown' notification observers on short-lived objects,
  17. * which would have an unnecessary performance cost.
  18. */
  19. struct ShutdownTracker
  20. {
  21. /**
  22. * Initialize static data. Called during imagelib module initialization.
  23. */
  24. static void Initialize();
  25. /**
  26. * Check whether shutdown has started. Callers can use this to check whether
  27. * it's safe to access XPCOM services; if shutdown has started, such calls
  28. * must be avoided.
  29. *
  30. * @return true if shutdown has already started.
  31. */
  32. static bool ShutdownHasStarted();
  33. private:
  34. virtual ~ShutdownTracker() = 0; // Forbid instantiation.
  35. };
  36. } // namespace image
  37. } // namespace mozilla
  38. #endif // mozilla_image_ShutdownTracker_h