Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
nsToolkit.cpp File Reference
#include "nscore.h"
#include "nsToolkit.h"

Go to the source code of this file.

Functions

NS_METHOD NS_GetCurrentToolkit (nsIToolkit **aResult)

Variables

static PRUintn gToolkitTLSIndex = 0

Function Documentation

Definition at line 117 of file nsToolkit.cpp.

{
    nsIToolkit* toolkit = nsnull;
    nsresult rv = NS_OK;
    PRStatus status;

    // Create the TLS index the first time through...
    if (0 == gToolkitTLSIndex) {
        status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
        if (PR_FAILURE == status) {
            rv = NS_ERROR_FAILURE;
        }
    }

    if (NS_SUCCEEDED(rv)) {
        toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);

        //
        // Create a new toolkit for this thread...
        //
        if (!toolkit) {
            toolkit = new nsToolkit();

            if (!toolkit) {
                rv = NS_ERROR_OUT_OF_MEMORY;
            } else {
                NS_ADDREF(toolkit);
                toolkit->Init(PR_GetCurrentThread());
                //
                // The reference stored in the TLS is weak.  It is
                // removed in the nsToolkit destructor...
                //
                PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit);
            }
        } else {
            NS_ADDREF(toolkit);
        }
        *aResult = toolkit;
    }

    return rv;
}

Here is the call graph for this function:


Variable Documentation

PRUintn gToolkitTLSIndex = 0 [static]

Definition at line 47 of file nsToolkit.cpp.