Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
prcountr.h File Reference
#include "prtypes.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define PRCOUNTER_NAME_MAX   31
#define PRCOUNTER_DESC_MAX   255
#define PR_DEFINE_COUNTER(name)   PRCounterHandle name
#define PR_INIT_COUNTER_HANDLE(handle, value)
#define PR_CREATE_COUNTER(handle, qName, rName, description)
#define PR_DESTROY_COUNTER(handle)
#define PR_GET_COUNTER_HANDLE_FROM_NAME(handle, qName, rName)
#define PR_GET_COUNTER_NAME_FROM_HANDLE(handle, qName, rName, description)
#define PR_INCREMENT_COUNTER(handle)
#define PR_DECREMENT_COUNTER(handle)
#define PR_ADD_TO_COUNTER(handle, value)
#define PR_SUBTRACT_FROM_COUNTER(handle, value)
#define PR_GET_COUNTER(counter, handle)   0
#define PR_SET_COUNTER(handle, value)
#define PR_FIND_NEXT_COUNTER_QNAME(next, handle)   NULL
#define PR_FIND_NEXT_COUNTER_RNAME(next, rhandle, qhandle)

Functions

 PR_CreateCounter (const char *qName, const char *rName, const char *description)
 PR_DestroyCounter (PRCounterHandle handle)
 PR_GetCounterHandleFromName (const char *qName, const char *rName)
 PR_GetCounterNameFromHandle (PRCounterHandle handle, const char **qName, const char **rName, const char **description)
 PR_IncrementCounter (PRCounterHandle handle)
 PR_DecrementCounter (PRCounterHandle handle)
 PR_AddToCounter (PRCounterHandle handle, PRUint32 value)
 PR_SubtractFromCounter (PRCounterHandle handle, PRUint32 value)
 PR_GetCounter (PRCounterHandle handle)
 PR_SetCounter (PRCounterHandle handle, PRUint32 value)
 PR_FindNextCounterQname (PRCounterHandle handle)
 PR_FindNextCounterRname (PRCounterHandle rhandle, PRCounterHandle qhandle)

Variables

PR_BEGIN_EXTERN_C typedef voidPRCounterHandle

Define Documentation

Definition at line 365 of file prcountr.h.

#define PR_CREATE_COUNTER (   handle,
  qName,
  rName,
  description 
)

Definition at line 180 of file prcountr.h.

Definition at line 336 of file prcountr.h.

Definition at line 130 of file prcountr.h.

Definition at line 210 of file prcountr.h.

Definition at line 503 of file prcountr.h.

#define PR_FIND_NEXT_COUNTER_RNAME (   next,
  rhandle,
  qhandle 
)

Definition at line 546 of file prcountr.h.

#define PR_GET_COUNTER (   counter,
  handle 
)    0

Definition at line 429 of file prcountr.h.

#define PR_GET_COUNTER_HANDLE_FROM_NAME (   handle,
  qName,
  rName 
)

Definition at line 243 of file prcountr.h.

#define PR_GET_COUNTER_NAME_FROM_HANDLE (   handle,
  qName,
  rName,
  description 
)

Definition at line 276 of file prcountr.h.

Definition at line 307 of file prcountr.h.

Definition at line 144 of file prcountr.h.

Definition at line 460 of file prcountr.h.

Definition at line 399 of file prcountr.h.

Definition at line 119 of file prcountr.h.

Definition at line 118 of file prcountr.h.


Function Documentation

PR_AddToCounter ( PRCounterHandle  handle,
PRUint32  value 
)

Definition at line 388 of file prcountr.c.

{
    PR_Lock(((RName *)handle)->lock);
    ((RName *)handle)->counter += value;
    PR_Unlock(((RName *)handle)->lock);

    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: AddToCounter: %p, %ld", 
        handle, ((RName *)handle)->counter ));

    return;
} /*  end PR_AddToCounter() */
PR_CreateCounter ( const char *  qName,
const char *  rName,
const char *  description 
)

Definition at line 147 of file prcountr.c.

