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