Back to index

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

Go to the source code of this file.

Classes

struct  param_store

Typedefs

typedef struct param_store PARAMSTORE

Functions

void _PR_MD_ENSURE_TLS (void)
void _PR_MD_EARLY_INIT ()
static void _pr_SetThreadMDHandle (PRThread *thread)
static ULONG _System OS2_FloatExcpHandler (PEXCEPTIONREPORTRECORD p1, PEXCEPTIONREGISTRATIONRECORD p2, PCONTEXTRECORD p3, PVOID pv)
 PR_OS2_SetFloatExcpHandler (EXCEPTIONREGISTRATIONRECORD *excpreg)
 PR_OS2_UnsetFloatExcpHandler (EXCEPTIONREGISTRATIONRECORD *excpreg)
PRStatus _PR_MD_INIT_THREAD (PRThread *thread)
static void ExcpStartFunc (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)
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

_NSPR_TLSpThreadLocalStorage = 0
_PRInterruptTable _pr_interruptTable [] = { { 0 } }
APIRET(* APIENTRY )(TID, ULONG, PCONTEXTRECORD)

Typedef Documentation

typedef struct param_store PARAMSTORE

Function Documentation

Definition at line 392 of file os2thred.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 293 of file os2thred.c.

{
    APIRET rv;

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

    if (thread->md.handle) {
        thread->md.handle = 0;
    }
}
PRStatus _PR_MD_CREATE_THREAD ( PRThread thread,
void(*)(void *)  start,
PRThreadPriority  priority,
PRThreadScope  scope,
PRThreadState  state,
PRUint32  stackSize 
)

Definition at line 216 of file os2thred.c.

{
    PARAMSTORE* params = PR_Malloc(sizeof(PARAMSTORE));
    params->start = start;
    params->thread = thread;
#ifdef XP_OS2_VACPP /* No exception handler for VACPP */
    thread->md.handle = thread->id = (TID) _beginthread(
                    (void(* _Optlink)(void*))start,
                    NULL, 
                    thread->stack->stackSize,
                    thread);
#else
    thread->md.handle = thread->id = (TID) _beginthread(ExcpStartFunc,
                                                        NULL, 
                                                        thread->stack->stackSize,
                                                        params);
#endif
    if(thread->md.handle == -1) {
        return PR_FAILURE;
    }

    /*
     * On OS/2, a thread is created with a thread priority of
     * THREAD_PRIORITY_NORMAL
     */

    if (priority != PR_PRIORITY_NORMAL) {
        _PR_MD_SET_PRIORITY(&(thread->md), priority);
    }

    return PR_SUCCESS;
}

Here is the call graph for this function:

Definition at line 71 of file os2thred.c.

{
   HMODULE hmod;

   if (DosLoadModule(NULL, 0, "DOSCALL1", &hmod) == 0)
       DosQueryProcAddr(hmod, 877, "DOSQUERYTHREADCONTEXT",
                        (PFN *)&QueryThreadContext);

#ifdef XP_OS2_VACPP
   _tzset();
#endif
}

Definition at line 57 of file os2thred.c.

{
   if(!pThreadLocalStorage)
   {
      /* Allocate thread local storage (TLS).  Note, that only 32 bytes can
       * be allocated at a time. 
       */
      int rc = DosAllocThreadLocalMemory(sizeof(_NSPR_TLS) / 4, (PULONG*)&pThreadLocalStorage);
      PR_ASSERT(rc == NO_ERROR);
      memset(pThreadLocalStorage, 0, sizeof(_NSPR_TLS));
   }
}

Here is the call graph for this function:

void _PR_MD_EXIT ( PRIntn  status)

Definition at line 317 of file os2thred.c.

{
    _exit(status);
}

Definition at line 309 of file os2thred.c.

Definition at line 179 of file os2thred.c.

{
   APIRET rv;

   if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
      _pr_SetThreadMDHandle(thread);
   }

   /* Create the blocking IO semaphore */
   rv = DosCreateEventSem(NULL, &(thread->md.blocked_sema), 0, 0);
   return (rv == NO_ERROR) ? PR_SUCCESS : PR_FAILURE;
}

Here is the call graph for this function:

Definition at line 363 of file os2thred.c.

Definition at line 383 of file os2thred.c.

{
    if (_PR_IS_NATIVE_THREAD(thread)) {
        DosResumeThread(thread->md.handle);
    }
}
void _PR_MD_SET_PRIORITY ( _MDThread thread,
PRThreadPriority  newPri 
)

Definition at line 262 of file os2thred.c.

{
    int nativePri = PRTYC_NOCHANGE;
    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:
        case PR_PRIORITY_NORMAL:
            nativePri = PRTYC_REGULAR;
            break;
        case PR_PRIORITY_HIGH:
            nativePri = PRTYC_FOREGROUNDSERVER;
            break;
        case PR_PRIORITY_URGENT:
            nativePri = PRTYC_TIMECRITICAL;
    }
    rv = DosSetPriority(PRTYS_THREAD, nativePri, 0, thread->handle);
    PR_ASSERT(rv == NO_ERROR);
    if (rv != NO_ERROR) {
        PR_LOG(_pr_thread_lm, PR_LOG_MIN,
                ("PR_SetThreadPriority: can't set thread priority\n"));
    }
    return;
}

