Back to index

lightning-sunbird  0.9+nobinonly
Classes | Typedefs | Functions | Variables
xnotify.c File Reference
#include "plerror.h"
#include "plgetopt.h"
#include "prinit.h"
#include "prprf.h"
#include "prio.h"
#include "prcvar.h"
#include "prmon.h"
#include "prcmon.h"
#include "prlock.h"
#include "prerror.h"
#include "prinrval.h"
#include "prthread.h"

Go to the source code of this file.

Classes

struct  CMonShared
struct  MonShared
struct  LockShared

Typedefs

typedef struct CMonShared CMonShared
typedef struct MonShared MonShared
typedef struct LockShared LockShared

Functions

static void LogNow (const char *msg, PRStatus rv)
static void Help (void)
static void PR_CALLBACK T2CMon (void *arg)
static void PR_CALLBACK T3CMon (void *arg)
static void T1CMon (void)
static void PR_CALLBACK T2Mon (void *arg)
static void PR_CALLBACK T3Mon (void *arg)
static void T1Mon (void)
static void PR_CALLBACK T2Lock (void *arg)
static void PR_CALLBACK T3Lock (void *arg)
static void T1Lock (void)
static PRIntn PR_CALLBACK RealMain (PRIntn argc, char **argv)
PRIntn main (PRIntn argc, char **argv)

Variables

static PRLockml = NULL
static PRIntervalTime base
static PRFileDescerr = NULL
static CMonShared sharedCM
static MonShared sharedM
static LockShared sharedL

Class Documentation

struct CMonShared

Definition at line 57 of file xnotify.c.

Class Members
PRInt32 o1
PRInt32 o2
struct MonShared

Definition at line 62 of file xnotify.c.

Collaboration diagram for MonShared:
Class Members
PRMonitor * o1
PRMonitor * o2
struct LockShared

Definition at line 67 of file xnotify.c.

Collaboration diagram for LockShared:
Class Members
PRCondVar * cv1
PRCondVar * cv2
PRLock * o1
PRLock * o2

Typedef Documentation

typedef struct CMonShared CMonShared
typedef struct LockShared LockShared
typedef struct MonShared MonShared

Function Documentation

static void Help ( void  ) [static]

Definition at line 83 of file xnotify.c.

{
    PR_fprintf(err, "Usage: [-[d][l][m][c]] [-h]\n");
    PR_fprintf(err, "\t-d   debug mode                  (default: FALSE)\n");
    PR_fprintf(err, "\t-l   test with locks             (default: FALSE)\n");
    PR_fprintf(err, "\t-m   tests with monitors         (default: FALSE)\n");
    PR_fprintf(err, "\t-c   tests with cmonitors        (default: FALSE)\n");
    PR_fprintf(err, "\t-h   help\n");
}  /* Help */
static void LogNow ( const char *  msg,
PRStatus  rv 
) [static]

Definition at line 73 of file xnotify.c.

{
    PRIntervalTime now = PR_IntervalNow();
    PR_Lock(ml);
    PR_fprintf(err, "%6ld: %s", (now - base), msg);
    if (PR_FAILURE == rv) PL_FPrintError(err, " ");
    else PR_fprintf(err, "\n");
    PR_Unlock(ml);
}  /* LogNow */

Here is the caller graph for this function:

PRIntn main ( PRIntn  argc,
char **  argv 
)

Definition at line 381 of file xnotify.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 ( PRIntn  argc,
char **  argv 
) [static]

Definition at line 337 of file xnotify.c.

{
       PLOptStatus os;
       PLOptState *opt = PL_CreateOptState(argc, argv, "dhlmc");
       PRBool locks = PR_FALSE, monitors = PR_FALSE, cmonitors = PR_FALSE;

    err = PR_GetSpecialFD(PR_StandardError);

       while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
              if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'd':  /* debug mode (noop) */
            break;
        case 'l':  /* locks */
                     locks = PR_TRUE;
            break;
        case 'm':  /* monitors */
                     monitors = PR_TRUE;
            break;
        case 'c':  /* cached monitors */
                     cmonitors = PR_TRUE;
            break;
        case 'h':  /* needs guidance */
         default:
            Help();
            return 2;
        }
    }
       PL_DestroyOptState(opt);

    ml = PR_NewLock();
    if (locks) T1Lock();
    if (monitors) T1Mon();
    if (cmonitors) T1CMon();

    PR_DestroyLock(ml);

    PR_fprintf(err, "Done!\n");    
    return 0;
}  /* main */

Here is the call graph for this function:

Here is the caller graph for this function:

static void T1CMon ( void  ) [static]

Definition at line 129 of file xnotify.c.

