From 61aaa8d82f49d6e62a3fb7245d554f4c5f1a3828 Mon Sep 17 00:00:00 2001 From: "ian.mcgreer%sun.com" Date: Mon, 12 May 2003 23:24:25 +0000 Subject: [PATCH] bug 203049, move operations outside of slot->slotLock r=relyea git-svn-id: svn://10.0.0.236/branches/NSS_3_3_BRANCH@142359 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/security/nss/lib/softoken/pkcs11.c | 35 ++++++++++----------- mozilla/security/nss/lib/softoken/pkcs11i.h | 2 +- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/mozilla/security/nss/lib/softoken/pkcs11.c b/mozilla/security/nss/lib/softoken/pkcs11.c index 55c6ad26c78..992feda1931 100644 --- a/mozilla/security/nss/lib/softoken/pkcs11.c +++ b/mozilla/security/nss/lib/softoken/pkcs11.c @@ -2916,16 +2916,16 @@ CK_RV NSC_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, flags | CKF_SERIAL_SESSION); if (session == NULL) return CKR_HOST_MEMORY; - PK11_USE_THREADS(PZ_Lock(slot->slotLock);) if (slotID == NETSCAPE_SLOT_ID && (flags & CKF_RW_SESSION)) { /* NETSCAPE_SLOT_ID is Read ONLY */ session->info.flags &= ~CKF_RW_SESSION; } - slot->sessionCount++; - if (session->info.flags & CKF_RW_SESSION) { - slot->rwSessionCount++; - } + PK11_USE_THREADS(PZ_Lock(slot->slotLock);) + ++slot->sessionCount; PK11_USE_THREADS(PZ_Unlock(slot->slotLock);) + if (session->info.flags & CKF_RW_SESSION) { + PR_AtomicIncrement(&slot->rwSessionCount); + } do { do { @@ -2975,19 +2975,18 @@ CK_RV NSC_CloseSession(CK_SESSION_HANDLE hSession) } PK11_USE_THREADS(PZ_Unlock(PK11_SESSION_LOCK(slot,hSession));) - PK11_USE_THREADS(PZ_Lock(slot->slotLock);) if (sessionFound) { - slot->sessionCount--; + PK11_USE_THREADS(PZ_Lock(slot->slotLock);) + if (--slot->sessionCount == 0) { + pw = slot->password; + slot->isLoggedIn = PR_FALSE; + slot->password = NULL; + } + PK11_USE_THREADS(PZ_Unlock(slot->slotLock);) if (session->info.flags & CKF_RW_SESSION) { - slot->rwSessionCount--; + PR_AtomicDecrement(&slot->rwSessionCount); } } - if (slot->sessionCount == 0) { - pw = slot->password; - slot->isLoggedIn = PR_FALSE; - slot->password = NULL; - } - PK11_USE_THREADS(PZ_Unlock(slot->slotLock);) pk11_FreeSession(session); if (pw) SECITEM_ZfreeItem(pw, PR_TRUE); @@ -3033,11 +3032,11 @@ CK_RV NSC_CloseAllSessions (CK_SLOT_ID slotID) session->next = session->prev = NULL; PK11_USE_THREADS(PZ_Unlock(PK11_SESSION_LOCK(slot,i));) PK11_USE_THREADS(PZ_Lock(slot->slotLock);) - slot->sessionCount--; - if (session->info.flags & CKF_RW_SESSION) { - slot->rwSessionCount--; - } + --slot->sessionCount; PK11_USE_THREADS(PZ_Unlock(slot->slotLock);) + if (session->info.flags & CKF_RW_SESSION) { + PR_AtomicDecrement(&slot->rwSessionCount); + } } else { PK11_USE_THREADS(PZ_Unlock(PK11_SESSION_LOCK(slot,i));) } diff --git a/mozilla/security/nss/lib/softoken/pkcs11i.h b/mozilla/security/nss/lib/softoken/pkcs11i.h index 72b0a6674d8..67f11c3aa06 100644 --- a/mozilla/security/nss/lib/softoken/pkcs11i.h +++ b/mozilla/security/nss/lib/softoken/pkcs11i.h @@ -291,7 +291,7 @@ struct PK11SlotStr { int sessionIDCount; int sessionIDConflict; int sessionCount; - int rwSessionCount; + PRInt32 rwSessionCount; int tokenIDCount; PK11Object *tokObjects[TOKEN_OBJECT_HASH_SIZE]; PK11Session *head[SESSION_HASH_SIZE];