Bug 202593 and bug 204980: fixed a recursive deadlock introduced by the

fix for bug 202593. The session returned by nssSlot_CreateSession doesn't
need its own lock.  It is either protected by a higher-level lock (the
slot or module lock) or used by only one thread throughout its lifetime.
Modified Files: dev/devslot.c pk11wrap/dev3hack.c
This commit is contained in:
wtc%netscape.com 2003-05-10 14:21:40 +00:00
Родитель e270a63b63
Коммит a10abe7fb3
2 изменённых файлов: 19 добавлений и 5 удалений

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

@ -32,7 +32,7 @@
*/ */
#ifdef DEBUG #ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: devslot.c,v $ $Revision: 1.13 $ $Date: 2003-04-19 00:03:13 $ $Name: $"; static const char CVS_ID[] = "@(#) $RCSfile: devslot.c,v $ $Revision: 1.14 $ $Date: 2003-05-10 14:21:38 $ $Name: $";
#endif /* DEBUG */ #endif /* DEBUG */
#ifndef NSSCKEPV_H #ifndef NSSCKEPV_H
@ -795,7 +795,7 @@ nssSlot_CreateSession
return (nssSession *)NULL; return (nssSession *)NULL;
} }
if (nssModule_IsThreadSafe(slot->module)) { if (nssModule_IsThreadSafe(slot->module)) {
/* If the parent module is not threadsafe, /* If the parent module is threadsafe,
* create lock to protect just this session. * create lock to protect just this session.
*/ */
rvSession->lock = PZ_NewLock(nssILockOther); rvSession->lock = PZ_NewLock(nssILockOther);

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

@ -32,7 +32,7 @@
*/ */
#ifdef DEBUG #ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: dev3hack.c,v $ $Revision: 1.18 $ $Date: 2003-04-19 00:03:32 $ $Name: $"; static const char CVS_ID[] = "@(#) $RCSfile: dev3hack.c,v $ $Revision: 1.19 $ $Date: 2003-05-10 14:21:40 $ $Name: $";
#endif /* DEBUG */ #endif /* DEBUG */
#ifndef NSS_3_4_CODE #ifndef NSS_3_4_CODE
@ -93,8 +93,22 @@ nssSlot_CreateSession
} }
rvSession->isRW = PR_TRUE; rvSession->isRW = PR_TRUE;
rvSession->slot = slot; rvSession->slot = slot;
/* actually, should get it's own lock if slot->lock is NULL */ /*
rvSession->lock = slot->lock; * The session doesn't need its own lock. Here's why.
* 1. If we are reusing the default RW session of the slot,
* the slot lock is already locked to protect the session.
* 2. If the module is not thread safe, the slot (or rather
* module) lock is already locked.
* 3. If the module is thread safe and we are using a new
* session, no higher-level lock has been locked and we
* would need a lock for the new session. However, the
* NSS_3_4_CODE usage of the session is that it is always
* used and destroyed within the same function and never
* shared with another thread.
* So the session is either already protected by another
* lock or only used by one thread.
*/
rvSession->lock = NULL;
rvSession->ownLock = PR_FALSE; rvSession->ownLock = PR_FALSE;
return rvSession; return rvSession;
} else { } else {