summaryrefslogtreecommitdiffstats
path: root/docs/nspr/reference/pr_centermonitor.rst
blob: 8c135f844e278cc4aeb240d52707671a178b553b (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
PR_CEnterMonitor
================

Enters the lock associated with a cached monitor.


Syntax
------

.. code::

   #include <prcmon.h>

   PRMonitor* PR_CEnterMonitor(void *address);


Parameter
~~~~~~~~~

The function has the following parameter:

``address``
   A reference to the data that is to be protected by the monitor. This
   reference must remain valid as long as there are monitoring
   operations being performed.


Returns
~~~~~~~

The function returns one of the following values:

-  If successful, the function returns a pointer to the :ref:`PRMonitor`
   associated with the value specified in the ``address`` parameter.
-  If unsuccessful (the monitor cache needs to be expanded and the
   system is out of memory), the function returns ``NULL``.


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

:ref:`PR_CEnterMonitor` uses the value specified in the ``address``
parameter to find a monitor in the monitor cache, then enters the lock
associated with the monitor. If no match is found, an available monitor
is associated with the address and the monitor's entry count is
incremented (so it has a value of one). If a match is found, then either
the calling thread is already in the monitor (and this is a reentrant
call) or another thread is holding the monitor's mutex. In the former
case, the entry count is simply incremented and the function returns. In
the latter case, the calling thread is likely to find the monitor locked
by another thread and waits for that thread to exit before continuing.

.. note::

   **Note**: :ref:`PR_CEnterMonitor` and :ref:`PR_CExitMonitor` must be
   paired--that is, there must be an exit for every entry--or the object
   will never become available for any other thread.