summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/src/misc/prcountr.c
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/src/misc/prcountr.c')
-rw-r--r--nsprpub/pr/src/misc/prcountr.c211
1 files changed, 110 insertions, 101 deletions
diff --git a/nsprpub/pr/src/misc/prcountr.c b/nsprpub/pr/src/misc/prcountr.c
index 0f126ad08..29d7d4ccb 100644
--- a/nsprpub/pr/src/misc/prcountr.c
+++ b/nsprpub/pr/src/misc/prcountr.c
@@ -10,16 +10,16 @@
**
** Design Notes:
**
-** The Counter Facility (CF) has a single anchor: qNameList.
+** The Counter Facility (CF) has a single anchor: qNameList.
** The anchor is a PRCList. qNameList is a list of links in QName
** structures. From qNameList any QName structure and its
-** associated RName structure can be located.
-**
+** associated RName structure can be located.
+**
** For each QName, a list of RName structures is anchored at
** rnLink in the QName structure.
-**
+**
** The counter itself is embedded in the RName structure.
-**
+**
** For manipulating the counter database, single lock is used to
** protect the entire list: counterLock.
**
@@ -29,7 +29,7 @@
** "overloaded" for traversing the QName structures; only the
** function PR_FindNextQnameHandle() uses this overloading.
**
-**
+**
** ToDo (lth): decide on how to lock or atomically update
** individual counters. Candidates are: the global lock; a lock
** per RName structure; Atomic operations (Note that there are
@@ -64,9 +64,9 @@ typedef struct RName
PRCList link;
QName *qName;
PRLock *lock;
- volatile PRUint32 counter;
- char name[PRCOUNTER_NAME_MAX+1];
- char desc[PRCOUNTER_DESC_MAX+1];
+ volatile PRUint32 counter;
+ char name[PRCOUNTER_NAME_MAX+1];
+ char desc[PRCOUNTER_DESC_MAX+1];
} RName;
@@ -87,7 +87,7 @@ static void _PR_CounterInitialize( void )
** This function should be called only once
*/
PR_ASSERT( counterLock == NULL );
-
+
counterLock = PR_NewLock();
PR_INIT_CLIST( &qNameList );
lm = PR_NewLogModule("counters");
@@ -111,20 +111,21 @@ static void _PR_CounterInitialize( void )
** Unlock
**
*/
-PR_IMPLEMENT(PRCounterHandle)
- PR_CreateCounter(
- const char *qName,
- const char *rName,
- const char *description
-)
+PR_IMPLEMENT(PRCounterHandle)
+PR_CreateCounter(
+ const char *qName,
+ const char *rName,
+ const char *description
+)
{
QName *qnp;
RName *rnp;
PRBool matchQname = PR_FALSE;
/* Self initialize, if necessary */
- if ( counterLock == NULL )
+ if ( counterLock == NULL ) {
_PR_CounterInitialize();
+ }
/* Validate input arguments */
PR_ASSERT( strlen(qName) <= PRCOUNTER_NAME_MAX );
@@ -157,10 +158,10 @@ PR_IMPLEMENT(PRCounterHandle)
{
qnp = PR_NEWZAP( QName );
PR_ASSERT( qnp != NULL );
- PR_INIT_CLIST( &qnp->link );
- PR_INIT_CLIST( &qnp->rNameList );
+ PR_INIT_CLIST( &qnp->link );
+ PR_INIT_CLIST( &qnp->rNameList );
strcpy( qnp->name, qName );
- PR_APPEND_LINK( &qnp->link, &qNameList );
+ PR_APPEND_LINK( &qnp->link, &qNameList );
}
/* Do we already have a matching RName? */
@@ -189,31 +190,31 @@ PR_IMPLEMENT(PRCounterHandle)
PR_ASSERT(0);
}
- PR_APPEND_LINK( &rnp->link, &qnp->rNameList ); /* add RName to QName's rnList */
+ 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 ));
+ qName, qnp, rName, rnp ));
return((PRCounterHandle)rnp);
} /* end PR_CreateCounter() */
-
+
/*
**
*/
-PR_IMPLEMENT(void)
- PR_DestroyCounter(
- PRCounterHandle handle
+PR_IMPLEMENT(void)
+PR_DestroyCounter(
+ PRCounterHandle handle
)
{
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));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting: QName: %s, RName: %s",
+ qnp->name, rnp->name));
/* Lock the Facility */
PR_Lock( counterLock );
@@ -222,8 +223,8 @@ PR_IMPLEMENT(void)
** 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_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 );
@@ -234,11 +235,11 @@ PR_IMPLEMENT(void)
*/
if ( PR_CLIST_IS_EMPTY( &qnp->rNameList ) )
{
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting unused QName: %s, %p",
- qnp->name, qnp));
+ 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 );
@@ -248,10 +249,10 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(PRCounterHandle)
- PR_GetCounterHandleFromName(
- const char *qName,
- const char *rName
+PR_IMPLEMENT(PRCounterHandle)
+PR_GetCounterHandleFromName(
+ const char *qName,
+ const char *rName
)
{
const char *qn, *rn, *desc;
@@ -259,7 +260,7 @@ PR_IMPLEMENT(PRCounterHandle)
RName *rnp = NULL;
PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetCounterHandleFromName:\n\t"
- "QName: %s, RName: %s", qName, rName ));
+ "QName: %s, RName: %s", qName, rName ));
qh = PR_FindNextCounterQname( NULL );
while (qh != NULL)
@@ -269,7 +270,7 @@ PR_IMPLEMENT(PRCounterHandle)
{
PR_GetCounterNameFromHandle( rh, &qn, &rn, &desc );
if ( (strcmp( qName, qn ) == 0)
- && (strcmp( rName, rn ) == 0 ))
+ && (strcmp( rName, rn ) == 0 ))
{
rnp = (RName *)rh;
goto foundIt;
@@ -287,12 +288,12 @@ foundIt:
/*
**
*/
-PR_IMPLEMENT(void)
- PR_GetCounterNameFromHandle(
- PRCounterHandle handle,
- const char **qName,
- const char **rName,
- const char **description
+PR_IMPLEMENT(void)
+PR_GetCounterNameFromHandle(
+ PRCounterHandle handle,
+ const char **qName,
+ const char **rName,
+ const char **description
)
{
RName *rnp = (RName *)handle;
@@ -303,8 +304,8 @@ PR_IMPLEMENT(void)
*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 ));
+ "QNp: %p, RNp: %p,\n\tQName: %s, RName: %s, Desc: %s",
+ qnp, rnp, qnp->name, rnp->name, rnp->desc ));
return;
} /* end PR_GetCounterNameFromHandle() */
@@ -313,17 +314,17 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_IncrementCounter(
- PRCounterHandle handle
+PR_IMPLEMENT(void)
+PR_IncrementCounter(
+ PRCounterHandle handle
)
{
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 ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Increment: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_IncrementCounter() */
@@ -333,17 +334,17 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_DecrementCounter(
- PRCounterHandle handle
+PR_IMPLEMENT(void)
+PR_DecrementCounter(
+ PRCounterHandle handle
)
{
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 ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Decrement: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_DecrementCounter() */
@@ -352,18 +353,18 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_AddToCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_IMPLEMENT(void)
+PR_AddToCounter(
+ PRCounterHandle handle,
+ PRUint32 value
)
{
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 ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: AddToCounter: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_AddToCounter() */
@@ -372,18 +373,18 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_SubtractFromCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_IMPLEMENT(void)
+PR_SubtractFromCounter(
+ PRCounterHandle handle,
+ PRUint32 value
)
{
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 ));
+
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: SubtractFromCounter: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_SubtractFromCounter() */
@@ -391,13 +392,13 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(PRUint32)
- PR_GetCounter(
- PRCounterHandle handle
+PR_IMPLEMENT(PRUint32)
+PR_GetCounter(
+ PRCounterHandle handle
)
{
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetCounter: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetCounter: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return(((RName *)handle)->counter);
} /* end PR_GetCounter() */
@@ -405,16 +406,16 @@ PR_IMPLEMENT(PRUint32)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_SetCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_IMPLEMENT(void)
+PR_SetCounter(
+ PRCounterHandle handle,
+ PRUint32 value
)
{
((RName *)handle)->counter = value;
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: SetCounter: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: SetCounter: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_SetCounter() */
@@ -422,24 +423,28 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(PRCounterHandle)
- PR_FindNextCounterQname(
- PRCounterHandle handle
+PR_IMPLEMENT(PRCounterHandle)
+PR_FindNextCounterQname(
+ PRCounterHandle handle
)
{
QName *qnp = (QName *)handle;
- if ( PR_CLIST_IS_EMPTY( &qNameList ))
- qnp = NULL;
- else if ( qnp == NULL )
+ 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 )
+ }
+ else if ( PR_NEXT_LINK( &qnp->link ) == &qNameList ) {
qnp = NULL;
- else
+ }
+ else {
qnp = (QName *)PR_NEXT_LINK( &qnp->link );
+ }
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: FindNextQname: Handle: %p, Returns: %p",
- handle, qnp ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: FindNextQname: Handle: %p, Returns: %p",
+ handle, qnp ));
return((PRCounterHandle)qnp);
} /* end PR_FindNextCounterQname() */
@@ -448,27 +453,31 @@ PR_IMPLEMENT(PRCounterHandle)
/*
**
*/
-PR_IMPLEMENT(PRCounterHandle)
- PR_FindNextCounterRname(
- PRCounterHandle rhandle,
- PRCounterHandle qhandle
+PR_IMPLEMENT(PRCounterHandle)
+PR_FindNextCounterRname(
+ PRCounterHandle rhandle,
+ PRCounterHandle qhandle
)
{
RName *rnp = (RName *)rhandle;
QName *qnp = (QName *)qhandle;
- if ( PR_CLIST_IS_EMPTY( &qnp->rNameList ))
+ if ( PR_CLIST_IS_EMPTY( &qnp->rNameList )) {
rnp = NULL;
- else if ( rnp == NULL )
+ }
+ else if ( rnp == NULL ) {
rnp = (RName *)PR_LIST_HEAD( &qnp->rNameList );
- else if ( PR_NEXT_LINK( &rnp->link ) == &qnp->rNameList )
+ }
+ else if ( PR_NEXT_LINK( &rnp->link ) == &qnp->rNameList ) {
rnp = NULL;
- else
+ }
+ 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 ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: FindNextRname: Rhandle: %p, QHandle: %p, Returns: %p",
+ rhandle, qhandle, rnp ));
return((PRCounterHandle)rnp);
} /* end PR_FindNextCounterRname() */