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
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.
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-------------------------------------------- */
49 pkix_pl_MonitorLock_Destroy(
50 PKIX_PL_Object
*object
,
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
;
69 PKIX_RETURN(MONITORLOCK
);
73 * FUNCTION: pkix_pl_MonitorLock_RegisterSelf
75 * Registers PKIX_MONITORLOCK_TYPE and its related functions with
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
85 pkix_pl_MonitorLock_RegisterSelf(
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--------------------------------------------- */
110 PKIX_PL_MonitorLock_Create(
111 PKIX_PL_MonitorLock
**pNewLock
,
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
,
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
;
138 PKIX_RETURN(MONITORLOCK
);
142 PKIX_PL_MonitorLock_Enter(
143 PKIX_PL_MonitorLock
*monitorLock
,
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
);
156 PKIX_PL_MonitorLock_Exit(
157 PKIX_PL_MonitorLock
*monitorLock
,
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
);
172 PKIX_RETURN_NO_LOGGER(MONITORLOCK
);