Bug 1190496 - Do shutdown on xpcom-shutdown-threads. r=cpearce

This happens after xpcom-shutdown, and is the notification we're supposed to
listen for to shutdown off-main-thread event queues.
This commit is contained in:
Bobby Holley 2015-08-03 14:27:12 -07:00
Родитель ba39c86b4e
Коммит 99f6b1c31c
2 изменённых файлов: 28 добавлений и 9 удалений

Просмотреть файл

@ -8,7 +8,6 @@
#include "nsContentUtils.h"
#include "mozilla/StaticPtr.h"
#include "MediaDecoder.h"
#include "mozilla/SharedThreadPool.h"
#include "mozilla/Logging.h"
namespace mozilla {
@ -120,11 +119,6 @@ MediaShutdownManager::Shutdown()
iter.Remove();
}
// Ensure all media shared thread pools are shutdown. This joins with all
// threads in the state machine thread pool, the decoder thread pool, and
// any others.
SharedThreadPool::SpinUntilEmpty();
// Remove the MediaShutdownManager instance from the shutdown observer
// list.
nsContentUtils::UnregisterShutdownObserver(this);

Просмотреть файл

@ -5,13 +5,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/SharedThreadPool.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Monitor.h"
#include "mozilla/ReentrantMonitor.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
#include "nsDataHashtable.h"
#include "nsXPCOMCIDInternal.h"
#include "nsComponentManagerUtils.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#ifdef XP_WIN
#include "ThreadPoolCOMListener.h"
#endif
@ -28,6 +30,28 @@ static StaticAutoPtr<nsDataHashtable<nsCStringHashKey, SharedThreadPool*>> sPool
static already_AddRefed<nsIThreadPool>
CreateThreadPool(const nsCString& aName);
class SharedThreadPoolShutdownObserver : public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
protected:
virtual ~SharedThreadPoolShutdownObserver() {}
};
NS_IMPL_ISUPPORTS(SharedThreadPoolShutdownObserver, nsIObserver, nsISupports)
NS_IMETHODIMP
SharedThreadPoolShutdownObserver::Observe(nsISupports* aSubject, const char *aTopic,
const char16_t *aData)
{
MOZ_RELEASE_ASSERT(!strcmp(aTopic, "xpcom-shutdown-threads"));
SharedThreadPool::SpinUntilEmpty();
sMonitor = nullptr;
sPools = nullptr;
return NS_OK;
}
void
SharedThreadPool::InitStatics()
{
@ -35,8 +59,9 @@ SharedThreadPool::InitStatics()
MOZ_ASSERT(!sMonitor && !sPools);
sMonitor = new ReentrantMonitor("SharedThreadPool");
sPools = new nsDataHashtable<nsCStringHashKey, SharedThreadPool*>();
ClearOnShutdown(&sMonitor);
ClearOnShutdown(&sPools);
nsCOMPtr<nsIObserverService> obsService = mozilla::services::GetObserverService();
nsCOMPtr<nsIObserver> obs = new SharedThreadPoolShutdownObserver();
obsService->AddObserver(obs, "xpcom-shutdown-threads", false);
}
/* static */