Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
w95thred.c File Reference
#include "primpl.h"
#include <process.h>

Go to the source code of this file.

Functions

void _PR_MD_EARLY_INIT ()
void _PR_MD_CLEANUP_BEFORE_EXIT (void)
PRStatus _PR_MD_INIT_THREAD (PRThread *thread)
static unsigned __stdcall pr_root (void *arg)
PRStatus _PR_MD_CREATE_THREAD (PRThread *thread, void(*start)(void *), PRThreadPriority priority, PRThreadScope scope, PRThreadState state, PRUint32 stackSize)
void _PR_MD_YIELD (void)
void _PR_MD_SET_PRIORITY (_MDThread *thread, PRThreadPriority newPri)
void _PR_MD_CLEAN_THREAD (PRThread *thread)
void _PR_MD_EXIT_THREAD (PRThread *thread)
void _PR_MD_EXIT (PRIntn status)
PRInt32 _PR_MD_SETTHREADAFFINITYMASK (PRThread *thread, PRUint32 mask)
PRInt32 _PR_MD_GETTHREADAFFINITYMASK (PRThread *thread, PRUint32 *mask)
void _PR_MD_SUSPEND_CPU (_PRCPU *cpu)
void _PR_MD_RESUME_CPU (_PRCPU *cpu)
void _PR_MD_SUSPEND_THREAD (PRThread *thread)
void _PR_MD_RESUME_THREAD (PRThread *thread)
PRThread_MD_CURRENT_THREAD (void)

Variables

DWORD _pr_currentThreadIndex
DWORD _pr_lastThreadIndex
DWORD _pr_currentCPUIndex
int _pr_intsOff = 0
_PRInterruptTable _pr_interruptTable [] = { { 0 } }

Function Documentation

Definition at line 281 of file w95thred.c.

{
PRThread *thread;

       thread = _MD_GET_ATTACHED_THREAD();

       if (NULL == thread) {
              thread = _PRI_AttachThread(
            PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
       }
       PR_ASSERT(thread != NULL);
       return thread;
}

Here is the call graph for this function:

Definition at line 196 of file w95thred.c.

{
    BOOL rv;

    if (thread->md.blocked_sema) {
        rv = CloseHandle(thread->md.blocked_sema);
        PR_ASSERT(rv);
        thread->md.blocked_sema = 0;
    }

    if (thread->md.handle) {
        rv = CloseHandle(thread->md.handle);
        PR_ASSERT(rv);
        thread->md.handle = 0;
    }
}

Definition at line 64 of file w95thred.c.

{
    _PR_NT_FreeSids();

    _PR_MD_CleanupSockets();

    WSACleanup();

#ifndef _PR_USE_STATIC_TLS
    TlsFree(_pr_currentThreadIndex);
    TlsFree(_pr_lastThreadIndex);
    TlsFree(_pr_currentCPUIndex);
#endif
}

Here is the call graph for this function:

PRStatus _PR_MD_CREATE_THREAD ( PRThread thread,
void(*)(void *)  start,
PRThreadPriority  priority,
PRThreadScope  scope,
PRThreadState  state,
PRUint32  stackSize 
)

Definition at line 119 of file w95thred.c.

{

    thread->md.start = start;
    thread->md.handle = (HANDLE) _beginthreadex(
                    NULL,
                    thread->stack->stackSize,
                    pr_root,
                    (void *)thread,
                    CREATE_SUSPENDED,
                    &(thread->id));
    if(!thread->md.handle) {
        return PR_FAILURE;
    }

    thread->md.id = thread->id;
    /*
     * On windows, a thread is created with a thread priority of
     * THREAD_PRIORITY_NORMAL.
     */
    if (priority != PR_PRIORITY_NORMAL) {
        _PR_MD_SET_PRIORITY(&(thread->md), priority);
    }

    /* Activate the thread */
    if ( ResumeThread( thread->md.handle ) != -1)
        return PR_SUCCESS;

    return PR_FAILURE;
}

Here is the call graph for this function:

Definition at line 55 of file w95thred.c.

{
#ifndef _PR_USE_STATIC_TLS
    _pr_currentThreadIndex = TlsAlloc();
    _pr_lastThreadIndex = TlsAlloc();
    _pr_currentCPUIndex = TlsAlloc();
#endif
}
void _PR_MD_EXIT ( PRIntn  status)

Definition at line 222 of file w95thred.c.

{
    _exit(status);
}

Definition at line 214 of file w95thred.c.

Definition at line 236 of file w95thred.c.

{
    PRInt32 rv, system_mask;

    rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
    
    return rv?0:-1;
}

Definition at line 80 of file w95thred.c.

{
    if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
        /*
        ** Warning:
        ** --------
        ** NSPR requires a real handle to every thread.
        ** GetCurrentThread() returns a pseudo-handle which
        ** is not suitable for some thread operations (e.g.,
        ** suspending).  Therefore, get a real handle from
        ** the pseudo handle via DuplicateHandle(...)
        */
        DuplicateHandle(
                GetCurrentProcess(),     /* Process of source handle */
                GetCurrentThread(),      /* Pseudo Handle to dup */
                GetCurrentProcess(),     /* Process of handle */
                &(thread->md.handle),    /* resulting handle */
                0L,                      /* access flags */
                FALSE,                   /* Inheritable */
                DUPLICATE_SAME_ACCESS);  /* Options */
    }

    /* Create the blocking IO semaphore */
    thread->md.blocked_sema = CreateSemaphore(NULL, 0, 1, NULL);
    if (thread->md.blocked_sema == NULL)
        return PR_FAILURE;
       else
              return PR_SUCCESS;
}

