Back to index

lightning-sunbird  0.9+nobinonly
Functions
join.c File Reference
#include "plgetopt.h"
#include "prttools.h"
#include "nspr.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Functions

static void Test_Result (int result)
static void PR_CALLBACK lowPriority (void *arg)
static void PR_CALLBACK highPriority (void *arg)
static void PR_CALLBACK unjoinable (void *arg)
void runTest (PRThreadScope scope1, PRThreadScope scope2)
void joinWithUnjoinable (void)
static PRIntn PR_CALLBACK RealMain (int argc, char **argv)
PRIntn main (PRIntn argc, char *argv[])

Function Documentation

static void PR_CALLBACK highPriority ( void arg) [static]

Definition at line 110 of file join.c.

{
}

Here is the caller graph for this function:

Definition at line 166 of file join.c.

{
    PRThread *thread;

    /* create the unjoinable thread */
    
    thread = PR_CreateThread(PR_USER_THREAD,
                     unjoinable, 0, 
                     PR_PRIORITY_NORMAL,
                     PR_GLOBAL_THREAD,
                     PR_UNJOINABLE_THREAD,
                     0);
    if (!thread) {
        if (debug_mode) printf("\tcannot create unjoinable thread\n");
        else Test_Result(FAIL);
        return;
    }

    if (PR_JoinThread(thread) == PR_SUCCESS) {
        if (debug_mode) printf("\tsuccessfully joined with unjoinable thread?!\n");
        else Test_Result(FAIL);
        return;
    } else {
        if (debug_mode) printf("\tcannot join with unjoinable thread, as expected\n");
        if (PR_GetError() != PR_INVALID_ARGUMENT_ERROR) {
            if (debug_mode) printf("\tWrong error code\n");
            else Test_Result(FAIL);
            return;
        }
    }
    if (PR_Interrupt(thread) == PR_FAILURE) {
        if (debug_mode) printf("\tcannot interrupt unjoinable thread\n");
        else Test_Result(FAIL);
        return;
    } else {
        if (debug_mode) printf("\tinterrupted unjoinable thread\n");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK lowPriority ( void arg) [static]

Definition at line 106 of file join.c.

{
}

Here is the caller graph for this function:

PRIntn main ( PRIntn  argc,
char *  argv[] 
)

Definition at line 257 of file join.c.

{
    PRIntn rv;
    
    PR_STDIO_INIT();
    rv = PR_Initialize(RealMain, argc, argv, 0);
    return rv;
}  /* main */

Here is the call graph for this function:

static PRIntn PR_CALLBACK RealMain ( int  argc,
char **  argv 
) [static]

Definition at line 205 of file join.c.

{
    /* The command line argument: -d is used to determine if the test is being run
    in debug mode. The regress tool requires only one line output:PASS or FAIL.
    All of the printfs associated with this test has been handled with a if (debug_mode)
    test.
    Usage: test_name -d
    */
    
    PLOptStatus os;
    PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
        if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'd':  /* debug mode */
            debug_mode = 1;
            break;
         default:
            break;
        }
    }
    PL_DestroyOptState(opt);

#ifdef XP_MAC
    SetupMacPrintfLog("join.log");
    debug_mode = 1;
#endif

    
    
 /* main test */
    printf("User-User test\n");
    runTest(PR_LOCAL_THREAD, PR_LOCAL_THREAD);
    printf("User-Kernel test\n");
    runTest(PR_LOCAL_THREAD, PR_GLOBAL_THREAD);
    printf("Kernel-User test\n");
    runTest(PR_GLOBAL_THREAD, PR_LOCAL_THREAD);
    printf("Kernel-Kernel test\n");
    runTest(PR_GLOBAL_THREAD, PR_GLOBAL_THREAD);
    printf("Join with unjoinable thread\n");
    joinWithUnjoinable();

    printf("PASSED\n");

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void runTest ( PRThreadScope  scope1,
PRThreadScope  scope2 
)

Definition at line 119 of file join.c.

{
    PRThread *low,*high;

    /* create the low and high priority threads */
    
    low = PR_CreateThread(PR_USER_THREAD,
                     lowPriority, 0, 
                     PR_PRIORITY_LOW,
                     scope1,
                     PR_JOINABLE_THREAD,
                     0);
    if (!low) {
        if (debug_mode) printf("\tcannot create low priority thread\n");
        else Test_Result(FAIL);
        return;
    }

    high = PR_CreateThread(PR_USER_THREAD,
                     highPriority, 0, 
                     PR_PRIORITY_HIGH,
                     scope2,
                     PR_JOINABLE_THREAD,
                     0);
    if (!high) {
        if (debug_mode) printf("\tcannot create high priority thread\n");
        else Test_Result(FAIL);
        return;
    }

    /* Do the joining for both threads */
    if (PR_JoinThread(low) == PR_FAILURE) {
        if (debug_mode) printf("\tcannot join low priority thread\n");
        else Test_Result (FAIL);
        return;
    } else {
        if (debug_mode) printf("\tjoined low priority thread\n");
    }
    if (PR_JoinThread(high) == PR_FAILURE) {
        if (debug_mode) printf("\tcannot join high priority thread\n");
        else Test_Result(FAIL);
        return;
    } else {
        if (debug_mode) printf("\tjoined high priority thread\n");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void Test_Result ( int  result) [static]

Definition at line 89 of file join.c.

{
    if (result == PASS)
        printf ("PASS\n");
    else
        printf ("FAIL\n");
    exit (1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK unjoinable ( void arg) [static]

Definition at line 114 of file join.c.

Here is the call graph for this function:

Here is the caller graph for this function: