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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
<HTML><HEAD><TITLE>Mutex Class</TITLE></HEAD>
<BODY bgcolor="#ffffff">
<H1>Mutex Class Reference</H1>
<p>
[<A HREF="index.html">APE Index</A>] [<A HREF="hier.html">APE Hierarchy</A>]
[<A HREF="header-list.html">Headers</A>]
</p>
<HR>
<P>Mutex lock for protected access. <a href="#short">More...</a></P>
<P>
<code>
#include <<a href="thread-h.html">thread.h</a>>
</code>
</P>
<H2>Public Members</H2>
<UL>
<LI> <b><a href="#ref0">Mutex</a></b> ()
</LI>
<LI> <b><a href="#ref1">~Mutex</a></b> ()
</LI>
<LI>inline void <b><a href="#ref2">EnterMutex</a></b> (void)
</LI>
<LI>void <b><a name="ref3">EnterMutex</a></b> (void)
</LI>
<LI>inline void <b><a href="#ref4">LeaveMutex</a></b> (void)
</LI>
<LI>void <b><a name="ref5">LeaveMutex</a></b> (void)
</LI>
</UL>
<H2>Protected Members</H2>
<UL>
<LI> pthread_mutex_t <b><a href="#ref6">_mutex</a></b>
</LI>
</UL>
<HR>
<H2><a name="short">Detailed Description</a></H2>
<P>
The Mutex class is used to protect a section of code so that at any
given time only a single thread can perform the protected operation.
The APE Mutex is always recursive in that if the same thread invokes
the same mutex lock multiple times, it must release it multiple times.
This allows a function to call another function which also happens to
use the same mutex lock when called directly.
The Mutex can be used as a base class to protect access in a derived
class. When used in this manner, the ENTER_CRITICAL and LEAVE_CRITICAL
macros can be used to specify when code written for the derived class
needs to be protected by the default Mutex of the derived class, and
hence is presumed to be 'thread safe' from multiple instance execution.
</P><HR>
<H3><b> <a name="ref0"></a><a name="Mutex">Mutex</a>() </b><code>[public]</code></H3>
<p>The mutex is always initialized as a recursive entity.
</p>
<H3><b> <a name="ref1"></a><a name="~Mutex">~Mutex</a>() </b><code>[public]</code></H3>
<p>Destroying the mutex removes any system resources associated
with it. If a mutex lock is currently in place, it is presumed
to terminate when the Mutex is destroyed.
</p>
<H3><b>inline void <a name="ref2"></a><a name="EnterMutex">EnterMutex</a>(void) </b><code>[public]</code></H3>
<p>Entering a Mutex locks the mutex for the current thread. This
also can be done using the ENTER_CRITICAL macro or by using the
++ operator on a mutex.
</p><p>
</p>
<dl><dt><b>See Also</b>:<dd><a href="Mutex.html#LeaveMutex">LeaveMutex</a></dl>
<H3><b>inline void <a name="ref4"></a><a name="LeaveMutex">LeaveMutex</a>(void) </b><code>[public]</code></H3>
<p>Leaving a mutex frees that mutex for use by another thread. If
the mutex has been entered (invoked) multiple times (recursivily)
by the same thread, then it will need to be exited the same number
of instances before it is free for re-use. This operation can
also be done using the LEAVE_CRITICAL macro or by the -- operator
on a mutex.
</p><p>
</p>
<dl><dt><b>See Also</b>:<dd><a href="Mutex.html#EnterMutex">EnterMutex</a></dl>
<H3><b> pthread_mutex_t <a name="ref6"></a><a name="_mutex">_mutex</a></b><code>[protected]</code></H3>
<p>Pthread mutex object. This is protected rather than private
because some mixed mode pthread operations require a mutex as
well as their primary pthread object. A good example of this
is the Event class, as waiting on a conditional object must be
associated with an accessable mutex. An alternative would be
to make such classes "friend" classes of the Mutex.
</p>
<HR>
<TABLE WIDTH="100%"><TR><TD ALIGN="left" VALIGN="top">
<UL><LI><I>Author</I>: David Sugar <dyfet@ostel.com> </LI>
<LI>Documentation generated by dyfet@home.sys on Thu Dec 16 09:54:26 EST 1999
</LI>
</UL></TD><TD ALIGN="RIGHT" VALIGN="TOP">
<b>K</b><i>doc</i>
</TD>
</TR></TABLE></BODY></HTML>
|