Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
w16thred.c File Reference
#include "primpl.h"
#include <sys/timeb.h>
#include <stdio.h>

Go to the source code of this file.

Classes

struct  DispatchTrace

Defines

#define NUM_DISPATCHTRACE_OBJECTS   24

Typedefs

typedef struct DispatchTrace DispatchTrace
typedef struct DispatchTraceDispatchTracePtr

Functions

static void TraceDispatch (PRThread *thread)
void _PR_MD_FINAL_INIT ()
void _MD_INIT_RUNNING_CPU (struct _PRCPU *cpu)
void _PR_MD_YIELD (void)
void _PR_MD_INIT_STACK (PRThreadStack *ts, PRIntn redzone)
PRStatus _PR_MD_INIT_THREAD (PRThread *thread)
PRStatus _PR_MD_WAIT (PRThread *thread, PRIntervalTime ticks)
voidPR_W16GetExceptionContext (void)
void PR_W16SetExceptionContext (void *context)
void _MD_RESTORE_CONTEXT (PRThread *t)

Variables

PRThread_pr_primordialThread
static char * pSource
static char * pTarget
static int cxByteCount
static int bytesMoved
static FILEfile1 = 0
static DispatchTrace dt [NUM_DISPATCHTRACE_OBJECTS] = {0}
static PRUint32 dispatchCount = 0
static int OldPriorityOfPrimaryThread = -1
static int TimeSlicesOnNonPrimaryThread = 0
static PRUint32 threadNumber = 1

Class Documentation

struct DispatchTrace

Definition at line 55 of file w16thred.c.

Collaboration diagram for DispatchTrace:
Class Members
PRInt16 mdThreadNumber
PRThreadPriority priority
PRUint32 state
PRThread * thread
PRInt16 unused

Define Documentation

Definition at line 81 of file w16thred.c.


Typedef Documentation

typedef struct DispatchTrace DispatchTrace
typedef struct DispatchTrace * DispatchTracePtr

Function Documentation

void _MD_INIT_RUNNING_CPU ( struct _PRCPU cpu)

Definition at line 126 of file w16thred.c.

Definition at line 307 of file w16thred.c.

{
    dispatchCount++;
    TraceDispatch( t );
    /* 
    ** This is a good opportunity to make sure that the main
    ** mozilla thread actually gets some time.  If interrupts
    ** are on, then we know it is safe to check if the main
    ** thread is being starved.  If moz has not been scheduled
    ** for a long time, then then temporarily bump the fe priority 
    ** up so that it gets to run at least one. 
    */ 
// #if 0 // lth. condition off for debug.
    if (_pr_primordialThread == t) {
        if (OldPriorityOfPrimaryThread != -1) {
            PR_SetThreadPriority(_pr_primordialThread, OldPriorityOfPrimaryThread);
            OldPriorityOfPrimaryThread = -1;
        }
        TimeSlicesOnNonPrimaryThread = 0;
    } else {
        TimeSlicesOnNonPrimaryThread++;
    }

    if ((TimeSlicesOnNonPrimaryThread >= 20) && (OldPriorityOfPrimaryThread == -1)) {
        OldPriorityOfPrimaryThread = PR_GetThreadPriority(_pr_primordialThread);
        PR_SetThreadPriority(_pr_primordialThread, 31);
        TimeSlicesOnNonPrimaryThread = 0;
    }
// #endif
    /*
    ** Save the Task Stack into the "shadow stack" of the current thread
    */
    cxByteCount  = (int) ((PRUint32) _pr_top_of_task_stack - (PRUint32) &t );
    pSource      = (char *) &t;
    pTarget      = (char *)((PRUint32)_pr_currentThread->stack->md.stackTop 
                            - (PRUint32)cxByteCount );
    _pr_currentThread->stack->md.cxByteCount = cxByteCount;
    
    for( bytesMoved = 0; bytesMoved < cxByteCount; bytesMoved++ )
        *(pTarget + bytesMoved ) = *(pSource + bytesMoved );
    
    /* Mark the new thread as the current thread */
    _pr_currentThread = t;

    /*
    ** Now copy the "shadow stack" of the new thread into the Task Stack
    **
    ** REMEMBER:
    **    After the stack has been copied, ALL local variables in this function
    **    are invalid !!
    */
    cxByteCount  = t->stack->md.cxByteCount;
    pSource      = t->stack->md.stackTop - cxByteCount;
    pTarget      = _pr_top_of_task_stack - cxByteCount;
    
    errno = (_pr_currentThread)->md.errcode;
    
    __asm 
    {
        mov cx, cxByteCount
        mov si, WORD PTR [pSource]
        mov di, WORD PTR [pTarget]
        mov ax, WORD PTR [pTarget + 2]
        mov es, ax
        mov ax, WORD PTR [pSource + 2]
        mov bx, ds
        mov ds, ax
        rep movsb
        mov ds, bx
    }

    /* 
    ** IMPORTANT:
    ** ----------
    ** SS:SP is now invalid :-( This means that all local variables and
    ** function arguments are invalid and NO function calls can be
    ** made !!! We must fix up SS:SP so that function calls can safely
    ** be made...
    */

    __asm {
        mov     ax, WORD PTR [_pr_top_of_task_stack]
        sub     ax, cxByteCount
        mov     sp, ax
    };

    /*
    ** Resume execution of thread: t by restoring the thread's context.
    **
    */
    Throw((_pr_currentThread)->md.context, 1);
} /* --- end MD_RESTORE_CONTEXT() --- */

