Addresses bug 126087 (hot locks identified by Ning at Sun).

Using atomic instructions to reduce contention on slot->freeListLock
and symKey->refLock.
This commit is contained in:
kirk.erickson%sun.com 2002-04-04 18:30:51 +00:00
Родитель 6e9cb5194b
Коммит d62094b5b6
1 изменённых файлов: 13 добавлений и 13 удалений

Просмотреть файл

@ -161,14 +161,16 @@ static PK11SymKey *
pk11_getKeyFromList(PK11SlotInfo *slot) { pk11_getKeyFromList(PK11SlotInfo *slot) {
PK11SymKey *symKey = NULL; PK11SymKey *symKey = NULL;
PK11_USE_THREADS(PZ_Lock(slot->freeListLock);) PK11_USE_THREADS(PZ_Lock(slot->freeListLock);)
if (slot->freeSymKeysHead) { if (slot->freeSymKeysHead) {
symKey = slot->freeSymKeysHead; symKey = slot->freeSymKeysHead;
slot->freeSymKeysHead = symKey->next; slot->freeSymKeysHead = symKey->next;
slot->keyCount--;
}
PK11_USE_THREADS(PZ_Unlock(slot->freeListLock);) PK11_USE_THREADS(PZ_Unlock(slot->freeListLock);)
PR_AtomicDecrement(&slot->keyCount);
}
else {
PK11_USE_THREADS(PZ_Unlock(slot->freeListLock);)
}
if (symKey) { if (symKey) {
symKey->next = NULL; symKey->next = NULL;
if ((symKey->series != slot->series) || (!symKey->sessionOwner)) if ((symKey->series != slot->series) || (!symKey->sessionOwner))
@ -247,11 +249,9 @@ PK11_FreeSymKey(PK11SymKey *symKey)
PK11SlotInfo *slot; PK11SlotInfo *slot;
PRBool freeit = PR_TRUE; PRBool freeit = PR_TRUE;
PK11_USE_THREADS(PZ_Lock(symKey->refLock);) if (PR_AtomicDecrement(&symKey->refCount) == -1) {
if (symKey->refCount-- == 1) {
destroy= PR_TRUE; destroy= PR_TRUE;
} }
PK11_USE_THREADS(PZ_Unlock(symKey->refLock);)
if (destroy) { if (destroy) {
if ((symKey->owner) && symKey->objectID != CK_INVALID_HANDLE) { if ((symKey->owner) && symKey->objectID != CK_INVALID_HANDLE) {
pk11_EnterKeyMonitor(symKey); pk11_EnterKeyMonitor(symKey);
@ -264,15 +264,15 @@ PK11_FreeSymKey(PK11SymKey *symKey)
PORT_Free(symKey->data.data); PORT_Free(symKey->data.data);
} }
slot = symKey->slot; slot = symKey->slot;
PK11_USE_THREADS(PZ_Lock(slot->freeListLock);)
if (slot->keyCount < slot->maxKeyCount) { if (slot->keyCount < slot->maxKeyCount) {
PK11_USE_THREADS(PZ_Lock(slot->freeListLock);)
symKey->next = slot->freeSymKeysHead; symKey->next = slot->freeSymKeysHead;
slot->freeSymKeysHead = symKey; slot->freeSymKeysHead = symKey;
slot->keyCount++; PK11_USE_THREADS(PZ_Unlock(slot->freeListLock);)
PR_AtomicIncrement(&slot->keyCount);
symKey->slot = NULL; symKey->slot = NULL;
freeit = PR_FALSE; freeit = PR_FALSE;
} }
PK11_USE_THREADS(PZ_Unlock(slot->freeListLock);)
if (freeit) { if (freeit) {
pk11_CloseSession(symKey->slot, symKey->session, pk11_CloseSession(symKey->slot, symKey->session,
symKey->sessionOwner); symKey->sessionOwner);