nsprpub/pr/include/prmon.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/include/prmon.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef prmon_h___
    1.10 +#define prmon_h___
    1.11 +
    1.12 +#include "prtypes.h"
    1.13 +#include "prinrval.h"
    1.14 +
    1.15 +PR_BEGIN_EXTERN_C
    1.16 +
    1.17 +typedef struct PRMonitor PRMonitor;
    1.18 +
    1.19 +/*
    1.20 +** Create a new monitor. Monitors are re-entrant locks with a single built-in
    1.21 +** condition variable.
    1.22 +**
    1.23 +** This may fail if memory is tight or if some operating system resource
    1.24 +** is low.
    1.25 +*/
    1.26 +NSPR_API(PRMonitor*) PR_NewMonitor(void);
    1.27 +
    1.28 +/*
    1.29 +** Destroy a monitor. The caller is responsible for guaranteeing that the
    1.30 +** monitor is no longer in use. There must be no thread waiting on the monitor's
    1.31 +** condition variable and that the lock is not held.
    1.32 +**
    1.33 +*/
    1.34 +NSPR_API(void) PR_DestroyMonitor(PRMonitor *mon);
    1.35 +
    1.36 +/*
    1.37 +** Enter the lock associated with the monitor. If the calling thread currently
    1.38 +** is in the monitor, the call to enter will silently succeed. In either case,
    1.39 +** it will increment the entry count by one.
    1.40 +*/
    1.41 +NSPR_API(void) PR_EnterMonitor(PRMonitor *mon);
    1.42 +
    1.43 +/*
    1.44 +** Decrement the entry count associated with the monitor. If the decremented
    1.45 +** entry count is zero, the monitor is exited. Returns PR_FAILURE if the
    1.46 +** calling thread has not entered the monitor.
    1.47 +*/
    1.48 +NSPR_API(PRStatus) PR_ExitMonitor(PRMonitor *mon);
    1.49 +
    1.50 +/*
    1.51 +** Wait for a notify on the monitor's condition variable. Sleep for "ticks"
    1.52 +** amount of time (if "ticks" is PR_INTERVAL_NO_TIMEOUT then the sleep is
    1.53 +** indefinite).
    1.54 +**
    1.55 +** While the thread is waiting it exits the monitor (as if it called
    1.56 +** PR_ExitMonitor as many times as it had called PR_EnterMonitor).  When
    1.57 +** the wait has finished the thread regains control of the monitors lock
    1.58 +** with the same entry count as before the wait began.
    1.59 +**
    1.60 +** The thread waiting on the monitor will be resumed when the monitor is
    1.61 +** notified (assuming the thread is the next in line to receive the
    1.62 +** notify) or when the "ticks" timeout elapses.
    1.63 +**
    1.64 +** Returns PR_FAILURE if the caller has not entered the monitor.
    1.65 +*/
    1.66 +NSPR_API(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime ticks);
    1.67 +
    1.68 +/*
    1.69 +** Notify a thread waiting on the monitor's condition variable. If a thread
    1.70 +** is waiting on the condition variable (using PR_Wait) then it is awakened
    1.71 +** and attempts to reenter the monitor.
    1.72 +*/
    1.73 +NSPR_API(PRStatus) PR_Notify(PRMonitor *mon);
    1.74 +
    1.75 +/*
    1.76 +** Notify all of the threads waiting on the monitor's condition variable.
    1.77 +** All of threads waiting on the condition are scheduled to reenter the
    1.78 +** monitor.
    1.79 +*/
    1.80 +NSPR_API(PRStatus) PR_NotifyAll(PRMonitor *mon);
    1.81 +
    1.82 +/*
    1.83 +** PR_ASSERT_CURRENT_THREAD_IN_MONITOR
    1.84 +** If the current thread is in |mon|, this assertion is guaranteed to
    1.85 +** succeed.  Otherwise, the behavior of this function is undefined.
    1.86 +*/
    1.87 +#if defined(DEBUG) || defined(FORCE_PR_ASSERT)
    1.88 +#define PR_ASSERT_CURRENT_THREAD_IN_MONITOR(/* PRMonitor* */ mon) \
    1.89 +    PR_AssertCurrentThreadInMonitor(mon)
    1.90 +#else
    1.91 +#define PR_ASSERT_CURRENT_THREAD_IN_MONITOR(/* PRMonitor* */ mon)
    1.92 +#endif
    1.93 +
    1.94 +/* Don't call this function directly. */
    1.95 +NSPR_API(void) PR_AssertCurrentThreadInMonitor(PRMonitor *mon);
    1.96 +
    1.97 +PR_END_EXTERN_C
    1.98 +
    1.99 +#endif /* prmon_h___ */

mercurial