michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: /* michael@0: * Locking and queue management primatives michael@0: * michael@0: */ michael@0: michael@0: #include "seccomon.h" michael@0: #include "nssilock.h" michael@0: #include "secmod.h" michael@0: #include "secmodi.h" michael@0: #include "secmodti.h" michael@0: #include "nssrwlk.h" michael@0: michael@0: /* michael@0: * create a new lock for a Module List michael@0: */ michael@0: SECMODListLock *SECMOD_NewListLock() michael@0: { michael@0: return NSSRWLock_New( 10, "moduleListLock"); michael@0: } michael@0: michael@0: /* michael@0: * destroy the lock michael@0: */ michael@0: void SECMOD_DestroyListLock(SECMODListLock *lock) michael@0: { michael@0: NSSRWLock_Destroy(lock); michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Lock the List for Read: NOTE: this assumes the reading isn't so common michael@0: * the writing will be starved. michael@0: */ michael@0: void SECMOD_GetReadLock(SECMODListLock *modLock) michael@0: { michael@0: NSSRWLock_LockRead(modLock); michael@0: } michael@0: michael@0: /* michael@0: * Release the Read lock michael@0: */ michael@0: void SECMOD_ReleaseReadLock(SECMODListLock *modLock) michael@0: { michael@0: NSSRWLock_UnlockRead(modLock); michael@0: } michael@0: michael@0: michael@0: /* michael@0: * lock the list for Write michael@0: */ michael@0: void SECMOD_GetWriteLock(SECMODListLock *modLock) michael@0: { michael@0: NSSRWLock_LockWrite(modLock); michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Release the Write Lock: NOTE, this code is pretty inefficient if you have michael@0: * lots of write collisions. michael@0: */ michael@0: void SECMOD_ReleaseWriteLock(SECMODListLock *modLock) michael@0: { michael@0: NSSRWLock_UnlockWrite(modLock); michael@0: } michael@0: michael@0: michael@0: /* michael@0: * must Hold the Write lock michael@0: */ michael@0: void michael@0: SECMOD_RemoveList(SECMODModuleList **parent, SECMODModuleList *child) michael@0: { michael@0: *parent = child->next; michael@0: child->next = NULL; michael@0: } michael@0: michael@0: /* michael@0: * if lock is not specified, it must already be held michael@0: */ michael@0: void michael@0: SECMOD_AddList(SECMODModuleList *parent, SECMODModuleList *child, michael@0: SECMODListLock *lock) michael@0: { michael@0: if (lock) { SECMOD_GetWriteLock(lock); } michael@0: michael@0: child->next = parent->next; michael@0: parent->next = child; michael@0: michael@0: if (lock) { SECMOD_ReleaseWriteLock(lock); } michael@0: } michael@0: michael@0: