security/nss/lib/pk11wrap/pk11list.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/pk11wrap/pk11list.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +/*
     1.8 + * Locking and queue management primatives
     1.9 + *
    1.10 + */
    1.11 +
    1.12 +#include "seccomon.h"
    1.13 +#include "nssilock.h"
    1.14 +#include "secmod.h"
    1.15 +#include "secmodi.h"
    1.16 +#include "secmodti.h"
    1.17 +#include "nssrwlk.h"
    1.18 +
    1.19 +/*
    1.20 + * create a new lock for a Module List
    1.21 + */
    1.22 +SECMODListLock *SECMOD_NewListLock()
    1.23 +{
    1.24 +    return NSSRWLock_New( 10, "moduleListLock");
    1.25 +}
    1.26 +
    1.27 +/*
    1.28 + * destroy the lock
    1.29 + */
    1.30 +void SECMOD_DestroyListLock(SECMODListLock *lock) 
    1.31 +{
    1.32 +    NSSRWLock_Destroy(lock);
    1.33 +}
    1.34 +
    1.35 +
    1.36 +/*
    1.37 + * Lock the List for Read: NOTE: this assumes the reading isn't so common
    1.38 + * the writing will be starved.
    1.39 + */
    1.40 +void SECMOD_GetReadLock(SECMODListLock *modLock) 
    1.41 +{
    1.42 +    NSSRWLock_LockRead(modLock);
    1.43 +}
    1.44 +
    1.45 +/*
    1.46 + * Release the Read lock
    1.47 + */
    1.48 +void SECMOD_ReleaseReadLock(SECMODListLock *modLock) 
    1.49 +{
    1.50 +    NSSRWLock_UnlockRead(modLock);
    1.51 +}
    1.52 +
    1.53 +
    1.54 +/*
    1.55 + * lock the list for Write
    1.56 + */
    1.57 +void SECMOD_GetWriteLock(SECMODListLock *modLock) 
    1.58 +{
    1.59 +    NSSRWLock_LockWrite(modLock);
    1.60 +}
    1.61 +
    1.62 +
    1.63 +/*
    1.64 + * Release the Write Lock: NOTE, this code is pretty inefficient if you have
    1.65 + * lots of write collisions.
    1.66 + */
    1.67 +void SECMOD_ReleaseWriteLock(SECMODListLock *modLock) 
    1.68 +{
    1.69 +    NSSRWLock_UnlockWrite(modLock);
    1.70 +}
    1.71 +
    1.72 +
    1.73 +/*
    1.74 + * must Hold the Write lock
    1.75 + */
    1.76 +void
    1.77 +SECMOD_RemoveList(SECMODModuleList **parent, SECMODModuleList *child) 
    1.78 +{
    1.79 +    *parent = child->next;
    1.80 +    child->next = NULL;
    1.81 +}
    1.82 +
    1.83 +/*
    1.84 + * if lock is not specified, it must already be held
    1.85 + */
    1.86 +void
    1.87 +SECMOD_AddList(SECMODModuleList *parent, SECMODModuleList *child, 
    1.88 +							SECMODListLock *lock) 
    1.89 +{
    1.90 +    if (lock) { SECMOD_GetWriteLock(lock); }
    1.91 +
    1.92 +    child->next = parent->next;
    1.93 +    parent->next = child;
    1.94 +
    1.95 +   if (lock) { SECMOD_ReleaseWriteLock(lock); }
    1.96 +}
    1.97 +
    1.98 +

mercurial