{
    PRStatus rv;
    PRThread *t2, *t3;

    PR_fprintf(err, "\n**********************************\n");
    PR_fprintf(err, "         CACHED MONITORS\n");
    PR_fprintf(err, "**********************************\n");

    base =  PR_IntervalNow();

    PR_CEnterMonitor(&sharedCM.o1);
    LogNow("T1 waiting 3 seconds on o1", PR_SUCCESS);
    rv = PR_CWait(&sharedCM.o1, PR_SecondsToInterval(3));
    if (PR_SUCCESS == rv) LogNow("T1 resuming on o1", rv);
    else LogNow("T1 wait on o1 failed", rv);
    PR_CExitMonitor(&sharedCM.o1);

    LogNow("T1 creating T2", PR_SUCCESS);
    t2 = PR_CreateThread(
        PR_USER_THREAD, T2CMon, &sharedCM, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);

    LogNow("T1 creating T3", PR_SUCCESS);
    t3 = PR_CreateThread(
        PR_USER_THREAD, T3CMon, &sharedCM, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);

    PR_CEnterMonitor(&sharedCM.o2);
    LogNow("T1 waiting forever on o2", PR_SUCCESS);
    rv = PR_CWait(&sharedCM.o2, PR_INTERVAL_NO_TIMEOUT);
    if (PR_SUCCESS == rv) LogNow("T1 resuming on o2", rv);
    else LogNow("T1 wait on o2 failed", rv);
    PR_CExitMonitor(&sharedCM.o2);

    (void)PR_JoinThread(t2);
    (void)PR_JoinThread(t3);

}  /* T1CMon */

Here is the call graph for this function:

Here is the caller graph for this function:

static void T1Lock ( void  ) [static]

Definition at line 289 of file xnotify.c.

{
    PRStatus rv;
    PRThread *t2, *t3;
    sharedL.o1 = PR_NewLock();
    sharedL.o2 = PR_NewLock();
    sharedL.cv1 = PR_NewCondVar(sharedL.o1);
    sharedL.cv2 = PR_NewCondVar(sharedL.o2);

    PR_fprintf(err, "\n**********************************\n");
    PR_fprintf(err, "             LOCKS\n");
    PR_fprintf(err, "**********************************\n");

    base =  PR_IntervalNow();

    PR_Lock(sharedL.o1);
    LogNow("T1 waiting 3 seconds on o1", PR_SUCCESS);
    rv = PR_WaitCondVar(sharedL.cv1, PR_SecondsToInterval(3));
    if (PR_SUCCESS == rv) LogNow("T1 resuming on o1", rv);
    else LogNow("T1 wait on o1 failed", rv);
    PR_Unlock(sharedL.o1);

    LogNow("T1 creating T2", PR_SUCCESS);
    t2 = PR_CreateThread(
        PR_USER_THREAD, T2Lock, &sharedL, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);

    LogNow("T1 creating T3", PR_SUCCESS);
    t3 = PR_CreateThread(
        PR_USER_THREAD, T3Lock, &sharedL, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);

    PR_Lock(sharedL.o2);
    LogNow("T1 waiting forever on o2", PR_SUCCESS);
    rv = PR_WaitCondVar(sharedL.cv2, PR_INTERVAL_NO_TIMEOUT);
    if (PR_SUCCESS == rv) LogNow("T1 resuming on o2", rv);
    else LogNow("T1 wait on o2 failed", rv);
    PR_Unlock(sharedL.o2);

    (void)PR_JoinThread(t2);
    (void)PR_JoinThread(t3);

    PR_DestroyLock(sharedL.o1);
    PR_DestroyLock(sharedL.o2);
    PR_DestroyCondVar(sharedL.cv1);
    PR_DestroyCondVar(sharedL.cv2);
}  /* T1Lock */

Here is the call graph for this function:

Here is the caller graph for this function:

static void T1Mon ( void  ) [static]

Definition at line 204 of file xnotify.c.

{
    PRStatus rv;
    PRThread *t2, *t3;

    PR_fprintf(err, "\n**********************************\n");
    PR_fprintf(err, "            MONITORS\n");
    PR_fprintf(err, "**********************************\n");

    sharedM.o1 = PR_NewMonitor();
    sharedM.o2 = PR_NewMonitor();

    base =  PR_IntervalNow();

    PR_EnterMonitor(sharedM.o1);
    LogNow("T1 waiting 3 seconds on o1", PR_SUCCESS);
    rv = PR_Wait(sharedM.o1, PR_SecondsToInterval(3));
    if (PR_SUCCESS == rv) LogNow("T1 resuming on o1", rv);
    else LogNow("T1 wait on o1 failed", rv);
    PR_ExitMonitor(sharedM.o1);

    LogNow("T1 creating T2", PR_SUCCESS);
    t2 = PR_CreateThread(
        PR_USER_THREAD, T2Mon, &sharedM, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);

    LogNow("T1 creating T3", PR_SUCCESS);
    t3 = PR_CreateThread(
        PR_USER_THREAD, T3Mon, &sharedM, PR_PRIORITY_NORMAL,
        PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);

    PR_EnterMonitor(sharedM.o2);
    LogNow("T1 waiting forever on o2", PR_SUCCESS);
    rv = PR_Wait(sharedM.o2, PR_INTERVAL_NO_TIMEOUT);
    if (PR_SUCCESS == rv) LogNow("T1 resuming on o2", rv);
    else LogNow("T1 wait on o2 failed", rv);
    PR_ExitMonitor(sharedM.o2);

    (void)PR_JoinThread(t2);
    (void)PR_JoinThread(t3);

    PR_DestroyMonitor(sharedM.o1);
    PR_DestroyMonitor(sharedM.o2);

}  /* T1Mon */

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK T2CMon ( void arg) [static]