{
    QName   *qnp;
    RName   *rnp;
    PRBool  matchQname = PR_FALSE;

    /* Self initialize, if necessary */
    if ( counterLock == NULL )
        _PR_CounterInitialize();

    /* Validate input arguments */
    PR_ASSERT( strlen(qName) <= PRCOUNTER_NAME_MAX );
    PR_ASSERT( strlen(rName) <= PRCOUNTER_NAME_MAX );
    PR_ASSERT( strlen(description) <= PRCOUNTER_DESC_MAX );

    /* Lock the Facility */
    PR_Lock( counterLock );

    /* Do we already have a matching QName? */
    if (!PR_CLIST_IS_EMPTY( &qNameList ))
    {
        qnp = (QName *) PR_LIST_HEAD( &qNameList );
        do {
            if ( strcmp(qnp->name, qName) == 0)
            {
                matchQname = PR_TRUE;
                break;
            }
            qnp = (QName *)PR_NEXT_LINK( &qnp->link );
        } while( qnp != (QName *)PR_LIST_HEAD( &qNameList ));
    }
    /*
    ** If we did not find a matching QName,
    **    allocate one and initialize it.
    **    link it onto the qNameList.
    **
    */
    if ( matchQname != PR_TRUE )
    {
        qnp = PR_NEWZAP( QName );
        PR_ASSERT( qnp != NULL );
        PR_INIT_CLIST( &qnp->link ); 
        PR_INIT_CLIST( &qnp->rNameList ); 
        strcpy( qnp->name, qName );
        PR_APPEND_LINK( &qnp->link, &qNameList ); 
    }

    /* Do we already have a matching RName? */
    if (!PR_CLIST_IS_EMPTY( &qnp->rNameList ))
    {
        rnp = (RName *) PR_LIST_HEAD( &qnp->rNameList );
        do {
            /*
            ** No duplicate RNames are allowed within a QName
            **
            */
            PR_ASSERT( strcmp(rnp->name, rName));
            rnp = (RName *)PR_NEXT_LINK( &rnp->link );
        } while( rnp != (RName *)PR_LIST_HEAD( &qnp->rNameList ));
    }

    /* Get a new RName structure; initialize its members */
    rnp = PR_NEWZAP( RName );
    PR_ASSERT( rnp != NULL );
    PR_INIT_CLIST( &rnp->link );
    strcpy( rnp->name, rName );
    strcpy( rnp->desc, description );
    rnp->lock = PR_NewLock();
    if ( rnp->lock == NULL )
    {
        PR_ASSERT(0);
    }

    PR_APPEND_LINK( &rnp->link, &qnp->rNameList ); /* add RName to QName's rnList */    
    rnp->qName = qnp;                       /* point the RName to the QName */

    /* Unlock the Facility */
    PR_Unlock( counterLock );
    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Create: QName: %s %p, RName: %s %p\n\t",
        qName, qnp, rName, rnp ));

    return((PRCounterHandle)rnp);
} /*  end PR_CreateCounter() */

Here is the call graph for this function:

Definition at line 369 of file prcountr.c.

{
    PR_Lock(((RName *)handle)->lock);
    ((RName *)handle)->counter--;
    PR_Unlock(((RName *)handle)->lock);

    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Decrement: %p, %ld", 
        handle, ((RName *)handle)->counter ));

    return;
} /*  end PR_DecrementCounter()  */

Definition at line 240 of file prcountr.c.

{
    RName   *rnp = (RName *)handle;
    QName   *qnp = rnp->qName;

    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting: QName: %s, RName: %s", 
        qnp->name, rnp->name));

    /* Lock the Facility */
    PR_Lock( counterLock );

    /*
    ** Remove RName from the list of RNames in QName
    ** and free RName
    */
    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting RName: %s, %p", 
        rnp->name, rnp));
    PR_REMOVE_LINK( &rnp->link );
    PR_Free( rnp->lock );
    PR_DELETE( rnp );

    /*
    ** If this is the last RName within QName
    **   remove QName from the qNameList and free it
    */
    if ( PR_CLIST_IS_EMPTY( &qnp->rNameList ) )
    {
        PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting unused QName: %s, %p", 
            qnp->name, qnp));
        PR_REMOVE_LINK( &qnp->link );
        PR_DELETE( qnp );
    } 

    /* Unlock the Facility */
    PR_Unlock( counterLock );
    return;
} /*  end PR_DestroyCounter() */

Definition at line 458 of file prcountr.c.

