mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1839235 - Protect VideoBridgeChild's singleton with a StaticMutex r=lsalzman
Protect sVideoBridge like ImageBridgeChild::GetSingleton() to avoid race condition. Differential Revision: https://phabricator.services.mozilla.com/D181844
This commit is contained in:
parent
6a6ef2a134
commit
c5cba984e2
@ -9,12 +9,15 @@
|
||||
#include "CompositorThread.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/ipc/Endpoint.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
#include "transport/runnable_utils.h"
|
||||
#include "SynchronousTask.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
// Singleton
|
||||
static StaticMutex sVideoBridgeLock MOZ_UNANNOTATED;
|
||||
StaticRefPtr<VideoBridgeChild> sVideoBridge;
|
||||
|
||||
/* static */
|
||||
@ -30,7 +33,9 @@ void VideoBridgeChild::StartupForGPUProcess() {
|
||||
VideoBridgeParent::Open(std::move(parentPipe), VideoBridgeSource::GpuProcess);
|
||||
}
|
||||
|
||||
/* static */
|
||||
void VideoBridgeChild::Open(Endpoint<PVideoBridgeChild>&& aEndpoint) {
|
||||
StaticMutexAutoLock lock(sVideoBridgeLock);
|
||||
MOZ_ASSERT(!sVideoBridge || !sVideoBridge->CanSend());
|
||||
sVideoBridge = new VideoBridgeChild();
|
||||
|
||||
@ -42,6 +47,7 @@ void VideoBridgeChild::Open(Endpoint<PVideoBridgeChild>&& aEndpoint) {
|
||||
|
||||
/* static */
|
||||
void VideoBridgeChild::Shutdown() {
|
||||
StaticMutexAutoLock lock(sVideoBridgeLock);
|
||||
if (sVideoBridge) {
|
||||
sVideoBridge->Close();
|
||||
sVideoBridge = nullptr;
|
||||
@ -53,7 +59,10 @@ VideoBridgeChild::VideoBridgeChild()
|
||||
|
||||
VideoBridgeChild::~VideoBridgeChild() = default;
|
||||
|
||||
VideoBridgeChild* VideoBridgeChild::GetSingleton() { return sVideoBridge; }
|
||||
VideoBridgeChild* VideoBridgeChild::GetSingleton() {
|
||||
StaticMutexAutoLock lock(sVideoBridgeLock);
|
||||
return sVideoBridge;
|
||||
}
|
||||
|
||||
bool VideoBridgeChild::AllocUnsafeShmem(size_t aSize, ipc::Shmem* aShmem) {
|
||||
if (!mThread->IsOnCurrentThread()) {
|
||||
|
Loading…
Reference in New Issue
Block a user