From e3f8423ef9253fc19086fe1b2891a941aa2522b5 Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Tue, 4 Apr 2000 08:49:49 +0000 Subject: [PATCH] Added assertions to prove that cancel was being used in a thread-safe way. Bug 31091. --- netwerk/protocol/file/src/nsFileChannel.cpp | 42 ++++++++++++++++++++- netwerk/protocol/file/src/nsFileChannel.h | 3 ++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/netwerk/protocol/file/src/nsFileChannel.cpp b/netwerk/protocol/file/src/nsFileChannel.cpp index 30ad089efe29..95b7d9a71f2f 100644 --- a/netwerk/protocol/file/src/nsFileChannel.cpp +++ b/netwerk/protocol/file/src/nsFileChannel.cpp @@ -41,6 +41,9 @@ static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); nsFileChannel::nsFileChannel() : mIOFlags(-1), mPerm(-1), +#ifdef DEBUG + mInitiator(nsnull), +#endif mLoadAttributes(LOAD_NORMAL), mBufferSegmentSize(0), mBufferMaxSize(0), @@ -125,6 +128,10 @@ nsFileChannel::GetStatus(nsresult *status) NS_IMETHODIMP nsFileChannel::Cancel(nsresult status) { +#ifdef DEBUG + NS_ASSERTION(mInitiator == PR_CurrentThread(), + "wrong thread calling this routine"); +#endif mStatus = status; if (mFileTransport) return mFileTransport->Cancel(status); @@ -134,6 +141,10 @@ nsFileChannel::Cancel(nsresult status) NS_IMETHODIMP nsFileChannel::Suspend() { +#ifdef DEBUG + NS_ASSERTION(mInitiator == PR_CurrentThread(), + "wrong thread calling this routine"); +#endif if (mFileTransport) return mFileTransport->Suspend(); return NS_OK; @@ -142,6 +153,10 @@ nsFileChannel::Suspend() NS_IMETHODIMP nsFileChannel::Resume() { +#ifdef DEBUG + NS_ASSERTION(mInitiator == PR_CurrentThread(), + "wrong thread calling this routine"); +#endif if (mFileTransport) return mFileTransport->Resume(); return NS_OK; @@ -275,6 +290,12 @@ nsFileChannel::AsyncRead(nsIStreamListener *listener, { nsresult rv; +#ifdef DEBUG + NS_ASSERTION(mInitiator == nsnull || mInitiator == PR_CurrentThread(), + "wrong thread calling this routine"); + mInitiator = PR_CurrentThread(); +#endif + if (mFileTransport) return NS_ERROR_IN_PROGRESS; @@ -319,6 +340,12 @@ nsFileChannel::AsyncWrite(nsIInputStream *fromStream, { nsresult rv; +#ifdef DEBUG + NS_ASSERTION(mInitiator == nsnull || mInitiator == PR_CurrentThread(), + "wrong thread calling this routine"); + mInitiator = PR_CurrentThread(); +#endif + if (mFileTransport) return NS_ERROR_IN_PROGRESS; @@ -550,6 +577,10 @@ nsFileChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) NS_IMETHODIMP nsFileChannel::OnStartRequest(nsIChannel* transportChannel, nsISupports* context) { +#ifdef DEBUG + NS_ASSERTION(mInitiator == PR_CurrentThread(), + "wrong thread calling this routine"); +#endif NS_ASSERTION(mRealListener, "No listener..."); return mRealListener->OnStartRequest(this, context); } @@ -558,6 +589,11 @@ NS_IMETHODIMP nsFileChannel::OnStopRequest(nsIChannel* transportChannel, nsISupports* context, nsresult aStatus, const PRUnichar* aMsg) { +#ifdef DEBUG + NS_ASSERTION(mInitiator == PR_CurrentThread(), + "wrong thread calling this routine"); +#endif + nsresult rv; rv = mRealListener->OnStopRequest(this, context, aStatus, aMsg); @@ -579,8 +615,12 @@ nsFileChannel::OnDataAvailable(nsIChannel* transportChannel, nsISupports* contex nsIInputStream *aIStream, PRUint32 aSourceOffset, PRUint32 aLength) { - nsresult rv; +#ifdef DEBUG + NS_ASSERTION(mInitiator == PR_CurrentThread(), + "wrong thread calling this routine"); +#endif + nsresult rv; rv = mRealListener->OnDataAvailable(this, context, aIStream, aSourceOffset, aLength); diff --git a/netwerk/protocol/file/src/nsFileChannel.h b/netwerk/protocol/file/src/nsFileChannel.h index 5d77a60ac4eb..754345ffe5d3 100644 --- a/netwerk/protocol/file/src/nsFileChannel.h +++ b/netwerk/protocol/file/src/nsFileChannel.h @@ -82,6 +82,9 @@ protected: PRUint32 mBufferSegmentSize; PRUint32 mBufferMaxSize; nsresult mStatus; +#ifdef DEBUG + PRThread* mInitiator; +#endif }; #endif // nsFileChannel_h__