Definition at line 93 of file xnotify.c.

{
    PRStatus rv;
    CMonShared *shared = (CMonShared*)arg;

    PR_CEnterMonitor(&shared->o1);
    LogNow("T2 waiting 5 seconds on o1", PR_SUCCESS);
    rv = PR_CWait(&shared->o1, PR_SecondsToInterval(5));
    if (PR_SUCCESS == rv) LogNow("T2 resuming on o1", rv);
    else LogNow("T2 wait failed on o1", rv);

    rv = PR_CNotify(&shared->o1);
    if (PR_SUCCESS == rv) LogNow("T2 notified o1", rv);
    else LogNow("T2 notify on o1 failed", rv);

    PR_CExitMonitor(&shared->o1);
}  /* T2CMon */

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK T2Lock ( void arg) [static]

Definition at line 250 of file xnotify.c.

{
    PRStatus rv;
    LockShared *shared = (LockShared*)arg;

    PR_Lock(shared->o1);
    LogNow("T2 waiting 5 seconds on o1", PR_SUCCESS);
    rv = PR_WaitCondVar(shared->cv1, PR_SecondsToInterval(5));
    if (PR_SUCCESS == rv) LogNow("T2 resuming on o1", rv);
    else LogNow("T2 wait failed on o1", rv);

    rv = PR_NotifyCondVar(shared->cv1);
    if (PR_SUCCESS == rv) LogNow("T2 notified o1", rv);
    else LogNow("T2 notify on o1 failed", rv);

    PR_Unlock(shared->o1);
}  /* T2Lock */

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK T2Mon ( void arg) [static]

Definition at line 169 of file xnotify.c.

{
    PRStatus rv;
    MonShared *shared = (MonShared*)arg;

    PR_EnterMonitor(shared->o1);
    LogNow("T2 waiting 5 seconds on o1", PR_SUCCESS);
    rv = PR_Wait(shared->o1, PR_SecondsToInterval(5));
    if (PR_SUCCESS == rv) LogNow("T2 resuming on o1", rv);
    else LogNow("T2 wait failed on o1", rv);

    rv = PR_Notify(shared->o1);
    if (PR_SUCCESS == rv) LogNow("T2 notified o1", rv);
    else LogNow("T2 notify on o1 failed", rv);

    PR_ExitMonitor(shared->o1);
}  /* T2Mon */

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK T3CMon ( void arg) [static]

Definition at line 111 of file xnotify.c.

{
    PRStatus rv;
    CMonShared *shared = (CMonShared*)arg;

    PR_CEnterMonitor(&shared->o2);
    LogNow("T3 waiting 5 seconds on o2", PR_SUCCESS);
    rv = PR_CWait(&shared->o2, PR_SecondsToInterval(5));
    if (PR_SUCCESS == rv) LogNow("T3 resuming on o2", rv);
    else LogNow("T3 wait failed on o2", rv);
    rv = PR_CNotify(&shared->o2);
    LogNow("T3 notify on o2", rv);
    PR_CExitMonitor(&shared->o2);

}  /* T3CMon */

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK T3Lock ( void arg) [static]

Definition at line 268 of file xnotify.c.

{
    PRStatus rv;
    LockShared *shared = (LockShared*)arg;

    PR_Lock(shared->o2);
    LogNow("T3 waiting 5 seconds on o2", PR_SUCCESS);
    rv = PR_WaitCondVar(shared->cv2, PR_SecondsToInterval(5));
    if (PR_SUCCESS == rv) LogNow("T3 resuming on o2", rv);
    else LogNow("T3 wait failed on o2", rv);
    rv = PR_NotifyCondVar(shared->cv2);
    LogNow("T3 notify on o2", rv);
    PR_Unlock(shared->o2);

}  /* T3Lock */

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK T3Mon ( void arg) [static]

Definition at line 187 of file xnotify.c.

{
    PRStatus rv;
    MonShared *shared = (MonShared*)arg;

    PR_EnterMonitor(shared->o2);
    LogNow("T3 waiting 5 seconds on o2", PR_SUCCESS);
    rv = PR_Wait(shared->o2, PR_SecondsToInterval(5));
    if (PR_SUCCESS == rv) LogNow("T3 resuming on o2", rv);
    else LogNow("T3 wait failed on o2", rv);
    rv = PR_Notify(shared->o2);
    LogNow("T3 notify on o2", rv);
    PR_ExitMonitor(shared->o2);

}  /* T3Mon */

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

PRIntervalTime base [static]

Definition at line 54 of file xnotify.c.

PRFileDesc* err = NULL [static]

Definition at line 55 of file xnotify.c.

PRLock* ml = NULL [static]

Definition at line 53 of file xnotify.c.

CMonShared sharedCM [static]

Definition at line 127 of file xnotify.c.

LockShared sharedL [static]

Definition at line 287 of file xnotify.c.

MonShared sharedM [static]

Definition at line 203 of file xnotify.c.