Bug 1151656 - Do static initialization explicitly. r=mattwoodrow

This commit is contained in:
Bobby Holley 2015-04-07 10:59:44 -07:00
parent 431df99c02
commit b5df0b86c9
5 changed files with 22 additions and 13 deletions

View File

@ -38,16 +38,15 @@ AbstractThread::MainThread()
}
void
AbstractThread::EnsureMainThreadSingleton()
AbstractThread::InitStatics()
{
MOZ_ASSERT(NS_IsMainThread());
if (!sMainThread) {
MOZ_ASSERT(!sMainThread);
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));
MOZ_DIAGNOSTIC_ASSERT(mainThread);
sMainThread = AbstractThread::Create(mainThread.get());
ClearOnShutdown(&sMainThread);
}
}
} // namespace mozilla

View File

@ -38,11 +38,10 @@ public:
template<typename TargetType> static AbstractThread* Create(TargetType* aTarget);
// Convenience method for getting an AbstractThread for the main thread.
//
// EnsureMainThreadSingleton must be called on the main thread before any
// other threads that might use MainThread() are spawned.
static AbstractThread* MainThread();
static void EnsureMainThreadSingleton();
// Must be called exactly once during startup.
static void InitStatics();
protected:
virtual ~AbstractThread() {}

View File

@ -117,6 +117,12 @@ public:
StaticRefPtr<MediaMemoryTracker> MediaMemoryTracker::sUniqueInstance;
void
MediaDecoder::InitStatics()
{
AbstractThread::InitStatics();
}
NS_IMPL_ISUPPORTS(MediaMemoryTracker, nsIMemoryReporter)
NS_IMPL_ISUPPORTS(MediaDecoder, nsIObserver)
@ -612,7 +618,6 @@ MediaDecoder::MediaDecoder() :
MOZ_COUNT_CTOR(MediaDecoder);
MOZ_ASSERT(NS_IsMainThread());
MediaMemoryTracker::AddMediaDecoder(this);
AbstractThread::EnsureMainThreadSingleton();
#ifdef PR_LOGGING
if (!gMediaDecoderLog) {
gMediaDecoderLog = PR_NewLogModule("MediaDecoder");

View File

@ -298,6 +298,9 @@ public:
PLAY_STATE_SHUTDOWN
};
// Must be called exactly once, on the main thread, during startup.
static void InitStatics();
MediaDecoder();
// Reset the decoder and notify the media element that

View File

@ -137,6 +137,7 @@ using namespace mozilla::system;
#include "mozilla/dom/HTMLVideoElement.h"
#include "CameraPreferences.h"
#include "TouchManager.h"
#include "MediaDecoder.h"
using namespace mozilla;
using namespace mozilla::net;
@ -314,6 +315,8 @@ nsLayoutStatics::Initialize()
mozilla::css::CommonAnimationManager::Initialize();
#endif
MediaDecoder::InitStatics();
return NS_OK;
}