Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
hash.c File Reference
#include "ck.h"

Go to the source code of this file.

Classes

struct  nssCKFWHashStr
struct  arg_str

Functions

static PLHashNumber nss_ckfw_identity_hash (const void *key)
NSS_IMPLEMENT nssCKFWHash * nssCKFWHash_Create (NSSCKFWInstance *fwInstance, NSSArena *arena, CK_RV *pError)
NSS_IMPLEMENT void nssCKFWHash_Destroy (nssCKFWHash *hash)
NSS_IMPLEMENT CK_RV nssCKFWHash_Add (nssCKFWHash *hash, const void *key, const void *value)
NSS_IMPLEMENT void nssCKFWHash_Remove (nssCKFWHash *hash, const void *it)
NSS_IMPLEMENT CK_ULONG nssCKFWHash_Count (nssCKFWHash *hash)
NSS_IMPLEMENT CK_BBOOL nssCKFWHash_Exists (nssCKFWHash *hash, const void *it)
NSS_IMPLEMENT voidnssCKFWHash_Lookup (nssCKFWHash *hash, const void *it)
static PRIntn nss_ckfwhash_enumerator (PLHashEntry *he, PRIntn index, void *arg)
NSS_IMPLEMENT void nssCKFWHash_Iterate (nssCKFWHash *hash, nssCKFWHashIterator fcn, void *closure)

Class Documentation

struct nssCKFWHashStr

Definition at line 69 of file hash.c.

Collaboration diagram for nssCKFWHashStr:
Class Members
CK_ULONG count
NSSCKFWMutex * mutex
PLHashTable * plHashTable
struct arg_str

Definition at line 365 of file hash.c.

Collaboration diagram for arg_str:
Class Members
void * closure
nssCKFWHashIterator fcn
nssHashIterator fcn

Function Documentation

static PLHashNumber nss_ckfw_identity_hash ( const void key) [static]

Definition at line 83 of file hash.c.

{
  PRUint32 i = (PRUint32)key;
  PR_ASSERT(sizeof(PLHashNumber) == sizeof(PRUint32));
  return (PLHashNumber)i;
}

Here is the caller graph for this function:

static PRIntn nss_ckfwhash_enumerator ( PLHashEntry he,
PRIntn  index,
void arg 
) [static]

Definition at line 300 of file hash.c.

{
  struct arg_str *as = (struct arg_str *)arg;
  as->fcn(he->key, he->value, as->closure);
  return HT_ENUMERATE_NEXT;
}

Here is the caller graph for this function:

NSS_IMPLEMENT CK_RV nssCKFWHash_Add ( nssCKFWHash *  hash,
const void key,
const void value 
)

Definition at line 166 of file hash.c.

{
  CK_RV error = CKR_OK;
  PLHashEntry *he;

  error = nssCKFWMutex_Lock(hash->mutex);
  if( CKR_OK != error ) {
    return error;
  }
  
  he = PL_HashTableAdd(hash->plHashTable, key, (void *)value);
  if( (PLHashEntry *)NULL == he ) {
    error = CKR_HOST_MEMORY;
  } else {
    hash->count++;
  }

  (void)nssCKFWMutex_Unlock(hash->mutex);

  return error;
}
NSS_IMPLEMENT CK_ULONG nssCKFWHash_Count ( nssCKFWHash *  hash)

Definition at line 224 of file hash.c.

{
  CK_ULONG count;

  if( CKR_OK != nssCKFWMutex_Lock(hash->mutex) ) {
    return (CK_ULONG)0;
  }

  count = hash->count;

  (void)nssCKFWMutex_Unlock(hash->mutex);

  return count;
}
NSS_IMPLEMENT nssCKFWHash* nssCKFWHash_Create ( NSSCKFWInstance *  fwInstance,
NSSArena *  arena,
CK_RV pError 
)

Definition at line 98 of file hash.c.

{
  nssCKFWHash *rv;

#ifdef NSSDEBUG
  if( (CK_RV *)NULL == pError ) {
    return (nssCKFWHash *)NULL;
  }

  if( PR_SUCCESS != nssArena_verifyPointer(arena) ) {
    *pError = CKR_ARGUMENTS_BAD;
    return (nssCKFWHash *)NULL;
  }
#endif /* NSSDEBUG */

  rv = nss_ZNEW(arena, nssCKFWHash);
  if( (nssCKFWHash *)NULL == rv ) {
    *pError = CKR_HOST_MEMORY;
    return (nssCKFWHash *)NULL;
  }

  rv->mutex = nssCKFWInstance_CreateMutex(fwInstance, arena, pError);
  if( (NSSCKFWMutex *)NULL == rv->mutex ) {
    if( CKR_OK == *pError ) {
      *pError = CKR_GENERAL_ERROR;
    }
    return (nssCKFWHash *)NULL;
  }

  rv->plHashTable = PL_NewHashTable(0, nss_ckfw_identity_hash, 
    PL_CompareValues, PL_CompareValues, &nssArenaHashAllocOps, arena);
  if( (PLHashTable *)NULL == rv->plHashTable ) {
    (void)nssCKFWMutex_Destroy(rv->mutex);
    (void)nss_ZFreeIf(rv);
    *pError = CKR_HOST_MEMORY;
    return (nssCKFWHash *)NULL;
  }

  rv->count = 0;

  return rv;
}
NSS_IMPLEMENT void nssCKFWHash_Destroy ( nssCKFWHash *  hash)

Definition at line 151 of file hash.c.

NSS_IMPLEMENT CK_BBOOL nssCKFWHash_Exists ( nssCKFWHash *  hash,
const void it 
)

Definition at line 247 of file hash.c.

{
  void *value;

  if( CKR_OK != nssCKFWMutex_Lock(hash->mutex) ) {
    return CK_FALSE;
  }

  value = PL_HashTableLookup(hash->plHashTable, it);

  (void)nssCKFWMutex_Unlock(hash->mutex);

  if( (void *)NULL == value ) {
    return CK_FALSE;
  } else {
    return CK_TRUE;
  }
}
NSS_IMPLEMENT void nssCKFWHash_Iterate ( nssCKFWHash *  hash,
nssCKFWHashIterator  fcn,
void closure 
)

Definition at line 318 of file hash.c.

{
  struct arg_str as;
  as.fcn = fcn;
  as.closure = closure;

  if( CKR_OK != nssCKFWMutex_Lock(hash->mutex) ) {
    return;
  }

  PL_HashTableEnumerateEntries(hash->plHashTable, nss_ckfwhash_enumerator, &as);

  (void)nssCKFWMutex_Unlock(hash->mutex);

  return;
}
NSS_IMPLEMENT void* nssCKFWHash_Lookup ( nssCKFWHash *  hash,
const void it 
)

Definition at line 275 of file hash.c.

{
  void *rv;

  if( CKR_OK != nssCKFWMutex_Lock(hash->mutex) ) {
    return (void *)NULL;
  }

  rv = PL_HashTableLookup(hash->plHashTable, it);

  (void)nssCKFWMutex_Unlock(hash->mutex);

  return rv;
}
NSS_IMPLEMENT void nssCKFWHash_Remove ( nssCKFWHash *  hash,
const void it 
)

Definition at line 198 of file hash.c.

{
  PRBool found;

  if( CKR_OK != nssCKFWMutex_Lock(hash->mutex) ) {
    return;
  }

  found = PL_HashTableRemove(hash->plHashTable, it);
  if( found ) {
    hash->count--;
  }

  (void)nssCKFWMutex_Unlock(hash->mutex);
  return;
}