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.

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

mercurial