Fix Centurion name.
[0ad.git] / libraries / source / spidermonkey / include-win32-debug / nspr / prmon.h
blob8bfee3dda1f7953baa220ab7f4a1f5080a210864
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef prmon_h___
7 #define prmon_h___
9 #include "prtypes.h"
10 #include "prinrval.h"
12 PR_BEGIN_EXTERN_C
14 typedef struct PRMonitor PRMonitor;
17 ** Create a new monitor. Monitors are re-entrant locks with a single built-in
18 ** condition variable.
20 ** This may fail if memory is tight or if some operating system resource
21 ** is low.
23 NSPR_API(PRMonitor*) PR_NewMonitor(void);
26 ** Destroy a monitor. The caller is responsible for guaranteeing that the
27 ** monitor is no longer in use. There must be no thread waiting on the monitor's
28 ** condition variable and that the lock is not held.
31 NSPR_API(void) PR_DestroyMonitor(PRMonitor *mon);
34 ** Enter the lock associated with the monitor. If the calling thread currently
35 ** is in the monitor, the call to enter will silently succeed. In either case,
36 ** it will increment the entry count by one.
38 NSPR_API(void) PR_EnterMonitor(PRMonitor *mon);
41 ** Decrement the entry count associated with the monitor. If the decremented
42 ** entry count is zero, the monitor is exited. Returns PR_FAILURE if the
43 ** calling thread has not entered the monitor.
45 NSPR_API(PRStatus) PR_ExitMonitor(PRMonitor *mon);
48 ** Wait for a notify on the monitor's condition variable. Sleep for "ticks"
49 ** amount of time (if "ticks" is PR_INTERVAL_NO_TIMEOUT then the sleep is
50 ** indefinite).
52 ** While the thread is waiting it exits the monitor (as if it called
53 ** PR_ExitMonitor as many times as it had called PR_EnterMonitor). When
54 ** the wait has finished the thread regains control of the monitors lock
55 ** with the same entry count as before the wait began.
57 ** The thread waiting on the monitor will be resumed when the monitor is
58 ** notified (assuming the thread is the next in line to receive the
59 ** notify) or when the "ticks" timeout elapses.
61 ** Returns PR_FAILURE if the caller has not entered the monitor.
63 NSPR_API(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime ticks);
66 ** Notify a thread waiting on the monitor's condition variable. If a thread
67 ** is waiting on the condition variable (using PR_Wait) then it is awakened
68 ** and attempts to reenter the monitor.
70 NSPR_API(PRStatus) PR_Notify(PRMonitor *mon);
73 ** Notify all of the threads waiting on the monitor's condition variable.
74 ** All of threads waiting on the condition are scheduled to reenter the
75 ** monitor.
77 NSPR_API(PRStatus) PR_NotifyAll(PRMonitor *mon);
80 ** PR_ASSERT_CURRENT_THREAD_IN_MONITOR
81 ** If the current thread is in |mon|, this assertion is guaranteed to
82 ** succeed. Otherwise, the behavior of this function is undefined.
84 #if defined(DEBUG) || defined(FORCE_PR_ASSERT)
85 #define PR_ASSERT_CURRENT_THREAD_IN_MONITOR(/* PRMonitor* */ mon) \
86 PR_AssertCurrentThreadInMonitor(mon)
87 #else
88 #define PR_ASSERT_CURRENT_THREAD_IN_MONITOR(/* PRMonitor* */ mon)
89 #endif
91 /* Don't call this function directly. */
92 NSPR_API(void) PR_AssertCurrentThreadInMonitor(PRMonitor *mon);
94 PR_END_EXTERN_C
96 #endif /* prmon_h___ */