Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsProxyRelease.h File Reference
#include "nsIEventQueueService.h"
#include "pratom.h"
#include "prmem.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


#define nsProxyRelease_h__
#define NS_IMPL_PROXY_RELEASE(_class)


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.

Define Documentation

Definition at line 62 of file nsProxyRelease.h.

Definition at line 39 of file nsProxyRelease.h.

Function Documentation

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.

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) {
        return NS_OK;

    if (!alwaysProxy) {
        PRBool onCurrentThread = PR_FALSE;
        rv = target->IsOnCurrentThread(&onCurrentThread);
        if (NS_SUCCEEDED(rv) && onCurrentThread) {
            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,

    rv = target->PostEvent(ev);
    if (NS_FAILED(rv)) {
        NS_WARNING("failed to post proxy release event");
        // 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: