Bug 1341496 - Part 1: Don't try to serialize read locks that aren't valid. r=nical
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 19 Apr 2017 15:15:42 +1200
changeset 565143 c5785434af743a93ea15a6270dc5cab9259f0fa0
parent 565142 8404a67bd0cded2579748e802dfe274685394954
child 565144 f4c724034728dbca08651d0b6047c8e778142237
push id54802
push userdgottwald@mozilla.com
push dateWed, 19 Apr 2017 15:26:27 +0000
reviewersnical
bugs1341496
milestone55.0a1
Bug 1341496 - Part 1: Don't try to serialize read locks that aren't valid. r=nical
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();
   }