Definition at line 357 of file os2thred.c.

Definition at line 369 of file os2thred.c.

{
    if (_PR_IS_NATIVE_THREAD(thread)) {
       APIRET rc;

        /* XXXMB - DosSuspendThread() is not a blocking call; how do we
         * know when the thread is *REALLY* suspended?
         */
       rc = DosSuspendThread(thread->md.handle);
       PR_ASSERT(rc == NO_ERROR);
    }
}

Definition at line 255 of file os2thred.c.

{
    /* Isn't there some problem with DosSleep(0) on OS/2? */
    DosSleep(0);
}
static void _pr_SetThreadMDHandle ( PRThread thread) [static]

Definition at line 85 of file os2thred.c.

{
   PTIB ptib;
   PPIB ppib;
   PRUword rc;

   rc = DosGetInfoBlocks(&ptib, &ppib);

   thread->md.handle = ptib->tib_ptib2->tib2_ultid;
}

Here is the caller graph for this function:

static void ExcpStartFunc ( void arg) [static]

Definition at line 201 of file os2thred.c.

{
    EXCEPTIONREGISTRATIONRECORD excpreg;
    PARAMSTORE params, *pParams = arg;

    PR_OS2_SetFloatExcpHandler(&excpreg);

    params = *pParams;
    PR_Free(pParams);
    params.start(params.thread);

    PR_OS2_UnsetFloatExcpHandler(&excpreg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static ULONG _System OS2_FloatExcpHandler ( PEXCEPTIONREPORTRECORD  p1,
PEXCEPTIONREGISTRATIONRECORD  p2,
PCONTEXTRECORD  p3,
PVOID  pv 
) [static]

Definition at line 104 of file os2thred.c.

{
#ifdef DEBUG_pedemonte
    printf("Entering exception handler; ExceptionNum = %x\n", p1->ExceptionNum);
    switch(p1->ExceptionNum) {
        case XCPT_FLOAT_DENORMAL_OPERAND:
            printf("got XCPT_FLOAT_DENORMAL_OPERAND\n");
            break;
        case XCPT_FLOAT_DIVIDE_BY_ZERO:
            printf("got XCPT_FLOAT_DIVIDE_BY_ZERO\n");
            break;
        case XCPT_FLOAT_INEXACT_RESULT:
            printf("got XCPT_FLOAT_INEXACT_RESULT\n");
            break;
        case XCPT_FLOAT_INVALID_OPERATION:
            printf("got XCPT_FLOAT_INVALID_OPERATION\n");
            break;
        case XCPT_FLOAT_OVERFLOW:
            printf("got XCPT_FLOAT_OVERFLOW\n");
            break;
        case XCPT_FLOAT_STACK_CHECK:
            printf("got XCPT_FLOAT_STACK_CHECK\n");
            break;
        case XCPT_FLOAT_UNDERFLOW:
            printf("got XCPT_FLOAT_UNDERFLOW\n");
            break;
    }
#endif

    switch(p1->ExceptionNum) {
        case XCPT_FLOAT_DENORMAL_OPERAND:
        case XCPT_FLOAT_DIVIDE_BY_ZERO:
        case XCPT_FLOAT_INEXACT_RESULT:
        case XCPT_FLOAT_INVALID_OPERATION:
        case XCPT_FLOAT_OVERFLOW:
        case XCPT_FLOAT_STACK_CHECK:
        case XCPT_FLOAT_UNDERFLOW:
        {
            unsigned cw = p3->ctx_env[0];
            if ((cw & MCW_EM) != MCW_EM) {
                /* Mask out all floating point exceptions */
                p3->ctx_env[0] |= MCW_EM;
                /* Following two lines set precision to 53 bit mantissa.  See jsnum.c */
                p3->ctx_env[0] &= ~MCW_PC;
                p3->ctx_env[0] |= PC_53;
                return XCPT_CONTINUE_EXECUTION;
            }
        }
    }
    return XCPT_CONTINUE_SEARCH;
}

Here is the caller graph for this function:

PR_OS2_SetFloatExcpHandler ( EXCEPTIONREGISTRATIONRECORD *  excpreg)

Definition at line 160 of file os2thred.c.

{
    /* setup the exception handler for the thread */
    APIRET rv;
    excpreg->ExceptionHandler = OS2_FloatExcpHandler;
    excpreg->prev_structure = NULL;
    rv = DosSetExceptionHandler(excpreg);
    PR_ASSERT(rv == NO_ERROR);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PR_OS2_UnsetFloatExcpHandler ( EXCEPTIONREGISTRATIONRECORD *  excpreg)

Definition at line 171 of file os2thred.c.

{
    /* unset exception handler */
    APIRET rv = DosUnsetExceptionHandler(excpreg);
    PR_ASSERT(rv == NO_ERROR);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 53 of file os2thred.c.

APIRET(* APIENTRY)(TID, ULONG, PCONTEXTRECORD)

Definition at line 54 of file os2thred.c.

Definition at line 52 of file os2thred.c.