nsCacheUtils.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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 _nsCacheUtils_h_
  6. #define _nsCacheUtils_h_
  7. #include "nsThreadUtils.h"
  8. #include "nsCOMPtr.h"
  9. #include "mozilla/Monitor.h"
  10. class nsIThread;
  11. /**
  12. * A class with utility methods for shutting down nsIThreads easily.
  13. */
  14. class nsShutdownThread : public mozilla::Runnable {
  15. public:
  16. explicit nsShutdownThread(nsIThread *aThread);
  17. ~nsShutdownThread();
  18. NS_IMETHOD Run();
  19. /**
  20. * Shutdown ensures that aThread->Shutdown() is called on a main thread
  21. */
  22. static nsresult Shutdown(nsIThread *aThread);
  23. /**
  24. * BlockingShutdown ensures that by the time it returns, aThread->Shutdown() has
  25. * been called and no pending events have been processed on the current thread.
  26. */
  27. static nsresult BlockingShutdown(nsIThread *aThread);
  28. private:
  29. mozilla::Monitor mMonitor;
  30. bool mShuttingDown;
  31. nsCOMPtr<nsIThread> mThread;
  32. };
  33. #endif