michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _nsCacheUtils_h_ michael@0: #define _nsCacheUtils_h_ michael@0: michael@0: #include "nsThreadUtils.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "mozilla/Mutex.h" michael@0: #include "mozilla/CondVar.h" michael@0: michael@0: class nsIThread; michael@0: michael@0: /** michael@0: * A class with utility methods for shutting down nsIThreads easily. michael@0: */ michael@0: class nsShutdownThread : public nsRunnable { michael@0: public: michael@0: nsShutdownThread(nsIThread *aThread); michael@0: ~nsShutdownThread(); michael@0: michael@0: NS_IMETHOD Run(); michael@0: michael@0: /** michael@0: * Shutdown ensures that aThread->Shutdown() is called on a main thread michael@0: */ michael@0: static nsresult Shutdown(nsIThread *aThread); michael@0: michael@0: /** michael@0: * BlockingShutdown ensures that by the time it returns, aThread->Shutdown() has michael@0: * been called and no pending events have been processed on the current thread. michael@0: */ michael@0: static nsresult BlockingShutdown(nsIThread *aThread); michael@0: michael@0: private: michael@0: mozilla::Mutex mLock; michael@0: mozilla::CondVar mCondVar; michael@0: nsCOMPtr mThread; michael@0: }; michael@0: michael@0: #endif