Bug 1746488: xpcom/io cleanup r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D134062
This commit is contained in:
Randell Jesup 2022-01-04 14:21:56 +00:00
Родитель e69bdb74e3
Коммит 7a46e96bdf
2 изменённых файлов: 44 добавлений и 22 удалений

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

@ -185,6 +185,7 @@ NonBlockingAsyncInputStream::Available(uint64_t* aLength) {
// Nothing more to read. Let's close the stream now.
if (*aLength == 0) {
MutexAutoLock lock(mLock);
mInputStream->Close();
mClosed = true;
return NS_BASE_STREAM_CLOSED;

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

@ -158,9 +158,17 @@ class nsMultiplexInputStream final : public nsIMultiplexInputStream,
uint32_t mSeekableStreams;
uint32_t mIPCSerializableStreams;
uint32_t mCloneableStreams;
uint32_t mAsyncInputStreams;
uint32_t mInputStreamLengths;
uint32_t mAsyncInputStreamLengths;
// These are Atomics so that we can check them in QueryInterface without
// taking a lock (to look at mStreams.Length() and the numbers above)
// With no streams added yet, all of these are possible
Atomic<bool, Relaxed> mIsSeekableStream{true};
Atomic<bool, Relaxed> mIsIPCSerializableStream{true};
Atomic<bool, Relaxed> mIsCloneableStream{true};
Atomic<bool, Relaxed> mIsAsyncInputStream{false};
Atomic<bool, Relaxed> mIsInputStreamLength{false};
Atomic<bool, Relaxed> mIsAsyncInputStreamLength{false};
};
NS_IMPL_ADDREF(nsMultiplexInputStream)
@ -220,10 +228,7 @@ nsMultiplexInputStream::nsMultiplexInputStream()
mAsyncWaitRequestedCount(0),
mSeekableStreams(0),
mIPCSerializableStreams(0),
mCloneableStreams(0),
mAsyncInputStreams(0),
mInputStreamLengths(0),
mAsyncInputStreamLengths(0) {}
mCloneableStreams(0) {}
NS_IMETHODIMP
nsMultiplexInputStream::GetCount(uint32_t* aCount) {
@ -866,9 +871,9 @@ nsresult nsMultiplexInputStream::AsyncWaitInternal() {
asyncWaitFlags = mAsyncWaitFlags;
asyncWaitRequestedCount = mAsyncWaitRequestedCount;
asyncWaitEventTarget = mAsyncWaitEventTarget;
}
MOZ_ASSERT_IF(stream, NS_SUCCEEDED(mStatus));
MOZ_ASSERT_IF(stream, NS_SUCCEEDED(mStatus));
}
// If we are here it's because we are already closed, or if the current stream
// is not async. In both case we have to execute the callback.
@ -1035,6 +1040,7 @@ bool nsMultiplexInputStream::Deserialize(
}
}
MutexAutoLock lock(mLock);
mCurrentStream = params.currentStream();
mStatus = params.status();
mStartedReadingCurrent = params.startedReadingCurrent();
@ -1409,39 +1415,54 @@ void nsMultiplexInputStream::AsyncWaitCompleted(
MAYBE_UPDATE_VALUE_REAL(x, substream) \
}
#define MAYBE_UPDATE_BOOL(x, y) \
if (!x) { \
nsCOMPtr<y> substream = do_QueryInterface(aStream.mBufferedStream); \
if (substream) { \
x = true; \
} \
}
void nsMultiplexInputStream::UpdateQIMap(StreamData& aStream) {
auto length = mStreams.Length();
MAYBE_UPDATE_VALUE_REAL(mSeekableStreams, aStream.mSeekableStream)
mIsSeekableStream = (mSeekableStreams == length);
MAYBE_UPDATE_VALUE(mIPCSerializableStreams, nsIIPCSerializableInputStream)
mIsIPCSerializableStream = (mIPCSerializableStreams == length);
MAYBE_UPDATE_VALUE(mCloneableStreams, nsICloneableInputStream)
MAYBE_UPDATE_VALUE_REAL(mAsyncInputStreams, aStream.mAsyncStream)
MAYBE_UPDATE_VALUE(mInputStreamLengths, nsIInputStreamLength)
MAYBE_UPDATE_VALUE(mAsyncInputStreamLengths, nsIAsyncInputStreamLength)
mIsCloneableStream = (mCloneableStreams == length);
// nsMultiplexInputStream is nsIAsyncInputStream if at least 1 of the
// substream implements that interface
if (!mIsAsyncInputStream && aStream.mAsyncStream) {
mIsAsyncInputStream = true;
}
MAYBE_UPDATE_BOOL(mIsInputStreamLength, nsIInputStreamLength)
MAYBE_UPDATE_BOOL(mIsAsyncInputStreamLength, nsIAsyncInputStreamLength)
}
#undef MAYBE_UPDATE_VALUE
#undef MAYBE_UPDATE_VALUE_REAL
#undef MAYBE_UPDATE_BOOL
bool nsMultiplexInputStream::IsSeekable() const {
return mStreams.Length() == mSeekableStreams;
}
bool nsMultiplexInputStream::IsSeekable() const { return mIsSeekableStream; }
bool nsMultiplexInputStream::IsIPCSerializable() const {
return mStreams.Length() == mIPCSerializableStreams;
return mIsIPCSerializableStream;
}
bool nsMultiplexInputStream::IsCloneable() const {
return mStreams.Length() == mCloneableStreams;
}
bool nsMultiplexInputStream::IsCloneable() const { return mIsCloneableStream; }
bool nsMultiplexInputStream::IsAsyncInputStream() const {
// nsMultiplexInputStream is nsIAsyncInputStream if at least 1 of the
// substream implements that interface.
return !!mAsyncInputStreams;
return mIsAsyncInputStream;
}
bool nsMultiplexInputStream::IsInputStreamLength() const {
return !!mInputStreamLengths;
return mIsInputStreamLength;
}
bool nsMultiplexInputStream::IsAsyncInputStreamLength() const {
return !!mAsyncInputStreamLengths;
return mIsAsyncInputStreamLength;
}