Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsProxyRelease.cpp File Reference
#include "nsProxyRelease.h"

Go to the source code of this file.

Functions

 HandleProxyReleaseEvent (PLEvent *self)
 DestroyProxyReleaseEvent (PLEvent *self)
NS_COM nsresult NS_ProxyRelease (nsIEventTarget *target, nsISupports *doomed, PRBool alwaysProxy)
 Ensures that the delete of a nsISupports object occurs on the target thread.

Function Documentation

Definition at line 12 of file nsProxyRelease.cpp.

{
    delete self;
}

Here is the caller graph for this function:

Definition at line 4 of file nsProxyRelease.cpp.

{              
    nsISupports* owner = (nsISupports*) self->owner;
    NS_RELEASE(owner);                                                                                              
    return nsnull;                                            
}

Here is the caller graph for this function:

NS_COM nsresult NS_ProxyRelease ( nsIEventTarget target,
nsISupports *  doomed,
PRBool  alwaysProxy = PR_FALSE 
)

Ensures that the delete of a nsISupports object occurs on the target thread.

Parameters:
targetthe target thread where the doomed object should be released.
doomedthe doomed object; the object to be released on the target thread.
alwaysProxynormally, if NS_ProxyRelease is called on the target thread, then the doomed object will released directly. however, if this parameter is true, then a PLEvent will always be posted to the target thread and the release will happen when that PLEvent is handled.

Definition at line 18 of file nsProxyRelease.cpp.

{
    nsresult rv;

    if (!target) {
        NS_RELEASE(doomed);
        return NS_OK;
    }

    if (!alwaysProxy) {
        PRBool onCurrentThread = PR_FALSE;
        rv = target->IsOnCurrentThread(&onCurrentThread);
        if (NS_SUCCEEDED(rv) && onCurrentThread) {
            NS_RELEASE(doomed);
            return NS_OK;
        }
    }

    PLEvent *ev = new PLEvent;
    if (!ev) {
        // we do not release doomed here since it may cause a delete on the
        // wrong thread.  better to leak than crash. 
        return NS_ERROR_OUT_OF_MEMORY;
    }

    PL_InitEvent(ev, doomed,
                 HandleProxyReleaseEvent,
                 DestroyProxyReleaseEvent);

    rv = target->PostEvent(ev);
    if (NS_FAILED(rv)) {
        NS_WARNING("failed to post proxy release event");
        PL_DestroyEvent(ev);
        // again, it is better to leak the doomed object than risk crashing as
        // a result of deleting it on the wrong thread.
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function: