patch 1 of bug 110686 "nsStandardURL not thread-safe" r=dougt, sr=mscott

This commit is contained in:
darin%netscape.com 2001-11-28 00:46:29 +00:00
parent 251fd3d269
commit 795d06e95f
2 changed files with 54 additions and 1 deletions

View File

@ -52,6 +52,42 @@ static PRLogModuleInfo *gRequestObserverProxyLog;
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
//-----------------------------------------------------------------------------
// ProxyRelease
//-----------------------------------------------------------------------------
static void *PR_CALLBACK
ProxyRelease_EventHandlerFunc(PLEvent *ev)
{
nsIRequestObserver *obs =
NS_STATIC_CAST(nsIRequestObserver *, PL_GetEventOwner(ev));
NS_RELEASE(obs);
return nsnull;
}
static void PR_CALLBACK
ProxyRelease_EventCleanupFunc(PLEvent *ev)
{
delete ev;
}
static void
ProxyRelease(nsIEventQueue *eventQ, nsIRequestObserver *obs)
{
PLEvent *ev = new PLEvent;
if (!ev) {
NS_ERROR("failed to allocate PLEvent");
return;
}
PL_InitEvent(ev, (void *) obs,
ProxyRelease_EventHandlerFunc,
ProxyRelease_EventCleanupFunc);
PRStatus rv = eventQ->PostEvent(ev);
NS_ASSERTION(rv == PR_SUCCESS, "PostEvent failed");
}
//-----------------------------------------------------------------------------
// nsARequestObserverEvent internal class...
//-----------------------------------------------------------------------------
@ -177,6 +213,23 @@ public:
}
};
//-----------------------------------------------------------------------------
// nsRequestObserverProxy <public>
//-----------------------------------------------------------------------------
nsRequestObserverProxy::~nsRequestObserverProxy()
{
if (mObserver) {
// order is crucial here... we must be careful to clear mObserver
// before posting the proxy release event. otherwise, we'd risk
// releasing the object on this thread.
nsIRequestObserver *obs = mObserver;
NS_ADDREF(obs);
mObserver = 0;
ProxyRelease(mEventQ, obs);
}
}
//-----------------------------------------------------------------------------
// nsRequestObserverProxy::nsISupports implementation...
//-----------------------------------------------------------------------------

View File

@ -55,7 +55,7 @@ public:
NS_DECL_NSIREQUESTOBSERVERPROXY
nsRequestObserverProxy() { NS_INIT_ISUPPORTS(); }
virtual ~nsRequestObserverProxy() {}
virtual ~nsRequestObserverProxy();
nsIRequestObserver *Observer() { return mObserver; }