Bug 1514417 - Add mutex to avoid VR shmem be deadlock when VRService and VRSubmitFrame threads are accessing it. r=kip

MozReview-Commit-ID: 7uXdypiXTUH

Differential Revision: https://phabricator.services.mozilla.com/D17581

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daosheng Mu 2019-01-25 01:04:09 +00:00
Родитель 68c5929c0b
Коммит e3c0193666
4 изменённых файлов: 17 добавлений и 2 удалений

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

@ -426,8 +426,8 @@ VRSystemManagerExternal::VRSystemManagerExternal(
VRExternalShmem* aAPIShmem /* = nullptr*/)
: mExternalShmem(aAPIShmem)
#if !defined(MOZ_WIDGET_ANDROID)
,
mSameProcess(aAPIShmem != nullptr)
, mMutex("VRSystemManagerExternal::mMutex")
, mSameProcess(aAPIShmem != nullptr)
#endif
{
#if defined(XP_MACOSX)
@ -844,6 +844,10 @@ void VRSystemManagerExternal::PushState(VRBrowserState* aBrowserState,
pthread_mutex_unlock((pthread_mutex_t*)&(mExternalShmem->browserMutex));
}
#else
// We need this MutexAutoLock to avoid mAPIShmem happens deadlock issue
// when both of VRService and VRSubmitFrame threads are writing/reading
// it from the memory.
MutexAutoLock lock(mMutex);
mExternalShmem->browserGenerationA++;
memcpy((void*)&(mExternalShmem->browserState), (void*)aBrowserState,
sizeof(VRBrowserState));

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

@ -134,6 +134,7 @@ class VRSystemManagerExternal : public VRSystemManager {
volatile VRExternalShmem* mExternalShmem;
#if !defined(MOZ_WIDGET_ANDROID)
Mutex mMutex;
bool mSameProcess;
#endif
TimeStamp mEarliestRestartTime;

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

@ -68,6 +68,9 @@ VRService::VRService()
mTargetShmemFile(0),
mLastHapticState{},
mFrameStartTime{},
#if !defined(MOZ_WIDGET_ANDROID)
mMutex("VRService::mMutex"),
#endif
mVRProcessEnabled(gfxPrefs::VRProcessEnabled()) {
// When we have the VR process, we map the memory
// of mAPIShmem from GPU process.
@ -456,6 +459,10 @@ void VRService::PullState(mozilla::gfx::VRBrowserState& aState) {
pthread_mutex_unlock((pthread_mutex_t*)&(mExternalShmem->browserMutex));
}
#else
// We need this MutexAutoLock to avoid mAPIShmem happens deadlock issue
// when both of VRService and VRSubmitFrame threads are writing/reading
// it from the memory.
MutexAutoLock lock(mMutex);
VRExternalShmem tmp;
if (mAPIShmem->browserGenerationA != mBrowserGeneration) {
memcpy(&tmp, mAPIShmem, sizeof(VRExternalShmem));

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

@ -63,6 +63,9 @@ class VRService {
base::ProcessHandle mTargetShmemFile;
VRHapticState mLastHapticState[kVRHapticsMaxCount];
TimeStamp mFrameStartTime[kVRFrameTimingHistoryDepth];
#if !defined(MOZ_WIDGET_ANDROID)
Mutex mMutex;
#endif
// We store the value of gfxPrefs::VRProcessEnabled() in mVRProcessEnabled.
// This allows us to read the value in the VRService destructor, after
// gfxPrefs has been shut down. We should investigate why gfxPrefs