Back to index

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

Go to the source code of this file.

Classes

struct  NSSCKFWMutexStr

Functions

static CK_RV mutex_noop (CK_VOID_PTR pMutex)
NSS_EXTERN NSSCKFWMutex * nssCKFWMutex_Create (CK_C_INITIALIZE_ARGS_PTR pInitArgs, CryptokiLockingState LockingState, NSSArena *arena, CK_RV *pError)
NSS_EXTERN CK_RV nssCKFWMutex_Destroy (NSSCKFWMutex *mutex)
NSS_EXTERN CK_RV nssCKFWMutex_Lock (NSSCKFWMutex *mutex)
NSS_EXTERN CK_RV nssCKFWMutex_Unlock (NSSCKFWMutex *mutex)
NSS_EXTERN CK_RV NSSCKFWMutex_Destroy (NSSCKFWMutex *mutex)
NSS_EXTERN CK_RV NSSCKFWMutex_Lock (NSSCKFWMutex *mutex)
NSS_EXTERN CK_RV NSSCKFWMutex_Unlock (NSSCKFWMutex *mutex)

Class Documentation

struct NSSCKFWMutexStr

Definition at line 69 of file mutex.c.

Collaboration diagram for NSSCKFWMutexStr:
Class Members
PRLock * lock

Function Documentation

static CK_RV mutex_noop ( CK_VOID_PTR  pMutex) [static]

Definition at line 116 of file mutex.c.

{
  return CKR_OK;
}
NSS_EXTERN NSSCKFWMutex* nssCKFWMutex_Create ( CK_C_INITIALIZE_ARGS_PTR  pInitArgs,
CryptokiLockingState  LockingState,
NSSArena *  arena,
CK_RV pError 
)

Definition at line 129 of file mutex.c.

{
  NSSCKFWMutex *mutex;
  
  mutex = nss_ZNEW(arena, NSSCKFWMutex);
  if( (NSSCKFWMutex *)NULL == mutex ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKFWMutex *)NULL;
  }
  *pError = CKR_OK;
  mutex->lock = NULL;
  if (LockingState == MultiThreaded) {
    mutex->lock = PR_NewLock();
    if (!mutex->lock) {
      *pError = CKR_HOST_MEMORY; /* we couldn't get the resource */
    }
  }
    
  if( CKR_OK != *pError ) {
    (void)nss_ZFreeIf(mutex);
    return (NSSCKFWMutex *)NULL;
  }

#ifdef DEBUG
  *pError = mutex_add_pointer(mutex);
  if( CKR_OK != *pError ) {
    if (mutex->lock) {
      PR_DestroyLock(mutex->lock);
    }
    (void)nss_ZFreeIf(mutex);
    return (NSSCKFWMutex *)NULL;
  }
#endif /* DEBUG */

  return mutex;
}  
NSS_EXTERN CK_RV nssCKFWMutex_Destroy ( NSSCKFWMutex *  mutex)

Definition at line 177 of file mutex.c.

{
  CK_RV rv = CKR_OK;

#ifdef NSSDEBUG
  rv = nssCKFWMutex_verifyPointer(mutex);
  if( CKR_OK != rv ) {
    return rv;
  }
#endif /* NSSDEBUG */
 
  if (mutex->lock) {
    PR_DestroyLock(mutex->lock);
  } 

#ifdef DEBUG
  (void)mutex_remove_pointer(mutex);
#endif /* DEBUG */

  (void)nss_ZFreeIf(mutex);
  return rv;
}
NSS_EXTERN CK_RV NSSCKFWMutex_Destroy ( NSSCKFWMutex *  mutex)

Definition at line 261 of file mutex.c.

{
#ifdef DEBUG
  CK_RV rv = nssCKFWMutex_verifyPointer(mutex);
  if( CKR_OK != rv ) {
    return rv;
  }
#endif /* DEBUG */
  
  return nssCKFWMutex_Destroy(mutex);
}

Here is the caller graph for this function:

NSS_EXTERN CK_RV nssCKFWMutex_Lock ( NSSCKFWMutex *  mutex)

Definition at line 208 of file mutex.c.

{
#ifdef NSSDEBUG
  CK_RV rv = nssCKFWMutex_verifyPointer(mutex);
  if( CKR_OK != rv ) {
    return rv;
  }
#endif /* NSSDEBUG */
  if (mutex->lock) {
    PR_Lock(mutex->lock);
  }
  
  return CKR_OK;
}
NSS_EXTERN CK_RV NSSCKFWMutex_Lock ( NSSCKFWMutex *  mutex)

Definition at line 281 of file mutex.c.

{
#ifdef DEBUG
  CK_RV rv = nssCKFWMutex_verifyPointer(mutex);
  if( CKR_OK != rv ) {
    return rv;
  }
#endif /* DEBUG */
  
  return nssCKFWMutex_Lock(mutex);
}

Here is the caller graph for this function:

NSS_EXTERN CK_RV nssCKFWMutex_Unlock ( NSSCKFWMutex *  mutex)

Definition at line 231 of file mutex.c.

{
  PRStatus nrv;
#ifdef NSSDEBUG
  CK_RV rv = nssCKFWMutex_verifyPointer(mutex);

  if( CKR_OK != rv ) {
    return rv;
  }
#endif /* NSSDEBUG */

  if (!mutex->lock) 
    return CKR_OK;

  nrv =  PR_Unlock(mutex->lock);

  /* if unlock fails, either we have a programming error, or we have
   * some sort of hardware failure... in either case return CKR_DEVICE_ERROR.
   */
  return nrv == PR_SUCCESS ? CKR_OK : CKR_DEVICE_ERROR;
}
NSS_EXTERN CK_RV NSSCKFWMutex_Unlock ( NSSCKFWMutex *  mutex)

Definition at line 301 of file mutex.c.

{
#ifdef DEBUG
  CK_RV rv = nssCKFWMutex_verifyPointer(mutex);
  if( CKR_OK != rv ) {
    return rv;
  }
#endif /* DEBUG */

  return nssCKFWMutex_Unlock(mutex);
}

Here is the caller graph for this function: