diff options
author | ian.mcgreer%sun.com <devnull@localhost> | 2003-04-22 14:25:45 +0000 |
---|---|---|
committer | ian.mcgreer%sun.com <devnull@localhost> | 2003-04-22 14:25:45 +0000 |
commit | c9cfee016455923ec0fa94ea253f804bec22aec4 (patch) | |
tree | 00a374b50c639a3661cc689d413805abbba0cc70 | |
parent | bd8734ae16ff46a2e51d366f83e6d7c51be9d0f4 (diff) | |
download | nss-hg-c9cfee016455923ec0fa94ea253f804bec22aec4.tar.gz |
bug 202553, replace reference mutex with atomic calls in PK11SlotInfo
r=relyea,wtc
-rw-r--r-- | security/nss/lib/pk11wrap/pk11slot.c | 27 | ||||
-rw-r--r-- | security/nss/lib/pk11wrap/secmodti.h | 3 |
2 files changed, 6 insertions, 24 deletions
diff --git a/security/nss/lib/pk11wrap/pk11slot.c b/security/nss/lib/pk11wrap/pk11slot.c index 85734b8f0..b32f83211 100644 --- a/security/nss/lib/pk11wrap/pk11slot.c +++ b/security/nss/lib/pk11wrap/pk11slot.c @@ -51,6 +51,7 @@ #include "secerr.h" #define NSSCKT_H /* we included pkcs11t.h, so block ckt.h from including nssckt.h */ #include "ckt.h" +#include "pratom.h" /************************************************************* @@ -382,27 +383,19 @@ PK11_NewSlotInfo(void) if (slot == NULL) return slot; #ifdef PKCS11_USE_THREADS - slot->refLock = PZ_NewLock(nssILockSlot); - if (slot->refLock == NULL) { - PORT_Free(slot); - return slot; - } slot->sessionLock = PZ_NewLock(nssILockSession); if (slot->sessionLock == NULL) { - PZ_DestroyLock(slot->refLock); PORT_Free(slot); return slot; } slot->freeListLock = PZ_NewLock(nssILockFreelist); if (slot->freeListLock == NULL) { PZ_DestroyLock(slot->sessionLock); - PZ_DestroyLock(slot->refLock); PORT_Free(slot); return slot; } #else slot->sessionLock = NULL; - slot->refLock = NULL; slot->freeListLock = NULL; #endif slot->freeSymKeysHead = NULL; @@ -451,9 +444,7 @@ PK11_NewSlotInfo(void) PK11SlotInfo * PK11_ReferenceSlot(PK11SlotInfo *slot) { - PK11_USE_THREADS(PZ_Lock(slot->refLock);) - slot->refCount++; - PK11_USE_THREADS(PZ_Unlock(slot->refLock);) + PR_AtomicIncrement(&slot->refCount); return slot; } @@ -477,10 +468,6 @@ PK11_DestroySlot(PK11SlotInfo *slot) SECMOD_SlotDestroyModule(slot->module,PR_TRUE); } #ifdef PKCS11_USE_THREADS - if (slot->refLock) { - PZ_DestroyLock(slot->refLock); - slot->refLock = NULL; - } if (slot->sessionLock) { PZ_DestroyLock(slot->sessionLock); slot->sessionLock = NULL; @@ -500,13 +487,9 @@ PK11_DestroySlot(PK11SlotInfo *slot) void PK11_FreeSlot(PK11SlotInfo *slot) { - PRBool freeit = PR_FALSE; - - PK11_USE_THREADS(PZ_Lock(slot->refLock);) - if (slot->refCount-- == 1) freeit = PR_TRUE; - PK11_USE_THREADS(PZ_Unlock(slot->refLock);) - - if (freeit) PK11_DestroySlot(slot); + if (PR_AtomicDecrement(&slot->refCount) == 0) { + PK11_DestroySlot(slot); + } } void diff --git a/security/nss/lib/pk11wrap/secmodti.h b/security/nss/lib/pk11wrap/secmodti.h index 3444bff12..ea13cd82f 100644 --- a/security/nss/lib/pk11wrap/secmodti.h +++ b/security/nss/lib/pk11wrap/secmodti.h @@ -81,8 +81,7 @@ struct PK11SlotInfoStr { unsigned long defaultFlags; /* keep track of who is using us so we don't accidently get freed while * still in use */ - int refCount; - PZLock *refLock; + PRInt32 refCount; /* to be in/decremented by atomic calls ONLY! */ PZLock *freeListLock; PK11SymKey *freeSymKeysHead; int keyCount; |