Commit dd0cb7b3 authored by Simon Giesecke's avatar Simon Giesecke
Browse files

Bug 708901 - Migrate to nsTHashSet in dom/media. r=padenot

Depends on D109320

Differential Revision: https://phabricator.services.mozilla.com/D109321
parent aff704cd
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "nsIObserverService.h"
#include "nsPrintfCString.h"
#include "nsProxyRelease.h"
#include "nsTHashSet.h"
#include "nsThreadUtils.h"
#include "prio.h"
#include "VideoUtils.h"
@@ -1068,15 +1069,14 @@ void MediaCache::SwapBlocks(AutoLock& aLock, int32_t aBlockIndex1,
  // Now update references to blocks in block lists.
  mFreeBlocks.NotifyBlockSwapped(aBlockIndex1, aBlockIndex2);

  nsTHashtable<nsPtrHashKey<MediaCacheStream> > visitedStreams;
  nsTHashSet<MediaCacheStream*> visitedStreams;

  for (int32_t i = 0; i < 2; ++i) {
    for (uint32_t j = 0; j < blocks[i]->mOwners.Length(); ++j) {
      MediaCacheStream* stream = blocks[i]->mOwners[j].mStream;
      // Make sure that we don't update the same stream twice --- that
      // would result in swapping the block references back again!
      if (visitedStreams.GetEntry(stream)) continue;
      visitedStreams.PutEntry(stream);
      if (!visitedStreams.EnsureInserted(stream)) continue;
      stream->mReadaheadBlocks.NotifyBlockSwapped(aBlockIndex1, aBlockIndex2);
      stream->mPlayedBlocks.NotifyBlockSwapped(aBlockIndex1, aBlockIndex2);
      stream->mMetadataBlocks.NotifyBlockSwapped(aBlockIndex1, aBlockIndex2);
+4 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include "mozilla/Unused.h"
#include "nsContentUtils.h"
#include "nsPrintfCString.h"
#include "nsTHashSet.h"

using namespace mozilla::media;

@@ -75,7 +76,7 @@ class MediaFormatReader::ShutdownPromisePool {
 private:
  bool mShutdown = false;
  const RefPtr<ShutdownPromise::Private> mOnShutdownComplete;
  nsTHashtable<nsRefPtrHashKey<ShutdownPromise>> mPromises;
  nsTHashSet<RefPtr<ShutdownPromise>> mPromises;
};

RefPtr<ShutdownPromise> MediaFormatReader::ShutdownPromisePool::Shutdown() {
@@ -91,10 +92,10 @@ void MediaFormatReader::ShutdownPromisePool::Track(
    RefPtr<ShutdownPromise> aPromise) {
  MOZ_DIAGNOSTIC_ASSERT(!mShutdown);
  MOZ_DIAGNOSTIC_ASSERT(!mPromises.Contains(aPromise));
  mPromises.PutEntry(aPromise);
  mPromises.Insert(aPromise);
  aPromise->Then(AbstractThread::GetCurrent(), __func__, [aPromise, this]() {
    MOZ_DIAGNOSTIC_ASSERT(mPromises.Contains(aPromise));
    mPromises.RemoveEntry(aPromise);
    mPromises.Remove(aPromise);
    if (mShutdown && mPromises.Count() == 0) {
      mOnShutdownComplete->Resolve(true, __func__);
    }
+4 −5
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ nsresult MediaShutdownManager::Register(MediaDecoder* aDecoder) {
  // Don't call Register() after you've Unregistered() all the decoders,
  // that's not going to work.
  MOZ_ASSERT(!mDecoders.Contains(aDecoder));
  mDecoders.PutEntry(aDecoder);
  mDecoders.Insert(aDecoder);
  MOZ_ASSERT(mDecoders.Contains(aDecoder));
  MOZ_ASSERT(mDecoders.Count() > 0);
  return NS_OK;
@@ -113,10 +113,9 @@ nsresult MediaShutdownManager::Register(MediaDecoder* aDecoder) {

void MediaShutdownManager::Unregister(MediaDecoder* aDecoder) {
  MOZ_ASSERT(NS_IsMainThread());
  if (!mDecoders.Contains(aDecoder)) {
  if (!mDecoders.EnsureRemoved(aDecoder)) {
    return;
  }
  mDecoders.RemoveEntry(aDecoder);
  if (sInitPhase == XPCOMShutdownStarted && mDecoders.Count() == 0) {
    RemoveBlocker();
  }
@@ -150,8 +149,8 @@ MediaShutdownManager::BlockShutdown(nsIAsyncShutdownClient*) {
  }

  // Iterate over the decoders and shut them down.
  for (auto iter = mDecoders.Iter(); !iter.Done(); iter.Next()) {
    iter.Get()->GetKey()->NotifyXPCOMShutdown();
  for (const auto& key : mDecoders) {
    key->NotifyXPCOMShutdown();
    // Check MediaDecoder::Shutdown doesn't call Unregister() synchronously in
    // order not to corrupt our hashtable traversal.
    MOZ_ASSERT(mDecoders.Count() == oldCount);
+2 −3
Original line number Diff line number Diff line
@@ -13,8 +13,7 @@
#  include "nsCOMPtr.h"
#  include "nsIAsyncShutdown.h"
#  include "nsIThread.h"
#  include "nsHashKeys.h"
#  include "nsTHashtable.h"
#  include "nsTHashSet.h"

namespace mozilla {

@@ -89,7 +88,7 @@ class MediaShutdownManager : public nsIAsyncShutdownBlocker {
  // References to the MediaDecoder. The decoders unregister themselves
  // in their Shutdown() method, so we'll drop the reference naturally when
  // we're shutting down (in the non xpcom-shutdown case).
  nsTHashtable<nsRefPtrHashKey<MediaDecoder>> mDecoders;
  nsTHashSet<RefPtr<MediaDecoder>> mDecoders;
};

}  // namespace mozilla
+3 −4
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ mozilla::ipc::IPCResult GMPTimerParent::RecvSetTimer(
  ctx->mId = aTimerId;
  ctx->mParent = this;

  mTimers.PutEntry(ctx.release());
  mTimers.Insert(ctx.release());

  return IPC_OK();
}
@@ -57,8 +57,7 @@ void GMPTimerParent::Shutdown() {

  MOZ_ASSERT(mGMPEventTarget->IsOnCurrentThread());

  for (auto iter = mTimers.Iter(); !iter.Done(); iter.Next()) {
    Context* context = iter.Get()->GetKey();
  for (Context* context : mTimers) {
    context->mTimer->Cancel();
    delete context;
  }
@@ -94,7 +93,7 @@ void GMPTimerParent::TimerExpired(Context* aContext) {
  }

  uint32_t id = aContext->mId;
  mTimers.RemoveEntry(aContext);
  mTimers.Remove(aContext);
  if (id) {
    Unused << SendTimerExpired(id);
  }
Loading