#512: M1472018 M1469309 M1472925 M1470260 (part 1)

This commit is contained in:
Cameron Kaiser 2018-07-18 19:39:47 -07:00
parent 30dbc914e8
commit f9fe116fa9
9 changed files with 39 additions and 18 deletions

View File

@ -64,6 +64,10 @@ WebCryptoThreadPool::DispatchInternal(nsIRunnable* aRunnable)
{ {
MutexAutoLock lock(mMutex); MutexAutoLock lock(mMutex);
if (mShutdown) {
return NS_ERROR_FAILURE;
}
if (!mPool) { if (!mPool) {
nsCOMPtr<nsIThreadPool> pool(do_CreateInstance(NS_THREADPOOL_CONTRACTID)); nsCOMPtr<nsIThreadPool> pool(do_CreateInstance(NS_THREADPOOL_CONTRACTID));
NS_ENSURE_TRUE(pool, NS_ERROR_FAILURE); NS_ENSURE_TRUE(pool, NS_ERROR_FAILURE);
@ -81,10 +85,21 @@ void
WebCryptoThreadPool::Shutdown() WebCryptoThreadPool::Shutdown()
{ {
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
MutexAutoLock lock(mMutex);
if (mPool) { // Limit the scope of locking to avoid deadlocking if DispatchInternal ends
mPool->Shutdown(); // up getting called during shutdown event processing.
nsCOMPtr<nsIThreadPool> pool;
{
MutexAutoLock lock(mMutex);
if (mShutdown) {
return;
}
pool = mPool;
mShutdown = true;
}
if (pool) {
pool->Shutdown();
} }
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService(); nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();

View File

@ -27,6 +27,7 @@ private:
WebCryptoThreadPool() WebCryptoThreadPool()
: mMutex("WebCryptoThreadPool::mMutex") : mMutex("WebCryptoThreadPool::mMutex")
, mPool(nullptr) , mPool(nullptr)
, mShutdown(false)
{ } { }
virtual ~WebCryptoThreadPool() virtual ~WebCryptoThreadPool()
{ } { }
@ -46,6 +47,7 @@ private:
mozilla::Mutex mMutex; mozilla::Mutex mMutex;
nsCOMPtr<nsIThreadPool> mPool; nsCOMPtr<nsIThreadPool> mPool;
bool mShutdown;
}; };
} // namespace dom } // namespace dom

View File

@ -173,7 +173,7 @@ public:
STREAM_LOG(LogLevel::Debug, ("Starting system thread")); STREAM_LOG(LogLevel::Debug, ("Starting system thread"));
profiler_register_thread("MediaStreamGraph", &aLocal); profiler_register_thread("MediaStreamGraph", &aLocal);
LIFECYCLE_LOG("Starting a new system driver for graph %p\n", LIFECYCLE_LOG("Starting a new system driver for graph %p\n",
mDriver->mGraphImpl); mDriver->mGraphImpl.get());
if (mDriver->mPreviousDriver) { if (mDriver->mPreviousDriver) {
LIFECYCLE_LOG("%p releasing an AudioCallbackDriver(%p), for graph %p\n", LIFECYCLE_LOG("%p releasing an AudioCallbackDriver(%p), for graph %p\n",
mDriver, mDriver,
@ -204,7 +204,7 @@ private:
void void
ThreadedDriver::Start() ThreadedDriver::Start()
{ {
LIFECYCLE_LOG("Starting thread for a SystemClockDriver %p\n", mGraphImpl); LIFECYCLE_LOG("Starting thread for a SystemClockDriver %p\n", mGraphImpl.get());
nsCOMPtr<nsIRunnable> event = new MediaStreamGraphInitThreadRunnable(this); nsCOMPtr<nsIRunnable> event = new MediaStreamGraphInitThreadRunnable(this);
// Note: mThread may be null during event->Run() if we pass to NewNamedThread! See AudioInitTask // Note: mThread may be null during event->Run() if we pass to NewNamedThread! See AudioInitTask
nsresult rv = NS_NewNamedThread("MediaStreamGrph", getter_AddRefs(mThread)); nsresult rv = NS_NewNamedThread("MediaStreamGrph", getter_AddRefs(mThread));
@ -599,7 +599,7 @@ AudioCallbackDriver::Destroy()
void void
AudioCallbackDriver::Resume() AudioCallbackDriver::Resume()
{ {
STREAM_LOG(LogLevel::Debug, ("Resuming audio threads for MediaStreamGraph %p", mGraphImpl)); STREAM_LOG(LogLevel::Debug, ("Resuming audio threads for MediaStreamGraph %p", mGraphImpl.get()));
if (cubeb_stream_start(mAudioStream) != CUBEB_OK) { if (cubeb_stream_start(mAudioStream) != CUBEB_OK) {
NS_WARNING("Could not start cubeb stream for MSG."); NS_WARNING("Could not start cubeb stream for MSG.");
} }
@ -611,12 +611,12 @@ AudioCallbackDriver::Start()
// If this is running on the main thread, we can't open the stream directly, // If this is running on the main thread, we can't open the stream directly,
// because it is a blocking operation. // because it is a blocking operation.
if (NS_IsMainThread()) { if (NS_IsMainThread()) {
STREAM_LOG(LogLevel::Debug, ("Starting audio threads for MediaStreamGraph %p from a new thread.", mGraphImpl)); STREAM_LOG(LogLevel::Debug, ("Starting audio threads for MediaStreamGraph %p from a new thread.", mGraphImpl.get()));
RefPtr<AsyncCubebTask> initEvent = RefPtr<AsyncCubebTask> initEvent =
new AsyncCubebTask(this, AsyncCubebOperation::INIT); new AsyncCubebTask(this, AsyncCubebOperation::INIT);
initEvent->Dispatch(); initEvent->Dispatch();
} else { } else {
STREAM_LOG(LogLevel::Debug, ("Starting audio threads for MediaStreamGraph %p from the previous driver's thread", mGraphImpl)); STREAM_LOG(LogLevel::Debug, ("Starting audio threads for MediaStreamGraph %p from the previous driver's thread", mGraphImpl.get()));
Init(); Init();
// Check if we need to resolve promises because the driver just got switched // Check if we need to resolve promises because the driver just got switched
@ -669,7 +669,7 @@ AudioCallbackDriver::Revive()
mGraphImpl->SetCurrentDriver(mNextDriver); mGraphImpl->SetCurrentDriver(mNextDriver);
mNextDriver->Start(); mNextDriver->Start();
} else { } else {
STREAM_LOG(LogLevel::Debug, ("Starting audio threads for MediaStreamGraph %p from a new thread.", mGraphImpl)); STREAM_LOG(LogLevel::Debug, ("Starting audio threads for MediaStreamGraph %p from a new thread.", mGraphImpl.get()));
RefPtr<AsyncCubebTask> initEvent = RefPtr<AsyncCubebTask> initEvent =
new AsyncCubebTask(this, AsyncCubebOperation::INIT); new AsyncCubebTask(this, AsyncCubebOperation::INIT);
initEvent->Dispatch(); initEvent->Dispatch();

View File

@ -183,9 +183,8 @@ protected:
GraphTime mIterationStart; GraphTime mIterationStart;
// Time of the end of this graph iteration. // Time of the end of this graph iteration.
GraphTime mIterationEnd; GraphTime mIterationEnd;
// The MediaStreamGraphImpl that owns this driver. This has a lifetime longer // The MediaStreamGraphImpl associated with this driver.
// than the driver, and will never be null. const RefPtr<MediaStreamGraphImpl> mGraphImpl;
MediaStreamGraphImpl* mGraphImpl;
// This enum specifies the wait state of the driver. // This enum specifies the wait state of the driver.
enum WaitState { enum WaitState {

View File

@ -2687,7 +2687,8 @@ MediaStreamGraphImpl::Destroy()
// First unregister from memory reporting. // First unregister from memory reporting.
UnregisterWeakMemoryReporter(this); UnregisterWeakMemoryReporter(this);
// Clear the self reference which will destroy this instance. // Clear the self reference which will destroy this instance if all
// associated GraphDrivers are destroyed.
mSelfRef = nullptr; mSelfRef = nullptr;
} }

View File

@ -566,6 +566,7 @@ UnregisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
AssertMainThread(); AssertMainThread();
if (!gSensorObservers) { if (!gSensorObservers) {
HAL_ERR("Un-registering a sensor when none have been registered");
return; return;
} }

View File

@ -18,7 +18,6 @@ namespace hal {
* If you add or change any here, do the same in GeckoHalDefines.java. * If you add or change any here, do the same in GeckoHalDefines.java.
*/ */
enum SensorType { enum SensorType {
SENSOR_UNKNOWN = -1,
SENSOR_ORIENTATION = 0, SENSOR_ORIENTATION = 0,
SENSOR_ACCELERATION = 1, SENSOR_ACCELERATION = 1,
SENSOR_PROXIMITY = 2, SENSOR_PROXIMITY = 2,
@ -63,7 +62,7 @@ namespace IPC {
struct ParamTraits<mozilla::hal::SensorType>: struct ParamTraits<mozilla::hal::SensorType>:
public ContiguousEnumSerializer< public ContiguousEnumSerializer<
mozilla::hal::SensorType, mozilla::hal::SensorType,
mozilla::hal::SENSOR_UNKNOWN, mozilla::hal::SENSOR_ORIENTATION,
mozilla::hal::NUM_SENSOR_TYPE> { mozilla::hal::NUM_SENSOR_TYPE> {
}; };

View File

@ -16,6 +16,7 @@
#include "mozilla/dom/battery/Types.h" #include "mozilla/dom/battery/Types.h"
#include "mozilla/dom/network/Types.h" #include "mozilla/dom/network/Types.h"
#include "mozilla/dom/ScreenOrientation.h" #include "mozilla/dom/ScreenOrientation.h"
#include "mozilla/EnumeratedRange.h"
#include "mozilla/Observer.h" #include "mozilla/Observer.h"
#include "mozilla/unused.h" #include "mozilla/unused.h"
#include "WindowIdentifier.h" #include "WindowIdentifier.h"
@ -485,9 +486,8 @@ public:
hal::UnregisterBatteryObserver(this); hal::UnregisterBatteryObserver(this);
hal::UnregisterNetworkObserver(this); hal::UnregisterNetworkObserver(this);
hal::UnregisterScreenConfigurationObserver(this); hal::UnregisterScreenConfigurationObserver(this);
for (int32_t sensor = SENSOR_UNKNOWN + 1; for (auto sensor : MakeEnumeratedRange(NUM_SENSOR_TYPE)) {
sensor < NUM_SENSOR_TYPE; ++sensor) { hal::UnregisterSensorObserver(sensor, this);
hal::UnregisterSensorObserver(SensorType(sensor), this);
} }
hal::UnregisterWakeLockObserver(this); hal::UnregisterWakeLockObserver(this);
hal::UnregisterSystemClockChangeObserver(this); hal::UnregisterSystemClockChangeObserver(this);

View File

@ -392,6 +392,9 @@ private:
virtual bool NotifyVsync(TimeStamp aVsyncTimestamp) override virtual bool NotifyVsync(TimeStamp aVsyncTimestamp) override
{ {
// IMPORTANT: All paths through this method MUST hold a strong ref on
// |this| for the duration of the TickRefreshDriver callback.
if (!NS_IsMainThread()) { if (!NS_IsMainThread()) {
MOZ_ASSERT(XRE_IsParentProcess()); MOZ_ASSERT(XRE_IsParentProcess());
// Compress vsync notifications such that only 1 may run at a time // Compress vsync notifications such that only 1 may run at a time
@ -412,6 +415,7 @@ private:
aVsyncTimestamp); aVsyncTimestamp);
NS_DispatchToMainThread(vsyncEvent); NS_DispatchToMainThread(vsyncEvent);
} else { } else {
RefPtr<RefreshDriverVsyncObserver> kungFuDeathGrip(this);
TickRefreshDriver(aVsyncTimestamp); TickRefreshDriver(aVsyncTimestamp);
} }