mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 07:45:30 +00:00
Bug 708901 - Migrate to nsTHashSet in dom/media. r=padenot
Depends on D109320 Differential Revision: https://phabricator.services.mozilla.com/D109321
This commit is contained in:
parent
aff704cd86
commit
dd0cb7b321
@ -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);
|
||||
|
@ -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__);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -9,8 +9,7 @@
|
||||
#include "mozilla/gmp/PGMPTimerParent.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsTHashSet.h"
|
||||
#include "mozilla/Monitor.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -46,7 +45,7 @@ class GMPTimerParent : public PGMPTimerParent {
|
||||
|
||||
void TimerExpired(Context* aContext);
|
||||
|
||||
nsTHashtable<nsPtrHashKey<Context>> mTimers;
|
||||
nsTHashSet<Context*> mTimers;
|
||||
|
||||
nsCOMPtr<nsISerialEventTarget> mGMPEventTarget;
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "AudioNodeEngine.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsTHashSet.h"
|
||||
#include <numeric>
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
@ -72,7 +74,7 @@ class AudioBufferMemoryTracker : public nsIMemoryReporter {
|
||||
/* This protects all members of this class. */
|
||||
static StaticMutex sMutex;
|
||||
static StaticRefPtr<AudioBufferMemoryTracker> sSingleton;
|
||||
nsTHashtable<nsPtrHashKey<const AudioBuffer>> mBuffers;
|
||||
nsTHashSet<const AudioBuffer*> mBuffers;
|
||||
};
|
||||
|
||||
StaticRefPtr<AudioBufferMemoryTracker> AudioBufferMemoryTracker::sSingleton;
|
||||
@ -118,13 +120,13 @@ void AudioBufferMemoryTracker::UnregisterAudioBuffer(
|
||||
void AudioBufferMemoryTracker::RegisterAudioBufferInternal(
|
||||
const AudioBuffer* aAudioBuffer) {
|
||||
sMutex.AssertCurrentThreadOwns();
|
||||
mBuffers.PutEntry(aAudioBuffer);
|
||||
mBuffers.Insert(aAudioBuffer);
|
||||
}
|
||||
|
||||
uint32_t AudioBufferMemoryTracker::UnregisterAudioBufferInternal(
|
||||
const AudioBuffer* aAudioBuffer) {
|
||||
sMutex.AssertCurrentThreadOwns();
|
||||
mBuffers.RemoveEntry(aAudioBuffer);
|
||||
mBuffers.Remove(aAudioBuffer);
|
||||
return mBuffers.Count();
|
||||
}
|
||||
|
||||
@ -133,12 +135,12 @@ MOZ_DEFINE_MALLOC_SIZE_OF(AudioBufferMemoryTrackerMallocSizeOf)
|
||||
NS_IMETHODIMP
|
||||
AudioBufferMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
nsISupports* aData, bool) {
|
||||
size_t amount = 0;
|
||||
|
||||
for (auto iter = mBuffers.Iter(); !iter.Done(); iter.Next()) {
|
||||
amount += iter.Get()->GetKey()->SizeOfIncludingThis(
|
||||
AudioBufferMemoryTrackerMallocSizeOf);
|
||||
}
|
||||
const size_t amount =
|
||||
std::accumulate(mBuffers.cbegin(), mBuffers.cend(), size_t(0),
|
||||
[](size_t val, const AudioBuffer* buffer) {
|
||||
return val + buffer->SizeOfIncludingThis(
|
||||
AudioBufferMemoryTrackerMallocSizeOf);
|
||||
});
|
||||
|
||||
MOZ_COLLECT_REPORT("explicit/webaudio/audiobuffer", KIND_HEAP, UNITS_BYTES,
|
||||
amount, "Memory used by AudioBuffer objects (Web Audio).");
|
||||
|
@ -696,12 +696,12 @@ void AudioContext::RemoveFromDecodeQueue(WebAudioDecodeJob* aDecodeJob) {
|
||||
|
||||
void AudioContext::RegisterActiveNode(AudioNode* aNode) {
|
||||
if (!mCloseCalled) {
|
||||
mActiveNodes.PutEntry(aNode);
|
||||
mActiveNodes.Insert(aNode);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioContext::UnregisterActiveNode(AudioNode* aNode) {
|
||||
mActiveNodes.RemoveEntry(aNode);
|
||||
mActiveNodes.Remove(aNode);
|
||||
}
|
||||
|
||||
uint32_t AudioContext::MaxChannelCount() const {
|
||||
@ -898,8 +898,7 @@ void AudioContext::OnStateChanged(void* aPromise, AudioContextState aNewState) {
|
||||
|
||||
nsTArray<RefPtr<mozilla::MediaTrack>> AudioContext::GetAllTracks() const {
|
||||
nsTArray<RefPtr<mozilla::MediaTrack>> tracks;
|
||||
for (auto iter = mAllNodes.ConstIter(); !iter.Done(); iter.Next()) {
|
||||
AudioNode* node = iter.Get()->GetKey();
|
||||
for (AudioNode* node : mAllNodes) {
|
||||
mozilla::MediaTrack* t = node->GetTrack();
|
||||
if (t) {
|
||||
tracks.AppendElement(t);
|
||||
@ -1192,12 +1191,12 @@ void AudioContext::CloseInternal(void* aPromise,
|
||||
|
||||
void AudioContext::RegisterNode(AudioNode* aNode) {
|
||||
MOZ_ASSERT(!mAllNodes.Contains(aNode));
|
||||
mAllNodes.PutEntry(aNode);
|
||||
mAllNodes.Insert(aNode);
|
||||
}
|
||||
|
||||
void AudioContext::UnregisterNode(AudioNode* aNode) {
|
||||
MOZ_ASSERT(mAllNodes.Contains(aNode));
|
||||
mAllNodes.RemoveEntry(aNode);
|
||||
mAllNodes.Remove(aNode);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise> AudioContext::StartRendering(ErrorResult& aRv) {
|
||||
@ -1268,8 +1267,7 @@ AudioContext::CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
nsISupports* aData, bool aAnonymize) {
|
||||
const nsLiteralCString nodeDescription(
|
||||
"Memory used by AudioNode DOM objects (Web Audio).");
|
||||
for (auto iter = mAllNodes.ConstIter(); !iter.Done(); iter.Next()) {
|
||||
AudioNode* node = iter.Get()->GetKey();
|
||||
for (AudioNode* node : mAllNodes) {
|
||||
int64_t amount = node->SizeOfIncludingThis(MallocSizeOf);
|
||||
nsPrintfCString domNodePath("explicit/webaudio/audio-node/%s/dom-nodes",
|
||||
node->NodeType());
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsTHashMap.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsTHashtable.h"
|
||||
#include "nsTHashSet.h"
|
||||
#include "js/TypeDecls.h"
|
||||
#include "nsIMemoryReporter.h"
|
||||
|
||||
@ -399,9 +399,9 @@ class AudioContext final : public DOMEventTargetHelper,
|
||||
nsTArray<RefPtr<Promise>> mPendingResumePromises;
|
||||
// See RegisterActiveNode. These will keep the AudioContext alive while it
|
||||
// is rendering and the window remains alive.
|
||||
nsTHashtable<nsRefPtrHashKey<AudioNode>> mActiveNodes;
|
||||
nsTHashSet<RefPtr<AudioNode>> mActiveNodes;
|
||||
// Raw (non-owning) references to all AudioNodes for this AudioContext.
|
||||
nsTHashtable<nsPtrHashKey<AudioNode>> mAllNodes;
|
||||
nsTHashSet<AudioNode*> mAllNodes;
|
||||
nsTHashMap<nsStringHashKey, AudioParamDescriptorMap> mWorkletParamDescriptors;
|
||||
// Cache to avoid recomputing basic waveforms all the time.
|
||||
RefPtr<BasicWaveFormCache> mBasicWaveFormCache;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "mozilla/dom/WorkletPrincipals.h"
|
||||
#include "mozilla/dom/AudioParamDescriptorBinding.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsTHashtable.h"
|
||||
#include "nsTHashSet.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
@ -214,7 +214,7 @@ AudioParamDescriptorMap AudioWorkletGlobalScope::DescriptorsFromJS(
|
||||
JSContext* aCx, JS::ForOfIterator* aIter, ErrorResult& aRv) {
|
||||
AudioParamDescriptorMap res;
|
||||
// To check for duplicates
|
||||
nsTHashtable<nsStringHashKey> namesSet;
|
||||
nsTHashSet<nsString> namesSet;
|
||||
|
||||
JS::Rooted<JS::Value> nextValue(aCx);
|
||||
bool done = false;
|
||||
@ -250,7 +250,7 @@ AudioParamDescriptorMap AudioWorkletGlobalScope::DescriptorsFromJS(
|
||||
return AudioParamDescriptorMap();
|
||||
}
|
||||
|
||||
if (!namesSet.PutEntry(descriptor.mName, fallible)) {
|
||||
if (!namesSet.Insert(descriptor.mName, fallible)) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return AudioParamDescriptorMap();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user