Bug 1341496 - Part 1: Don't try to serialize read locks that aren't valid. r?nical draft
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 07 Apr 2017 16:36:13 +1200
changeset 557681 70503bbbc3dc89100af5c2cc4c27af92b599108c
parent 557546 422bd63b18bc5b11482255aaaef1826285309233
child 557682 86370a556914d409810072c78534896c39579e86
push id52782
push usermwoodrow@mozilla.com
push dateFri, 07 Apr 2017 04:36:35 +0000
reviewersnical
bugs1341496
milestone55.0a1
Bug 1341496 - Part 1: Don't try to serialize read locks that aren't valid. r?nical MozReview-Commit-ID: 4CNlzWPlQMo
gfx/layers/client/TextureClient.cpp
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -582,23 +582,24 @@ TextureClient::EnableReadLock()
 
 bool
 TextureClient::SerializeReadLock(ReadLockDescriptor& aDescriptor)
 {
   if (mReadLock && mUpdated) {
     // Take a read lock on behalf of the TextureHost. The latter will unlock
     // after the shared data is available again for drawing.
     mReadLock->ReadLock();
-    mReadLock->Serialize(aDescriptor, GetAllocator()->GetParentPid());
     mUpdated = false;
-    return true;
-  } else {
-    aDescriptor = null_t();
-    return false;
+    if (mReadLock->Serialize(aDescriptor, GetAllocator()->GetParentPid())) {
+      return true;
+    }
   }
+
+  aDescriptor = null_t();
+  return false;
 }
 
 TextureClient::~TextureClient()
 {
   mReadLock = nullptr;
   Destroy();
 }
 
@@ -1441,24 +1442,33 @@ public:
     : mSemaphore("TextureReadLock", 1)
   {}
   explicit CrossProcessSemaphoreReadLock(CrossProcessSemaphoreHandle aHandle)
     : mSemaphore(aHandle)
   {}
 
   virtual bool ReadLock() override
   {
+    if (!IsValid()) {
+      return false;
+    }
     return mSemaphore.Wait();
   }
   virtual bool TryReadLock(TimeDuration aTimeout) override
   {
+    if (!IsValid()) {
+      return false;
+    }
     return mSemaphore.Wait(Some(aTimeout));
   }
   virtual int32_t ReadUnlock() override
   {
+    if (!IsValid()) {
+      return 1;
+    }
     mSemaphore.Signal();
     return 1;
   }
   virtual bool IsValid() const override { return true; }
 
   virtual bool Serialize(ReadLockDescriptor& aOutput, base::ProcessId aOther) override;
 
   virtual LockType GetType() override { return TYPE_CROSS_PROCESS_SEMAPHORE; }
@@ -1640,18 +1650,22 @@ ShmemTextureReadLock::GetReadCount() {
   }
   ShmReadLockInfo* info = GetShmReadLockInfoPtr();
   return info->readCount;
 }
 
 bool
 CrossProcessSemaphoreReadLock::Serialize(ReadLockDescriptor& aOutput, base::ProcessId aOther)
 {
-  aOutput = ReadLockDescriptor(CrossProcessSemaphoreDescriptor(mSemaphore.ShareToProcess(aOther)));
-  return true;
+  if (IsValid()) {
+    aOutput = ReadLockDescriptor(CrossProcessSemaphoreDescriptor(mSemaphore.ShareToProcess(aOther)));
+    return true;
+  } else {
+    return false;
+  }
 }
 
 void
 TextureClient::EnableBlockingReadLock()
 {
   if (!mReadLock) {
     mReadLock = new CrossProcessSemaphoreReadLock();
   }