Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / lib / libpkix / pkix_pl_nss / system / pkix_pl_monitorlock.c
blob3d910facaa096c7609aa7ae66ca1f4ff7a846fed
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Sun Microsystems
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 * pkix_pl_monitorlock.c
40 * Read/Write Lock Functions
44 #include "pkix_pl_monitorlock.h"
46 /* --Private-Functions-------------------------------------------- */
48 static PKIX_Error *
49 pkix_pl_MonitorLock_Destroy(
50 PKIX_PL_Object *object,
51 void *plContext)
53 PKIX_PL_MonitorLock* monitorLock = NULL;
55 PKIX_ENTER(MONITORLOCK, "pkix_pl_MonitorLock_Destroy");
56 PKIX_NULLCHECK_ONE(object);
58 PKIX_CHECK(pkix_CheckType(object, PKIX_MONITORLOCK_TYPE, plContext),
59 PKIX_OBJECTNOTMONITORLOCK);
61 monitorLock = (PKIX_PL_MonitorLock*) object;
63 PKIX_MONITORLOCK_DEBUG("Calling PR_DestroyMonitor)\n");
64 PR_DestroyMonitor(monitorLock->lock);
65 monitorLock->lock = NULL;
67 cleanup:
69 PKIX_RETURN(MONITORLOCK);
73 * FUNCTION: pkix_pl_MonitorLock_RegisterSelf
74 * DESCRIPTION:
75 * Registers PKIX_MONITORLOCK_TYPE and its related functions with
76 * systemClasses[].
77 * THREAD SAFETY:
78 * Not Thread Safe - for performance and complexity reasons
80 * Since this function is only called by PKIX_PL_Initialize, which should
81 * only be called once, it is acceptable that this function is not
82 * thread-safe.
84 PKIX_Error *
85 pkix_pl_MonitorLock_RegisterSelf(
86 void *plContext)
89 extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES];
90 pkix_ClassTable_Entry entry;
92 PKIX_ENTER(MONITORLOCK, "pkix_pl_MonitorLock_RegisterSelf");
94 entry.description = "MonitorLock";
95 entry.destructor = pkix_pl_MonitorLock_Destroy;
96 entry.equalsFunction = NULL;
97 entry.hashcodeFunction = NULL;
98 entry.toStringFunction = NULL;
99 entry.comparator = NULL;
100 entry.duplicateFunction = NULL;
102 systemClasses[PKIX_MONITORLOCK_TYPE] = entry;
104 PKIX_RETURN(MONITORLOCK);
107 /* --Public-Functions--------------------------------------------- */
109 PKIX_Error *
110 PKIX_PL_MonitorLock_Create(
111 PKIX_PL_MonitorLock **pNewLock,
112 void *plContext)
114 PKIX_PL_MonitorLock *monitorLock = NULL;
116 PKIX_ENTER(MONITORLOCK, "PKIX_PL_MonitorLock_Create");
117 PKIX_NULLCHECK_ONE(pNewLock);
119 PKIX_CHECK(PKIX_PL_Object_Alloc
120 (PKIX_MONITORLOCK_TYPE,
121 sizeof (PKIX_PL_MonitorLock),
122 (PKIX_PL_Object **)&monitorLock,
123 plContext),
124 PKIX_ERRORALLOCATINGMONITORLOCK);
126 PKIX_MONITORLOCK_DEBUG("\tCalling PR_NewMonitor)\n");
127 monitorLock->lock = PR_NewMonitor();
129 if (monitorLock->lock == NULL) {
130 PKIX_DECREF(monitorLock);
131 PKIX_ERROR(PKIX_ERRORALLOCATINGPRMONITORLOCK);
134 *pNewLock = monitorLock;
136 cleanup:
138 PKIX_RETURN(MONITORLOCK);
141 PKIX_Error *
142 PKIX_PL_MonitorLock_Enter(
143 PKIX_PL_MonitorLock *monitorLock,
144 void *plContext)
146 PKIX_ENTER_NO_LOGGER(MONITORLOCK, "PKIX_PL_MonitorLock_Enter");
147 PKIX_NULLCHECK_ONE(monitorLock);
149 PKIX_MONITORLOCK_DEBUG("\tCalling PR_EnterMonitor)\n");
150 (void) PR_EnterMonitor(monitorLock->lock);
152 PKIX_RETURN_NO_LOGGER(MONITORLOCK);
155 PKIX_Error *
156 PKIX_PL_MonitorLock_Exit(
157 PKIX_PL_MonitorLock *monitorLock,
158 void *plContext)
160 PRStatus prStatus;
161 PKIX_ENTER_NO_LOGGER(MONITORLOCK, "PKIX_PL_MonitorLock_Exit");
162 PKIX_NULLCHECK_ONE(monitorLock);
164 PKIX_MONITORLOCK_DEBUG("\tCalling PR_ExitMonitor)\n");
165 prStatus = PR_ExitMonitor(monitorLock->lock);
166 if (prStatus != PR_SUCCESS) {
167 PKIX_ERROR(PKIX_MONITORLOCKEXITFAILED);
170 cleanup:
172 PKIX_RETURN_NO_LOGGER(MONITORLOCK);