diff --git a/netwerk/base/src/nsFileTransport.cpp b/netwerk/base/src/nsFileTransport.cpp index 8ccfd41b9aa..67bd7fe5851 100644 --- a/netwerk/base/src/nsFileTransport.cpp +++ b/netwerk/base/src/nsFileTransport.cpp @@ -24,7 +24,6 @@ #include "nsIFileStream.h" #include "nsFileSpec.h" #include "nsIBuffer.h" -#include "prcmon.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -37,11 +36,13 @@ nsFileTransport::nsFileTransport() mBufferStream(nsnull), mStatus(NS_OK), mService(nsnull), mSourceOffset(0) { NS_INIT_REFCNT(); + mMonitor = PR_NewMonitor(); } nsFileTransport::~nsFileTransport() { if (mPath) nsCRT::free(mPath); + PR_DestroyMonitor(mMonitor); NS_IF_RELEASE(mListener); NS_IF_RELEASE(mContext); NS_IF_RELEASE(mService); @@ -70,7 +71,9 @@ nsFileTransport::Init(nsISupports* context, State state) { nsresult rv = NS_OK; - PR_CEnterMonitor(this); + if (!mMonitor) + return NS_ERROR_OUT_OF_MEMORY; + PR_EnterMonitor(mMonitor); if (mState != ENDED) rv = NS_ERROR_FAILURE; @@ -83,7 +86,7 @@ nsFileTransport::Init(nsISupports* context, mState = state; } - PR_CExitMonitor(this); + PR_ExitMonitor(mMonitor); return rv; } @@ -118,13 +121,15 @@ NS_IMETHODIMP nsFileTransport::Cancel(void) { nsresult rv = NS_OK; - PR_CEnterMonitor(this); + if (!mMonitor) + return NS_ERROR_OUT_OF_MEMORY; + PR_EnterMonitor(mMonitor); mStatus = NS_BINDING_ABORTED; if (mSuspended) { Resume(); } mState = ENDING; - PR_CExitMonitor(this); + PR_ExitMonitor(mMonitor); return rv; } @@ -132,13 +137,15 @@ NS_IMETHODIMP nsFileTransport::Suspend(void) { nsresult rv = NS_OK; - PR_CEnterMonitor(this); + if (!mMonitor) + return NS_ERROR_OUT_OF_MEMORY; + PR_EnterMonitor(mMonitor); if (!mSuspended) { // XXX close the stream here? mStatus = mService->Suspend(this); mSuspended = PR_TRUE; } - PR_CExitMonitor(this); + PR_ExitMonitor(mMonitor); return rv; } @@ -146,13 +153,15 @@ NS_IMETHODIMP nsFileTransport::Resume(void) { nsresult rv = NS_OK; - PR_CEnterMonitor(this); + if (!mMonitor) + return NS_ERROR_OUT_OF_MEMORY; + PR_EnterMonitor(mMonitor); if (!mSuspended) { // XXX re-open the stream and seek here? mStatus = mService->Resume(this); mSuspended = PR_FALSE; } - PR_CExitMonitor(this); + PR_ExitMonitor(mMonitor); return rv; } @@ -226,7 +235,11 @@ nsFileTransport::OpenOutputStream(nsIOutputStream* *result) void nsFileTransport::Process(void) { - PR_CEnterMonitor(this); + if (!mMonitor) { + mState = ENDING; + return; + } + PR_EnterMonitor(mMonitor); switch (mState) { case START_READ: { nsISupports* fs; @@ -314,12 +327,12 @@ nsFileTransport::Process(void) break; } } - PR_CExitMonitor(this); + PR_ExitMonitor(mMonitor); return; error: mState = ENDING; - PR_CExitMonitor(this); + PR_ExitMonitor(mMonitor); return; } diff --git a/netwerk/base/src/nsFileTransport.h b/netwerk/base/src/nsFileTransport.h index 5d5112181ad..929053a01a5 100644 --- a/netwerk/base/src/nsFileTransport.h +++ b/netwerk/base/src/nsFileTransport.h @@ -22,6 +22,7 @@ #include "nsITransport.h" #include "nsIThread.h" #include "plevent.h" +#include "prmon.h" class nsFileTransportService; class nsIBaseStream; @@ -87,6 +88,9 @@ protected: nsIInputStream* mBufferStream; nsresult mStatus; PRUint32 mSourceOffset; + +private: + PRMonitor* mMonitor; }; #define NS_FILE_TRANSPORT_BUFFER_SIZE (4*1024) diff --git a/netwerk/test/TestFileInput.cpp b/netwerk/test/TestFileInput.cpp index 03854c7668d..1208943cb84 100644 --- a/netwerk/test/TestFileInput.cpp +++ b/netwerk/test/TestFileInput.cpp @@ -23,7 +23,7 @@ #include "nsIThread.h" #include "plevent.h" #include "prinrval.h" -#include "prcmon.h" +#include "prmon.h" #include "prio.h" #include "nsIFileStream.h" #include "nsFileSpec.h" @@ -45,10 +45,12 @@ public: NS_IMETHOD Run() { // printf("waiting\n"); - PR_CEnterMonitor(this); + if (!mMonitor) + return NS_ERROR_OUT_OF_MEMORY; + PR_EnterMonitor(mMonitor); if (mEventQueue == nsnull) PR_CWait(this, PR_INTERVAL_NO_TIMEOUT); - PR_CExitMonitor(this); + PR_ExitMonitor(mMonitor); // printf("running\n"); PL_EventLoop(mEventQueue); @@ -60,10 +62,12 @@ public: : mEventQueue(nsnull), mStartTime(0), mThread(nsnull) { NS_INIT_REFCNT(); + mMonitor = PR_NewMonitor(); } virtual ~nsReader() { NS_IF_RELEASE(mThread); + PR_DestroyMonitor(mMonitor); } nsresult Init(nsIThread* thread) { @@ -71,12 +75,12 @@ public: NS_ADDREF(mThread); PRThread* prthread; thread->GetPRThread(&prthread); - PR_CEnterMonitor(this); + PR_EnterMonitor(mMonitor); mEventQueue = PL_CreateEventQueue("runner event loop", prthread); // wake up event loop - PR_CNotify(this); - PR_CExitMonitor(this); + PR_Notify(mMonitor); + PR_ExitMonitor(mMonitor); return NS_OK; } @@ -84,10 +88,10 @@ public: PLEventQueue* GetEventQueue() { return mEventQueue; } NS_IMETHOD OnStartBinding(nsISupports* context) { - PR_CEnterMonitor(this); + PR_EnterMonitor(mMonitor); // printf("start binding\n"); mStartTime = PR_IntervalNow(); - PR_CExitMonitor(this); + PR_ExitMonitor(mMonitor); return NS_OK; } @@ -95,7 +99,7 @@ public: nsIInputStream *aIStream, PRUint32 aSourceOffset, PRUint32 aLength) { - PR_CEnterMonitor(this); + PR_EnterMonitor(mMonitor); char buf[1025]; while (aLength > 0) { PRUint32 amt; @@ -105,7 +109,7 @@ public: aLength -= amt; gVolume += amt; } - PR_CExitMonitor(this); + PR_ExitMonitor(mMonitor); return NS_OK; } @@ -113,7 +117,7 @@ public: nsresult aStatus, nsIString* aMsg) { nsresult rv; - PR_CEnterMonitor(this); + PR_EnterMonitor(mMonitor); if (aStatus == NS_OK) { PRIntervalTime endTime = PR_IntervalNow(); gDuration += (endTime - mStartTime); @@ -121,7 +125,7 @@ public: else { printf("stop binding, %d\n", aStatus); } - PR_CExitMonitor(this); + PR_ExitMonitor(mMonitor); // get me out of my event loop rv = mThread->Interrupt(); @@ -134,6 +138,9 @@ protected: PLEventQueue* mEventQueue; PRIntervalTime mStartTime; nsIThread* mThread; + +private: + PRMonitor* mMonitor; }; NS_IMPL_ADDREF(nsReader);