Blame nss/lib/pk11wrap/pk11list.c

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