Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
cvar.c File Reference
#include "nspr.h"
#include "plgetopt.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  CircBuf

Defines

#define DEFAULT_COUNT   1000
#define kQSIZE   1

Functions

static CircBufNewCB (void)
static void DeleteCB (CircBuf *cbp)
static void PutCBData (CircBuf *cbp, void *data)
static voidGetCBData (CircBuf *cbp)
static void PR_CALLBACK CXReader (void *arg)
static void PR_CALLBACK CXWriter (void *arg)
static void CondWaitContextSwitch (PRThreadScope scope1, PRThreadScope scope2)
static void CondWaitContextSwitchUU (void)
static void CondWaitContextSwitchUK (void)
static void CondWaitContextSwitchKK (void)
static void Measure (void(*func)(void), const char *msg)
static PRIntn PR_CALLBACK RealMain (int argc, char **argv)
PRIntn main (PRIntn argc, char *argv[])

Variables

PRMonitormon
PRInt32 count = 0
PRIntn debug_mode
static PRBool failed = PR_FALSE
static int alive

Class Documentation

struct CircBuf

Definition at line 82 of file cvar.c.

Collaboration diagram for CircBuf:
Class Members
PRLock * bufLock
void * data
PRCondVar * notEmpty
PRCondVar * notFull
int numFull
int startIdx

Define Documentation

#define DEFAULT_COUNT   1000

Definition at line 76 of file cvar.c.

#define kQSIZE   1

Definition at line 80 of file cvar.c.


Function Documentation

static void CondWaitContextSwitch ( PRThreadScope  scope1,
PRThreadScope  scope2 
) [static]

Definition at line 207 of file cvar.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void CondWaitContextSwitchKK ( void  ) [static]

Definition at line 253 of file cvar.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void CondWaitContextSwitchUK ( void  ) [static]

Definition at line 248 of file cvar.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void CondWaitContextSwitchUU ( void  ) [static]

Definition at line 243 of file cvar.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK CXReader ( void arg) [static]

Definition at line 173 of file cvar.c.

{
       CircBuf *cbp = (CircBuf *)arg;
    PRInt32 i, n;
    void *data;

    n = count / 2;
    for (i = 0; i < n; i++) {
              data = GetCBData(cbp);
              if ((int)data != i)
              if (debug_mode) printf("data mismatch at for i = %d usec\n", i);
    }
 
    PR_EnterMonitor(mon);
    --alive;
    PR_Notify(mon);
    PR_ExitMonitor(mon);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void PR_CALLBACK CXWriter ( void arg) [static]

Definition at line 192 of file cvar.c.

{
       CircBuf *cbp = (CircBuf *)arg;
    PRInt32 i, n;

    n = count / 2;
    for (i = 0; i < n; i++)
              PutCBData(cbp, (void *)i);

    PR_EnterMonitor(mon);
    --alive;
    PR_Notify(mon);
    PR_ExitMonitor(mon);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void DeleteCB ( CircBuf cbp) [static]

Definition at line 116 of file cvar.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void* GetCBData ( CircBuf cbp) [static]

Definition at line 149 of file cvar.c.

{
       void *data;
       
       PR_Lock(cbp->bufLock);
       /* wait while the buffer is empty */
       while (cbp->numFull == 0)
              PR_WaitCondVar(cbp->notEmpty,PR_INTERVAL_NO_TIMEOUT);
       data = cbp->data[cbp->startIdx];
       cbp->startIdx =(cbp->startIdx + 1) % kQSIZE;
       cbp->numFull -= 1;
       
       /* let a waiting writer know that there is room */
       PR_NotifyCondVar(cbp->notFull);
       PR_Unlock(cbp->bufLock);
       
       return (data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 327 of file cvar.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 void Measure ( void(*)(void func,
const char *  msg 
) [static]

Definition at line 260 of file cvar.c.

{
    PRIntervalTime start, stop;
    double d;

    start = PR_IntervalNow();
    (*func)();
    stop = PR_IntervalNow();

    d = (double)PR_IntervalToMicroseconds(stop - start);

    if (debug_mode) printf("%40s: %6.2f usec\n", msg, d / count);

    if (0 ==  d) failed = PR_TRUE;
}

Here is the caller graph for this function:

static CircBuf* NewCB ( void  ) [static]

Definition at line 96 of file cvar.c.

{
       CircBuf              *cbp;
       
       cbp = PR_NEW(CircBuf);
       if (cbp == NULL)
              return (NULL);
              
       cbp->bufLock  = PR_NewLock();
       cbp->startIdx        = 0;
       cbp->numFull  = 0;
       cbp->notFull  = PR_NewCondVar(cbp->bufLock);
       cbp->notEmpty = PR_NewCondVar(cbp->bufLock);
       
       return (cbp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void PutCBData ( CircBuf cbp,
void data 
) [static]

Definition at line 129 of file cvar.c.

{
       PR_Lock(cbp->bufLock);
       /* wait while the buffer is full */
       while (cbp->numFull == kQSIZE)
              PR_WaitCondVar(cbp->notFull,PR_INTERVAL_NO_TIMEOUT);
       cbp->data[(cbp->startIdx + cbp->numFull) % kQSIZE] = data;
       cbp->numFull += 1;
       
       /* let a waiting reader know that there is data */
       PR_NotifyCondVar(cbp->notEmpty);
       PR_Unlock(cbp->bufLock);

}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 276 of file cvar.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] [-c n]
       */
       PLOptStatus os;
       PLOptState *opt = PL_CreateOptState(argc, argv, "dc:");
       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;
        case 'c':  /* loop count */
            count = atoi(opt->value);
            break;
         default:
            break;
        }
    }
       PL_DestroyOptState(opt);

    if (0 == count) count = DEFAULT_COUNT;

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

    mon = PR_NewMonitor();

    Measure(CondWaitContextSwitchUU, "cond var wait context switch- user/user");
    Measure(CondWaitContextSwitchUK, "cond var wait context switch- user/kernel");
    Measure(CondWaitContextSwitchKK, "cond var wait context switch- kernel/kernel");

       PR_DestroyMonitor(mon);

       if (debug_mode) printf("%s\n", (failed) ? "FAILED" : "PASSED");

       if(failed)
              return 1;
       else
              return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int alive [static]

Definition at line 171 of file cvar.c.

Definition at line 77 of file cvar.c.

PRIntn debug_mode

Definition at line 78 of file cvar.c.

PRBool failed = PR_FALSE [static]

Definition at line 91 of file cvar.c.

Definition at line 75 of file cvar.c.