Here is the call graph for this function:

Definition at line 252 of file w95thred.c.

Definition at line 271 of file w95thred.c.

{
    if (_PR_IS_NATIVE_THREAD(thread)) {
        DWORD previousSuspendCount;
        previousSuspendCount = ResumeThread(thread->md.handle);
        PR_ASSERT(previousSuspendCount == 1);
    }
}
void _PR_MD_SET_PRIORITY ( _MDThread thread,
PRThreadPriority  newPri 
)

Definition at line 163 of file w95thred.c.

{
    int nativePri;
    BOOL rv;

    if (newPri < PR_PRIORITY_FIRST) {
        newPri = PR_PRIORITY_FIRST;
    } else if (newPri > PR_PRIORITY_LAST) {
        newPri = PR_PRIORITY_LAST;
    }
    switch (newPri) {
        case PR_PRIORITY_LOW:
            nativePri = THREAD_PRIORITY_BELOW_NORMAL;
            break;
        case PR_PRIORITY_NORMAL:
            nativePri = THREAD_PRIORITY_NORMAL;
            break;
        case PR_PRIORITY_HIGH:
            nativePri = THREAD_PRIORITY_ABOVE_NORMAL;
            break;
        case PR_PRIORITY_URGENT:
            nativePri = THREAD_PRIORITY_HIGHEST;
    }
    rv = SetThreadPriority(thread->handle, nativePri);
    PR_ASSERT(rv);
    if (!rv) {
       PR_LOG(_pr_thread_lm, PR_LOG_MIN,
                ("PR_SetThreadPriority: can't set thread priority\n"));
    }
    return;
}

Definition at line 227 of file w95thred.c.

{
    int rv;

    rv = SetThreadAffinityMask(thread->md.handle, mask);

    return rv?0:-1;
}

Definition at line 246 of file w95thred.c.

Definition at line 258 of file w95thred.c.

{
    if (_PR_IS_NATIVE_THREAD(thread)) {
        DWORD previousSuspendCount;
        /* XXXMB - SuspendThread() is not a blocking call; how do we
         * know when the thread is *REALLY* suspended?
         */
        previousSuspendCount = SuspendThread(thread->md.handle);
        PR_ASSERT(previousSuspendCount == 0);
    }
}

Definition at line 156 of file w95thred.c.

{
    /* Can NT really yield at all? */
    Sleep(0);
}
static unsigned __stdcall pr_root ( void arg) [static]

Definition at line 111 of file w95thred.c.

{
    PRThread *thread = (PRThread *)arg;
    thread->md.start(thread);
    return 0;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 49 of file w95thred.c.

Definition at line 47 of file w95thred.c.

Definition at line 52 of file w95thred.c.

Definition at line 51 of file w95thred.c.

Definition at line 48 of file w95thred.c.