Lines Matching refs:mon

15 static void _PR_PostNotifyToMonitor(PRMonitor *mon, PRBool broadcast)  in _PR_PostNotifyToMonitor()  argument
17 PR_ASSERT(mon != NULL); in _PR_PostNotifyToMonitor()
18 PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mon); in _PR_PostNotifyToMonitor()
24 mon->notifyTimes = -1; in _PR_PostNotifyToMonitor()
26 else if (mon->notifyTimes != -1) { in _PR_PostNotifyToMonitor()
27 mon->notifyTimes += 1; in _PR_PostNotifyToMonitor()
57 PRMonitor *mon; in PR_NewMonitor() local
64 mon = PR_NEWZAP(PRMonitor); in PR_NewMonitor()
65 if (mon == NULL) { in PR_NewMonitor()
70 rv = _PR_InitLock(&mon->lock); in PR_NewMonitor()
76 mon->owner = NULL; in PR_NewMonitor()
78 rv = _PR_InitCondVar(&mon->entryCV, &mon->lock); in PR_NewMonitor()
84 rv = _PR_InitCondVar(&mon->waitCV, &mon->lock); in PR_NewMonitor()
90 mon->notifyTimes = 0; in PR_NewMonitor()
91 mon->entryCount = 0; in PR_NewMonitor()
92 mon->name = NULL; in PR_NewMonitor()
93 return mon; in PR_NewMonitor()
96 _PR_FreeCondVar(&mon->entryCV); in PR_NewMonitor()
98 _PR_FreeLock(&mon->lock); in PR_NewMonitor()
100 PR_Free(mon); in PR_NewMonitor()
106 PRMonitor* mon = PR_NewMonitor(); in PR_NewNamedMonitor() local
107 if (mon) { in PR_NewNamedMonitor()
108 mon->name = name; in PR_NewNamedMonitor()
110 return mon; in PR_NewNamedMonitor()
118 PR_IMPLEMENT(void) PR_DestroyMonitor(PRMonitor *mon) in PR_DestroyMonitor() argument
120 PR_ASSERT(mon != NULL); in PR_DestroyMonitor()
121 _PR_FreeCondVar(&mon->waitCV); in PR_DestroyMonitor()
122 _PR_FreeCondVar(&mon->entryCV); in PR_DestroyMonitor()
123 _PR_FreeLock(&mon->lock); in PR_DestroyMonitor()
125 memset(mon, 0xaf, sizeof(PRMonitor)); in PR_DestroyMonitor()
127 PR_Free(mon); in PR_DestroyMonitor()
133 PR_IMPLEMENT(void) PR_EnterMonitor(PRMonitor *mon) in PR_EnterMonitor() argument
138 PR_ASSERT(mon != NULL); in PR_EnterMonitor()
139 PR_Lock(&mon->lock); in PR_EnterMonitor()
140 if (mon->entryCount != 0) { in PR_EnterMonitor()
141 if (mon->owner == me) { in PR_EnterMonitor()
144 while (mon->entryCount != 0) { in PR_EnterMonitor()
145 rv = PR_WaitCondVar(&mon->entryCV, PR_INTERVAL_NO_TIMEOUT); in PR_EnterMonitor()
150 PR_ASSERT(mon->notifyTimes == 0); in PR_EnterMonitor()
151 PR_ASSERT(mon->owner == NULL); in PR_EnterMonitor()
152 mon->owner = me; in PR_EnterMonitor()
155 mon->entryCount += 1; in PR_EnterMonitor()
156 rv = PR_Unlock(&mon->lock); in PR_EnterMonitor()
165 PR_IMPLEMENT(PRBool) PR_TestAndEnterMonitor(PRMonitor *mon) in PR_TestAndEnterMonitor() argument
170 PR_ASSERT(mon != NULL); in PR_TestAndEnterMonitor()
171 PR_Lock(&mon->lock); in PR_TestAndEnterMonitor()
172 if (mon->entryCount != 0) { in PR_TestAndEnterMonitor()
173 if (mon->owner == me) { in PR_TestAndEnterMonitor()
176 rv = PR_Unlock(&mon->lock); in PR_TestAndEnterMonitor()
181 PR_ASSERT(mon->notifyTimes == 0); in PR_TestAndEnterMonitor()
182 PR_ASSERT(mon->owner == NULL); in PR_TestAndEnterMonitor()
183 mon->owner = me; in PR_TestAndEnterMonitor()
186 mon->entryCount += 1; in PR_TestAndEnterMonitor()
187 rv = PR_Unlock(&mon->lock); in PR_TestAndEnterMonitor()
195 PR_IMPLEMENT(PRStatus) PR_ExitMonitor(PRMonitor *mon) in PR_ExitMonitor() argument
200 PR_ASSERT(mon != NULL); in PR_ExitMonitor()
201 PR_Lock(&mon->lock); in PR_ExitMonitor()
203 PR_ASSERT(mon->entryCount > 0); in PR_ExitMonitor()
204 PR_ASSERT(mon->owner == me); in PR_ExitMonitor()
205 if (mon->entryCount == 0 || mon->owner != me) in PR_ExitMonitor()
207 rv = PR_Unlock(&mon->lock); in PR_ExitMonitor()
212 mon->entryCount -= 1; /* reduce by one */ in PR_ExitMonitor()
213 if (mon->entryCount == 0) in PR_ExitMonitor()
217 mon->owner = NULL; in PR_ExitMonitor()
218 if (mon->notifyTimes != 0) { in PR_ExitMonitor()
219 _PR_PostNotifiesFromMonitor(&mon->waitCV, mon->notifyTimes); in PR_ExitMonitor()
220 mon->notifyTimes = 0; in PR_ExitMonitor()
222 rv = PR_NotifyCondVar(&mon->entryCV); in PR_ExitMonitor()
225 rv = PR_Unlock(&mon->lock); in PR_ExitMonitor()
234 PR_IMPLEMENT(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon) in PR_GetMonitorEntryCount() argument
240 PR_Lock(&mon->lock); in PR_GetMonitorEntryCount()
241 if (mon->owner == me) { in PR_GetMonitorEntryCount()
242 count = mon->entryCount; in PR_GetMonitorEntryCount()
244 rv = PR_Unlock(&mon->lock); in PR_GetMonitorEntryCount()
249 PR_IMPLEMENT(void) PR_AssertCurrentThreadInMonitor(PRMonitor *mon) in PR_AssertCurrentThreadInMonitor() argument
254 PR_Lock(&mon->lock); in PR_AssertCurrentThreadInMonitor()
255 PR_ASSERT(mon->entryCount != 0 && in PR_AssertCurrentThreadInMonitor()
256 mon->owner == _PR_MD_CURRENT_THREAD()); in PR_AssertCurrentThreadInMonitor()
257 rv = PR_Unlock(&mon->lock); in PR_AssertCurrentThreadInMonitor()
279 PR_IMPLEMENT(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime ticks) in PR_Wait() argument
285 PR_ASSERT(mon != NULL); in PR_Wait()
286 PR_Lock(&mon->lock); in PR_Wait()
288 PR_ASSERT(mon->entryCount > 0); in PR_Wait()
290 PR_ASSERT(mon->owner == _PR_MD_CURRENT_THREAD()); /* XXX return failure */ in PR_Wait()
293 saved_entries = mon->entryCount; in PR_Wait()
294 mon->entryCount = 0; in PR_Wait()
295 saved_owner = mon->owner; in PR_Wait()
296 mon->owner = NULL; in PR_Wait()
298 if (mon->notifyTimes != 0) { in PR_Wait()
299 _PR_PostNotifiesFromMonitor(&mon->waitCV, mon->notifyTimes); in PR_Wait()
300 mon->notifyTimes = 0; in PR_Wait()
302 rv = PR_NotifyCondVar(&mon->entryCV); in PR_Wait()
305 rv = PR_WaitCondVar(&mon->waitCV, ticks); in PR_Wait()
308 while (mon->entryCount != 0) { in PR_Wait()
309 rv = PR_WaitCondVar(&mon->entryCV, PR_INTERVAL_NO_TIMEOUT); in PR_Wait()
312 PR_ASSERT(mon->notifyTimes == 0); in PR_Wait()
314 mon->entryCount = saved_entries; in PR_Wait()
315 mon->owner = saved_owner; in PR_Wait()
317 rv = PR_Unlock(&mon->lock); in PR_Wait()
327 PR_IMPLEMENT(PRStatus) PR_Notify(PRMonitor *mon) in PR_Notify() argument
329 _PR_PostNotifyToMonitor(mon, PR_FALSE); in PR_Notify()
338 PR_IMPLEMENT(PRStatus) PR_NotifyAll(PRMonitor *mon) in PR_NotifyAll() argument
340 _PR_PostNotifyToMonitor(mon, PR_TRUE); in PR_NotifyAll()
346 PRUint32 _PR_MonitorToString(PRMonitor *mon, char *buf, PRUint32 buflen) in _PR_MonitorToString() argument
350 if (mon->owner) { in _PR_MonitorToString()
352 mon, mon->owner->id, mon->owner, mon->entryCount); in _PR_MonitorToString()
354 nb = PR_snprintf(buf, buflen, "[%p]", mon); in _PR_MonitorToString()