Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
dllmain.cpp File Reference
#include "PyXPCOM_std.h"
#include <prthread.h>

Go to the source code of this file.

Classes

struct  ThreadData
struct  DllInitializer

Functions

void PyXPCOM_InterpreterState_Ensure ()
void PyXPCOM_InterpreterState_Free ()
PRBool PyXPCOM_ThreadState_Ensure ()
void PyXPCOM_InterpreterLock_Acquire ()
void PyXPCOM_InterpreterLock_Release ()
void PyXPCOM_ThreadState_Free ()
void PyXPCOM_ThreadState_Clear ()
void PyXPCOM_AcquireGlobalLock (void)
void PyXPCOM_ReleaseGlobalLock (void)
void PyXPCOM_DLLAddRef (void)
void PyXPCOM_DLLRelease (void)
void pyxpcom_construct (void)
void pyxpcom_destruct (void)

Variables

static PRInt32 g_cLockCount = 0
static PRLockg_lockMain = nsnull
static PyThreadState * ptsGlobal = nsnull
PyInterpreterState * PyXPCOM_InterpreterState = nsnull
PRUintn tlsIndex = 0
struct DllInitializer dll_initializer

Class Documentation

struct ThreadData

Definition at line 290 of file sqliteInt.h.

Collaboration diagram for ThreadData:
Class Members
CERTCertificate * cert
int client
int data_read
int data_sent
int data_tosend
int dummy
PRFileDesc * event
int exit_code
PRFileDesc * fd
int index
PRNetAddr na
struct ThreadData * next
BtShared * pBtree
PRPollDesc pd
struct ThreadData * peer
CERTCertificate * peercert
int peerport
PRFileDesc * r
char recvbuf
PRFileDesc * s
int secerr
int secerr_flag
char sendbuf
int state
char * status_cipher
char * status_issuer
int status_keysize
int status_on
int status_skeysize
char * status_subject
PRThread * subthread
PyThreadState * ts
u8 useSharedData
unsigned char xor_reading
unsigned char xor_writing

Function Documentation

Definition at line 167 of file dllmain.cpp.

{
       NS_PRECONDITION(g_lockMain != nsnull, "Cant acquire a NULL lock!");
       PR_Lock(g_lockMain);
}

Here is the caller graph for this function:

Definition at line 214 of file dllmain.cpp.