Here is the call graph for this function:

Definition at line 109 of file w16thred.c.

{
    PRThreadStack *     stack = 0;
    PRInt32             stacksize = 0;
    PRThread *          me = _PR_MD_CURRENT_THREAD();
    
    _PR_ADJUST_STACKSIZE( stacksize );
    stack = _PR_NewStack( stacksize );
    
    me->stack = stack;
    stack->thr = me;
    
    return;
} /* --- end _PR_MD_FINAL_INIT() --- */

Here is the call graph for this function:

Here is the caller graph for this function:

void _PR_MD_INIT_STACK ( PRThreadStack ts,
PRIntn  redzone 
)

Definition at line 147 of file w16thred.c.

{
    ts->md.stackTop = ts->stackTop - sizeof(PRThread);
    ts->md.cxByteCount = 0;
    
    return;
} /* --- end _PR_MD_INIT_STACK() --- */

Here is the caller graph for this function:

Definition at line 160 of file w16thred.c.

{
    if ( thread->flags & _PR_PRIMORDIAL)
    {
        _pr_primordialThread = thread;
        thread->md.threadNumber = 1;
    }
    else
    {
        thread->md.threadNumber = ++threadNumber;
    }

    thread->md.magic = _MD_MAGIC_THREAD;
    strcpy( thread->md.guardBand, "GuardBand" );
    
    return PR_SUCCESS;
}
PRStatus _PR_MD_WAIT ( PRThread thread,
PRIntervalTime  ticks 
)

Definition at line 180 of file w16thred.c.

{
    _MD_SWITCH_CONTEXT( thread );
    
    return( PR_SUCCESS );
}

Definition at line 135 of file w16thred.c.

{
    PR_ASSERT(0);
}

Definition at line 187 of file w16thred.c.

{
    return _MD_CURRENT_THREAD()->md.exceptionContext;
}

Definition at line 193 of file w16thred.c.

{
    _MD_CURRENT_THREAD()->md.exceptionContext = context;
}
static void TraceDispatch ( PRThread thread) [static]

Definition at line 401 of file w16thred.c.

{
    int i;
    
    /*
    ** push all DispatchTrace objects to down one slot.
    ** Note: the last entry is lost; last-1 becomes last, etc.
    */
    for( i = NUM_DISPATCHTRACE_OBJECTS -2; i >= 0; i-- )
    {
        dt[i +1] = dt[i];
    }
    
    /*
    ** Build dt[0] from t
    */
    dt->thread = thread;
    dt->state = thread->state;
    dt->mdThreadNumber = thread->md.threadNumber;
    dt->priority = thread->priority;
    
    return;
} /* --- end TraceDispatch() --- */

Here is the caller graph for this function:


Variable Documentation

Definition at line 68 of file w16thred.c.

int bytesMoved [static]

Definition at line 78 of file w16thred.c.

int cxByteCount [static]

Definition at line 77 of file w16thred.c.

PRUint32 dispatchCount = 0 [static]

Definition at line 83 of file w16thred.c.

Definition at line 82 of file w16thred.c.

FILE* file1 = 0 [static]

Definition at line 79 of file w16thred.c.

Definition at line 85 of file w16thred.c.

char* pSource [static]

Definition at line 75 of file w16thred.c.

char* pTarget [static]

Definition at line 76 of file w16thred.c.

PRUint32 threadNumber = 1 [static]

Definition at line 87 of file w16thred.c.

Definition at line 86 of file w16thred.c.