#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);
if (mShutdown) {
return NS_ERROR_FAILURE;
}
if (!mPool) {
nsCOMPtr<nsIThreadPool> pool(do_CreateInstance(NS_THREADPOOL_CONTRACTID));
NS_ENSURE_TRUE(pool, NS_ERROR_FAILURE);
@ -81,10 +85,21 @@ void
WebCryptoThreadPool::Shutdown()
{
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
MutexAutoLock lock(mMutex);
if (mPool) {
mPool->Shutdown();
// Limit the scope of locking to avoid deadlocking if DispatchInternal ends
// 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();

View File

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

View File

@ -173,7 +173,7 @@ public:
STREAM_LOG(LogLevel::Debug, ("Starting system thread"));
profiler_register_thread("MediaStreamGraph", &aLocal);
LIFECYCLE_LOG("Starting a new system driver for graph %p\n",
mDriver->mGraphImpl);
mDriver->mGraphImpl.get());
if (mDriver->mPreviousDriver) {
LIFECYCLE_LOG("%p releasing an AudioCallbackDriver(%p), for graph %p\n",
mDriver,
@ -204,7 +204,7 @@ private:
void
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);
// Note: mThread may be null during event->Run() if we pass to NewNamedThread! See AudioInitTask
nsresult rv = NS_NewNamedThread("MediaStreamGrph", getter_AddRefs(mThread));
@ -599,7 +599,7 @@ AudioCallbackDriver::Destroy()
void
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) {
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,
// because it is a blocking operation.
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 =
new AsyncCubebTask(this, AsyncCubebOperation::INIT);
initEvent->Dispatch();
} 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();
// Check if we need to resolve promises because the driver just got switched
@ -669,7 +669,7 @@ AudioCallbackDriver::Revive()
mGraphImpl->SetCurrentDriver(mNextDriver);
mNextDriver->Start();
} 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 =
new AsyncCubebTask(this, AsyncCubebOperation::INIT);
initEvent->Dispatch();

View File

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

View File

@ -2687,7 +2687,8 @@ MediaStreamGraphImpl::Destroy()
// First unregister from memory reporting.
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;
}

View File

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

View File

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

View File

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

View File

@ -392,6 +392,9 @@ private:
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()) {
MOZ_ASSERT(XRE_IsParentProcess());
// Compress vsync notifications such that only 1 may run at a time
@ -412,6 +415,7 @@ private:
aVsyncTimestamp);
NS_DispatchToMainThread(vsyncEvent);
} else {
RefPtr<RefreshDriverVsyncObserver> kungFuDeathGrip(this);
TickRefreshDriver(aVsyncTimestamp);
}