Skip to content

Commit

Permalink
initial checkin of threadsafe list
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgreer%netscape.com committed Sep 19, 2001
1 parent 102170b commit f5a1bf1
Show file tree
Hide file tree
Showing 4 changed files with 469 additions and 3 deletions.
168 changes: 167 additions & 1 deletion security/nss/lib/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define BASE_H

#ifdef DEBUG
static const char BASE_CVS_ID[] = "@(#) $RCSfile: base.h,v $ $Revision: 1.3 $ $Date: 2000/05/17 20:19:23 $ $Name: $";
static const char BASE_CVS_ID[] = "@(#) $RCSfile: base.h,v $ $Revision: 1.4 $ $Date: 2001/09/19 20:20:04 $ $Name: $";
#endif /* DEBUG */

/*
Expand Down Expand Up @@ -767,6 +767,172 @@ nssUTF8_Equal
PRStatus *statusOpt
);

/*
* nssList
*
* The goal is to provide a simple, optionally threadsafe, linked list
* class. Since NSS did not seem to use the circularity of PRCList
* much before, this provides a list that appears to be a linear,
* NULL-terminated list.
*/

/*
* nssList_Create
*
* If threadsafe is true, the list will be locked during modifications
* and traversals.
*/
NSS_EXTERN nssList *
nssList_Create
(
PRBool threadSafe
);

/*
* nssList_Destroy
*/
NSS_EXTERN PRStatus
nssList_Destroy
(
nssList *list
);

/*
* nssList_SetCompareFunction
*
* By default, two list elements will be compared by comparing their
* data pointers. By setting this function, the user can control
* how elements are compared.
*/
NSS_EXTERN void
nssList_SetCompareFunction
(
nssList *list,
nssListCompareFunc compareFunc
);

/*
* nssList_AddElement
*/
NSS_EXTERN PRStatus
nssList_AddElement
(
nssList *list,
void *data
);

/*
* nssList_AddElementUnique
*
* This will use the compare function to see if the element is already
* in the list.
*/
NSS_EXTERN PRStatus
nssList_AddElementUnique
(
nssList *list,
void *data
);

/*
* nssList_RemoveElement
*
* Uses the compare function to locate the element and remove it.
*/
NSS_EXTERN PRStatus
nssList_RemoveElement(nssList *list, void *data);

/*
* nssList_GetElement
*
* Uses the compare function to locate an element. Also serves as
* nssList_Exists.
*/
NSS_EXTERN void *
nssList_GetElement
(
nssList *list,
void *data
);

/*
* nssList_GetNumElements
*/
NSS_EXTERN PRUint32
nssList_GetNumElements
(
nssList *list
);

/*
* nssList_GetArray
*
* Fill rvArray, up to maxElements, with elements in the list. The
* array is NULL-terminated, so its allocated size must be maxElements + 1.
*/
NSS_EXTERN PRStatus
nssList_GetArray
(
nssList *list,
void **rvArray,
PRUint32 maxElements
);

/*
* nssList_CreateIterator
*
* Create an iterator for list traversal.
*/
NSS_EXTERN nssListIterator *
nssList_CreateIterator
(
nssList *list
);

/*
* nssListIterator_Destroy
*/
NSS_EXTERN void
nssListIterator_Destroy
(
nssListIterator *iter
);

/*
* nssListIterator_Start
*
* Begin a list iteration. After this call, if the list is threadSafe,
* the list is *locked*.
*/
NSS_EXTERN void *
nssListIterator_Start
(
nssListIterator *iter
);

/*
* nssListIterator_Next
*
* Continue a list iteration.
*/
NSS_EXTERN void *
nssListIterator_Next
(
nssListIterator *iter
);

/*
* nssListIterator_Finish
*
* Complete a list iteration. This *must* be called in order for the
* lock to be released.
*/
NSS_EXTERN PRStatus
nssListIterator_Finish
(
nssListIterator *iter
);

/*
* nssPointerTracker
*
Expand Down
6 changes: 5 additions & 1 deletion security/nss/lib/base/baset.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define BASET_H

#ifdef DEBUG
static const char BASET_CVS_ID[] = "@(#) $RCSfile: baset.h,v $ $Revision: 1.2 $ $Date: 2001/01/03 19:48:42 $ $Name: $";
static const char BASET_CVS_ID[] = "@(#) $RCSfile: baset.h,v $ $Revision: 1.3 $ $Date: 2001/09/19 20:20:05 $ $Name: $";
#endif /* DEBUG */

/*
Expand Down Expand Up @@ -99,6 +99,10 @@ typedef struct nssArenaMarkStr nssArenaMark;

#endif /* DEBUG */

typedef struct nssListStr nssList;
typedef struct nssListIteratorStr nssListIterator;
typedef PRBool (* nssListCompareFunc)(void *a, void *b);

/*
* nssPointerTracker
*
Expand Down
Loading

0 comments on commit f5a1bf1

Please sign in to comment.