Back to index

lightning-sunbird  0.9+nobinonly
pk11list.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 /*
00037  * Locking and queue management primatives
00038  *
00039  */
00040 
00041 #include "seccomon.h"
00042 #include "nssilock.h"
00043 #include "secmod.h"
00044 #include "secmodi.h"
00045 #include "secmodti.h"
00046 #include "nssrwlk.h"
00047 
00048 /*
00049  * create a new lock for a Module List
00050  */
00051 SECMODListLock *SECMOD_NewListLock()
00052 {
00053     return NSSRWLock_New( 10, "moduleListLock");
00054 }
00055 
00056 /*
00057  * destroy the lock
00058  */
00059 void SECMOD_DestroyListLock(SECMODListLock *lock) 
00060 {
00061     NSSRWLock_Destroy(lock);
00062 }
00063 
00064 
00065 /*
00066  * Lock the List for Read: NOTE: this assumes the reading isn't so common
00067  * the writing will be starved.
00068  */
00069 void SECMOD_GetReadLock(SECMODListLock *modLock) 
00070 {
00071     NSSRWLock_LockRead(modLock);
00072 }
00073 
00074 /*
00075  * Release the Read lock
00076  */
00077 void SECMOD_ReleaseReadLock(SECMODListLock *modLock) 
00078 {
00079     NSSRWLock_UnlockRead(modLock);
00080 }
00081 
00082 
00083 /*
00084  * lock the list for Write
00085  */
00086 void SECMOD_GetWriteLock(SECMODListLock *modLock) 
00087 {
00088     NSSRWLock_LockWrite(modLock);
00089 }
00090 
00091 
00092 /*
00093  * Release the Write Lock: NOTE, this code is pretty inefficient if you have
00094  * lots of write collisions.
00095  */
00096 void SECMOD_ReleaseWriteLock(SECMODListLock *modLock) 
00097 {
00098     NSSRWLock_UnlockWrite(modLock);
00099 }
00100 
00101 
00102 /*
00103  * must Hold the Write lock
00104  */
00105 void
00106 SECMOD_RemoveList(SECMODModuleList **parent, SECMODModuleList *child) 
00107 {
00108     *parent = child->next;
00109     child->next = NULL;
00110 }
00111 
00112 /*
00113  * if lock is not specified, it must already be held
00114  */
00115 void
00116 SECMOD_AddList(SECMODModuleList *parent, SECMODModuleList *child, 
00117                                                  SECMODListLock *lock) 
00118 {
00119     if (lock) { SECMOD_GetWriteLock(lock); }
00120 
00121     child->next = parent->next;
00122     parent->next = child;
00123 
00124    if (lock) { SECMOD_ReleaseWriteLock(lock); }
00125 }
00126 
00127