security/nss/lib/pk11wrap/pk11list.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 /*
michael@0 5 * Locking and queue management primatives
michael@0 6 *
michael@0 7 */
michael@0 8
michael@0 9 #include "seccomon.h"
michael@0 10 #include "nssilock.h"
michael@0 11 #include "secmod.h"
michael@0 12 #include "secmodi.h"
michael@0 13 #include "secmodti.h"
michael@0 14 #include "nssrwlk.h"
michael@0 15
michael@0 16 /*
michael@0 17 * create a new lock for a Module List
michael@0 18 */
michael@0 19 SECMODListLock *SECMOD_NewListLock()
michael@0 20 {
michael@0 21 return NSSRWLock_New( 10, "moduleListLock");
michael@0 22 }
michael@0 23
michael@0 24 /*
michael@0 25 * destroy the lock
michael@0 26 */
michael@0 27 void SECMOD_DestroyListLock(SECMODListLock *lock)
michael@0 28 {
michael@0 29 NSSRWLock_Destroy(lock);
michael@0 30 }
michael@0 31
michael@0 32
michael@0 33 /*
michael@0 34 * Lock the List for Read: NOTE: this assumes the reading isn't so common
michael@0 35 * the writing will be starved.
michael@0 36 */
michael@0 37 void SECMOD_GetReadLock(SECMODListLock *modLock)
michael@0 38 {
michael@0 39 NSSRWLock_LockRead(modLock);
michael@0 40 }
michael@0 41
michael@0 42 /*
michael@0 43 * Release the Read lock
michael@0 44 */
michael@0 45 void SECMOD_ReleaseReadLock(SECMODListLock *modLock)
michael@0 46 {
michael@0 47 NSSRWLock_UnlockRead(modLock);
michael@0 48 }
michael@0 49
michael@0 50
michael@0 51 /*
michael@0 52 * lock the list for Write
michael@0 53 */
michael@0 54 void SECMOD_GetWriteLock(SECMODListLock *modLock)
michael@0 55 {
michael@0 56 NSSRWLock_LockWrite(modLock);
michael@0 57 }
michael@0 58
michael@0 59
michael@0 60 /*
michael@0 61 * Release the Write Lock: NOTE, this code is pretty inefficient if you have
michael@0 62 * lots of write collisions.
michael@0 63 */
michael@0 64 void SECMOD_ReleaseWriteLock(SECMODListLock *modLock)
michael@0 65 {
michael@0 66 NSSRWLock_UnlockWrite(modLock);
michael@0 67 }
michael@0 68
michael@0 69
michael@0 70 /*
michael@0 71 * must Hold the Write lock
michael@0 72 */
michael@0 73 void
michael@0 74 SECMOD_RemoveList(SECMODModuleList **parent, SECMODModuleList *child)
michael@0 75 {
michael@0 76 *parent = child->next;
michael@0 77 child->next = NULL;
michael@0 78 }
michael@0 79
michael@0 80 /*
michael@0 81 * if lock is not specified, it must already be held
michael@0 82 */
michael@0 83 void
michael@0 84 SECMOD_AddList(SECMODModuleList *parent, SECMODModuleList *child,
michael@0 85 SECMODListLock *lock)
michael@0 86 {
michael@0 87 if (lock) { SECMOD_GetWriteLock(lock); }
michael@0 88
michael@0 89 child->next = parent->next;
michael@0 90 parent->next = child;
michael@0 91
michael@0 92 if (lock) { SECMOD_ReleaseWriteLock(lock); }
michael@0 93 }
michael@0 94
michael@0 95

mercurial