{
    QName *qnp = (QName *)handle;

    if ( PR_CLIST_IS_EMPTY( &qNameList ))
            qnp = NULL;
    else if ( qnp == NULL )
        qnp = (QName *)PR_LIST_HEAD( &qNameList );
    else if ( PR_NEXT_LINK( &qnp->link ) ==  &qNameList )
        qnp = NULL;
    else  
        qnp = (QName *)PR_NEXT_LINK( &qnp->link );

    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: FindNextQname: Handle: %p, Returns: %p", 
        handle, qnp ));

    return((PRCounterHandle)qnp);
} /*  end  PR_FindNextCounterQname() */

Here is the caller graph for this function:

Definition at line 484 of file prcountr.c.

{
    RName *rnp = (RName *)rhandle;
    QName *qnp = (QName *)qhandle;


    if ( PR_CLIST_IS_EMPTY( &qnp->rNameList ))
        rnp = NULL;
    else if ( rnp == NULL )
        rnp = (RName *)PR_LIST_HEAD( &qnp->rNameList );
    else if ( PR_NEXT_LINK( &rnp->link ) ==  &qnp->rNameList )
        rnp = NULL;
    else
        rnp = (RName *)PR_NEXT_LINK( &rnp->link );

    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: FindNextRname: Rhandle: %p, QHandle: %p, Returns: %p", 
        rhandle, qhandle, rnp ));

    return((PRCounterHandle)rnp);
} /*  end PR_FindNextCounterRname() */

Here is the caller graph for this function:

Definition at line 427 of file prcountr.c.

{
    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetCounter: %p, %ld", 
        handle, ((RName *)handle)->counter ));

    return(((RName *)handle)->counter);
} /*  end  PR_GetCounter() */
PR_GetCounterHandleFromName ( const char *  qName,
const char *  rName 
)

Definition at line 284 of file prcountr.c.

{
    const char    *qn, *rn, *desc;
    PRCounterHandle     qh, rh = NULL;
    RName   *rnp = NULL;

    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetCounterHandleFromName:\n\t"
        "QName: %s, RName: %s", qName, rName ));

    qh = PR_FindNextCounterQname( NULL );
    while (qh != NULL)
    {
        rh = PR_FindNextCounterRname( NULL, qh );
        while ( rh != NULL )
        {
            PR_GetCounterNameFromHandle( rh, &qn, &rn, &desc );
            if ( (strcmp( qName, qn ) == 0)
                && (strcmp( rName, rn ) == 0 ))
            {
                rnp = (RName *)rh;
                goto foundIt;
            }
            rh = PR_FindNextCounterRname( rh, qh );
        }
        qh = PR_FindNextCounterQname( NULL );
    }

foundIt:
    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetConterHandleFromName: %p", rnp ));
    return(rh);
} /*  end PR_GetCounterHandleFromName() */

Here is the call graph for this function:

PR_GetCounterNameFromHandle ( PRCounterHandle  handle,
const char **  qName,
const char **  rName,
const char **  description 
)

Definition at line 323 of file prcountr.c.

{
    RName   *rnp = (RName *)handle;
    QName   *qnp = rnp->qName;

    *qName = qnp->name;
    *rName = rnp->name;
    *description = rnp->desc;

    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetConterNameFromHandle: "
        "QNp: %p, RNp: %p,\n\tQName: %s, RName: %s, Desc: %s", 
        qnp, rnp, qnp->name, rnp->name, rnp->desc ));

    return;
} /*  end PR_GetCounterNameFromHandle() */

Here is the caller graph for this function:

Definition at line 349 of file prcountr.c.

{
    PR_Lock(((RName *)handle)->lock);
    ((RName *)handle)->counter++;
    PR_Unlock(((RName *)handle)->lock);

    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Increment: %p, %ld", 
        handle, ((RName *)handle)->counter ));

    return;
} /*  end PR_IncrementCounter() */
PR_SetCounter ( PRCounterHandle  handle,
PRUint32  value 
)

Definition at line 441 of file prcountr.c.

{
    ((RName *)handle)->counter = value;

    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: SetCounter: %p, %ld", 
        handle, ((RName *)handle)->counter ));

    return;
} /*  end  PR_SetCounter() */

Definition at line 408 of file prcountr.c.

{
    PR_Lock(((RName *)handle)->lock);
    ((RName *)handle)->counter -= value;
    PR_Unlock(((RName *)handle)->lock);
    
    PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: SubtractFromCounter: %p, %ld", 
        handle, ((RName *)handle)->counter ));

    return;
} /*  end  PR_SubtractFromCounter() */

Variable Documentation

Definition at line 116 of file prcountr.h.