{
       g_lockMain = PR_NewLock();
#ifndef PYXPCOM_USE_PYGILSTATE
       PRStatus status;
       status = PR_NewThreadPrivateIndex( &tlsIndex, NULL );
       NS_WARN_IF_FALSE(status==0, "Could not allocate TLS storage");
       if (NS_FAILED(status)) {
              PR_DestroyLock(g_lockMain);
              return; // PR_FALSE;
       }
#endif // PYXPCOM_USE_PYGILSTATE
       return; // PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 229 of file dllmain.cpp.

{
       PR_DestroyLock(g_lockMain);
#ifndef PYXPCOM_USE_PYGILSTATE
       // I can't locate a way to kill this - 
       // should I pass a dtor to PR_NewThreadPrivateIndex??
       // TlsFree(tlsIndex);
#endif // PYXPCOM_USE_PYGILSTATE
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 178 of file dllmain.cpp.

{
       // Must be thread-safe, although cant have the Python lock!
       CEnterLeaveXPCOMFramework _celf;
       PRInt32 cnt = PR_AtomicIncrement(&g_cLockCount);
       if (cnt==1) { // First call 
              if (!Py_IsInitialized()) {
                     Py_Initialize();
                     // Make sure our Windows framework is all setup.
                     PyXPCOM_Globals_Ensure();
                     // Make sure we have _something_ as sys.argv.
                     if (PySys_GetObject("argv")==NULL) {
                            PyObject *path = PyList_New(0);
                            PyObject *str = PyString_FromString("");
                            PyList_Append(path, str);
                            PySys_SetObject("argv", path);
                            Py_XDECREF(path);
                            Py_XDECREF(str);
                     }

                     // Must force Python to start using thread locks, as
                     // we are free-threaded (maybe, I think, sometimes :-)
                     PyEval_InitThreads();
#ifndef PYXPCOM_USE_PYGILSTATE
                     // Release Python lock, as first thing we do is re-get it.
                     ptsGlobal = PyEval_SaveThread();
#endif
                     // NOTE: We never finalize Python!!
              }
       }
}

Here is the call graph for this function:

Definition at line 209 of file dllmain.cpp.

Here is the call graph for this function:

Definition at line 126 of file dllmain.cpp.

{
       ThreadData *pData = (ThreadData *)PR_GetThreadPrivate(tlsIndex);
       NS_ABORT_IF_FALSE(pData, "Have no thread data for this thread!");
       PyThreadState *thisThreadState = pData->ts;
       PyEval_AcquireThread(thisThreadState);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 135 of file dllmain.cpp.

{
       ThreadData *pData = (ThreadData *)PR_GetThreadPrivate(tlsIndex);
       NS_ABORT_IF_FALSE(pData, "Have no thread data for this thread!");
       PyThreadState *thisThreadState = pData->ts;
       PyEval_ReleaseThread(thisThreadState);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 74 of file dllmain.cpp.

{
       if (PyXPCOM_InterpreterState==NULL) {
              PyThreadState *threadStateSave = PyThreadState_Swap(NULL);
              if (threadStateSave==NULL)
                     Py_FatalError("Can not setup interpreter state, as current state is invalid");

              PyXPCOM_InterpreterState = threadStateSave->interp;
              PyThreadState_Swap(threadStateSave);
       }
}

Here is the caller graph for this function:

Definition at line 86 of file dllmain.cpp.

{
       PyXPCOM_ThreadState_Free();
       PyXPCOM_InterpreterState = NULL; // Eek - should I be freeing something?
}

Here is the call graph for this function:

Definition at line 172 of file dllmain.cpp.

{
       NS_PRECONDITION(g_lockMain != nsnull, "Cant release a NULL lock!");
       PR_Unlock(g_lockMain);
}

Here is the caller graph for this function:

Definition at line 156 of file dllmain.cpp.

{
       ThreadData *pData = (ThreadData *)PR_GetThreadPrivate(tlsIndex);
       PyThreadState *thisThreadState = pData->ts;
       PyThreadState_Clear(thisThreadState);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 103 of file dllmain.cpp.

{
       ThreadData *pData = (ThreadData *)PR_GetThreadPrivate(tlsIndex);
       if (pData==NULL) { /* First request on this thread */
              /* Check we have an interpreter state */
              if (PyXPCOM_InterpreterState==NULL) {
                            Py_FatalError("Can not setup thread state, as have no interpreter state");
              }
              pData = (ThreadData *)nsMemory::Alloc(sizeof(ThreadData));
              if (!pData)
                     Py_FatalError("Out of memory allocating thread state.");
              memset(pData, 0, sizeof(*pData));
              if (NS_FAILED( PR_SetThreadPrivate( tlsIndex, pData ) ) ) {
                     NS_ABORT_IF_FALSE(0, "Could not create thread data for this thread!");
                     Py_FatalError("Could not thread private thread data!");
              }
              pData->ts = PyThreadState_New(PyXPCOM_InterpreterState);
              return PR_TRUE; // Did create a thread state state
       }
       return PR_FALSE; // Thread state was previously created
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 146 of file dllmain.cpp.

{
       ThreadData *pData = (ThreadData *)PR_GetThreadPrivate(tlsIndex);
       if (!pData) return;
       PyThreadState *thisThreadState = pData->ts;
       PyThreadState_Delete(thisThreadState);
       PR_SetThreadPrivate(tlsIndex, NULL);
       nsMemory::Free(pData);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

PRInt32 g_cLockCount = 0 [static]

Definition at line 58 of file dllmain.cpp.

PRLock* g_lockMain = nsnull [static]

Definition at line 59 of file dllmain.cpp.

PyThreadState* ptsGlobal = nsnull [static]

Definition at line 67 of file dllmain.cpp.

PyInterpreterState* PyXPCOM_InterpreterState = nsnull

Definition at line 68 of file dllmain.cpp.

PRUintn tlsIndex = 0

Definition at line 69 of file dllmain.cpp.