00001 /* ***** BEGIN LICENSE BLOCK *****00002 * Version: MPL 1.1/GPL 2.0/LGPL 2.100003 *00004 * The contents of this file are subject to the Mozilla Public License Version00005 * 1.1 (the "License"); you may not use this file except in compliance with00006 * the License. You may obtain a copy of the License at00007 * 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 License00011 * for the specific language governing rights and limitations under the00012 * License.00013 *00014 * The Original Code is the Netscape security libraries.00015 *00016 * The Initial Developer of the Original Code is00017 * Netscape Communications Corporation.00018 * Portions created by the Initial Developer are Copyright (C) 1994-200000019 * the Initial Developer. All Rights Reserved.00020 *00021 * Contributor(s):00022 *00023 * Alternatively, the contents of this file may be used under the terms of00024 * either the GNU General Public License Version 2 or later (the "GPL"), or00025 * 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 instead00027 * of those above. If you wish to allow use of your version of this file only00028 * under the terms of either the GPL or the LGPL, and not to allow others to00029 * use your version of this file under the terms of the MPL, indicate your00030 * decision by deleting the provisions above and replace them with the notice00031 * and other provisions required by the GPL or the LGPL. If you do not delete00032 * the provisions above, a recipient may use your version of this file under00033 * the terms of any one of the MPL, the GPL or the LGPL.00034 *00035 * ***** END LICENSE BLOCK ***** */00036 /*00037 * Locking and queue management primatives00038 *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 List00050 */00051SECMODListLock *SECMOD_NewListLock()
00052 {
00053 returnNSSRWLock_New( 10, "moduleListLock");
00054 }
00055
00056 /*00057 * destroy the lock00058 */00059voidSECMOD_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 common00067 * the writing will be starved.00068 */00069voidSECMOD_GetReadLock(SECMODListLock *modLock)
00070 {
00071 NSSRWLock_LockRead(modLock);
00072 }
00073
00074 /*00075 * Release the Read lock00076 */00077voidSECMOD_ReleaseReadLock(SECMODListLock *modLock)
00078 {
00079 NSSRWLock_UnlockRead(modLock);
00080 }
00081
00082
00083 /*00084 * lock the list for Write00085 */00086voidSECMOD_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 have00094 * lots of write collisions.00095 */00096voidSECMOD_ReleaseWriteLock(SECMODListLock *modLock)
00097 {
00098 NSSRWLock_UnlockWrite(modLock);
00099 }
00100
00101
00102 /*00103 * must Hold the Write lock00104 */00105 void00106SECMOD_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 held00114 */00115 void00116SECMOD_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