summaryrefslogtreecommitdiffstats
path: root/docs/nspr/reference/pr_waitcondvar.rst
blob: f915464f7b2669bf96077f27aea9eda7ce079449 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
PR_WaitCondVar
==============

Waits on a condition.


Syntax
------

.. code::

   #include <prcvar.h>

   PRStatus PR_WaitCondVar(
     PRCondVar *cvar,
     PRIntervalTime timeout);


Parameters
~~~~~~~~~~

:ref:`PR_WaitCondVar` has the following parameters:

``cvar``
   The condition variable on which to wait.
``timeout``
   The value ``PR_INTERVAL_NO_TIMEOUT`` requires that a condition be
   notified (or the thread interrupted) before it will resume from the
   wait. The value ``PR_INTERVAL_NO_WAIT`` causes the thread to release
   the lock, possibly causing a rescheduling within the runtime, then
   immediately attempt to reacquire the lock and resume.


Returns
~~~~~~~

The function returns one of the following values:

-  If successful, ``PR_SUCCESS``.
-  If unsuccessful (for example, if the caller has not locked the lock
   associated with the condition variable or the thread was interrupted
   with :ref:`PR_Interrupt`), ``PR_FAILURE``. The details can be determined
   with :ref:`PR_GetError`.


Description
-----------

Before the call to :ref:`PR_WaitCondVar`, the lock associated with the
condition variable must be held by the calling thread. After a call to
:ref:`PR_WaitCondVar`, the lock is released and the thread is blocked in a
"waiting on condition" state until another thread notifies the condition
or a caller-specified amount of time expires.

When the condition variable is notified, a thread waiting on that
condition moves from the "waiting on condition" state to the "ready"
state. When scheduled, the thread attempts to reacquire the lock that it
held when :ref:`PR_WaitCondVar` was called.

Any value other than ``PR_INTERVAL_NO_TIMEOUT`` or
``PR_INTERVAL_NO_WAIT`` for the timeout parameter will cause the thread
to be rescheduled due to either explicit notification or the expiration
of the specified interval. The latter must be determined by treating
time as one part of the monitored data being protected by the lock and
tested explicitly for an expired interval. To detect the expiration of
the specified interval, call :ref:`PR_IntervalNow` before and after the
call to :ref:`PR_WaitCondVar` and compare the elapsed time with the
specified interval.