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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Loki: Loki::MutexLocker Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li>
<form action="search.php" method="get">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><label> <u>S</u>earch for </label></td>
<td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
</tr>
</table>
</form>
</li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="annotated.html"><span>Class List</span></a></li>
<li><a href="classes.html"><span>Class Index</span></a></li>
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
<li><a href="functions.html"><span>Class Members</span></a></li>
</ul>
</div>
<div class="navpath"><a class="el" href="a00192.html">Loki</a>::<a class="el" href="a00083.html">MutexLocker</a>
</div>
</div>
<div class="contents">
<h1>Loki::MutexLocker Class Reference</h1><!-- doxytag: class="Loki::MutexLocker" --><code>#include <LevelMutex.h></code>
<p>
<div class="dynheader">
Collaboration diagram for Loki::MutexLocker:</div>
<div class="dynsection">
<center><font size="2">[<a target="top" href="graph_legend.html">legend</a>]</font></center></div>
<p>
<a href="a00339.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="a00083.html#ae8699ba4423d83aff277149c9008ec8">MutexLocker</a> (volatile <a class="el" href="a00071.html">LevelMutexInfo</a> &mutex, bool lock=true)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="a00083.html#aeffc60518694479ac9985ee1878ed0f">MutexLocker</a> (volatile <a class="el" href="a00071.html">LevelMutexInfo</a> &mutex, unsigned int milliSeconds, bool lock=true)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="bab99d9acf93e5add22deb8cf7d04a09"></a><!-- doxytag: member="Loki::MutexLocker::~MutexLocker" ref="bab99d9acf93e5add22deb8cf7d04a09" args="(void)" -->
</td><td class="memItemRight" valign="bottom"><a class="el" href="a00083.html#bab99d9acf93e5add22deb8cf7d04a09">~MutexLocker</a> (void)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Destructs the locker, and determines if it needs to unlock the mutex. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="a00083.html#c929c01961dc1b2a2ee1a39333a79c0b">Lock</a> (void)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="a00083.html#f5ea31fe3fac046cf646722cc8befa09">Unlock</a> (void)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="231de9c6db22151209ab2537fc45c65e"></a><!-- doxytag: member="Loki::MutexLocker::IsLocked" ref="231de9c6db22151209ab2537fc45c65e" args="(void) const " -->
bool </td><td class="memItemRight" valign="bottom"><a class="el" href="a00083.html#231de9c6db22151209ab2537fc45c65e">IsLocked</a> (void) const </td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Returns true if the mutex is locked by this object. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="2b49f0c689ff6cb8e29f2d8963b041df"></a><!-- doxytag: member="Loki::MutexLocker::GetMutex" ref="2b49f0c689ff6cb8e29f2d8963b041df" args="(void) const " -->
const volatile <a class="el" href="a00071.html">LevelMutexInfo</a> & </td><td class="memItemRight" valign="bottom"><a class="el" href="a00083.html#2b49f0c689ff6cb8e29f2d8963b041df">GetMutex</a> (void) const </td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Provides access to mutex controlled by this. <br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
You can place an instance of this as a local variable inside a function to lock a single mutex. It will lock the mutex if no error occurs, or throw if one does happen. When the function ends, the destructor will determine if it needs to unlock the mutex. This RAII technique insures the mutex gets unlocked even when exceptions occur. <hr><h2>Constructor & Destructor Documentation</h2>
<a class="anchor" name="ae8699ba4423d83aff277149c9008ec8"></a><!-- doxytag: member="Loki::MutexLocker::MutexLocker" ref="ae8699ba4423d83aff277149c9008ec8" args="(volatile LevelMutexInfo &mutex, bool lock=true)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">Loki::MutexLocker::MutexLocker </td>
<td>(</td>
<td class="paramtype">volatile <a class="el" href="a00071.html">LevelMutexInfo</a> & </td>
<td class="paramname"> <em>mutex</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">bool </td>
<td class="paramname"> <em>lock</em> = <code>true</code></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td><code> [explicit]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Creates an object to lock an unlock a mutex for a function. This will throw if an attempt to lock the mutex fails. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>mutex</em> </td><td>Reference to the mutex. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>lock</em> </td><td>True if function wants to lock the mutex as this gets constructed. </td></tr>
</table>
</dl>
<p>References <a class="el" href="a00243.html#l00208">Loki::LevelMutexInfo::GetLevel()</a>, and <a class="el" href="a00071.html#c0e21e08ee9974533a4da5008452bd04">Loki::LevelMutexInfo::Lock()</a>.</p>
<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>
</div>
</div><p>
<a class="anchor" name="aeffc60518694479ac9985ee1878ed0f"></a><!-- doxytag: member="Loki::MutexLocker::MutexLocker" ref="aeffc60518694479ac9985ee1878ed0f" args="(volatile LevelMutexInfo &mutex, unsigned int milliSeconds, bool lock=true)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">Loki::MutexLocker::MutexLocker </td>
<td>(</td>
<td class="paramtype">volatile <a class="el" href="a00071.html">LevelMutexInfo</a> & </td>
<td class="paramname"> <em>mutex</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">unsigned int </td>
<td class="paramname"> <em>milliSeconds</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">bool </td>
<td class="paramname"> <em>lock</em> = <code>true</code></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Creates an object to lock an unlock a mutex for a function. This waits a specified amount of time for another thread to unlock the mutex if it is locked. This will throw if an attempt to lock the mutex fails. <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>mutex</em> </td><td>Reference to the mutex. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>milliSeconds</em> </td><td>Amount of time to wait for another thread to unlock the mutex. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>lock</em> </td><td>True if function wants to lock the mutex as this gets constructed. </td></tr>
</table>
</dl>
<p>References <a class="el" href="a00243.html#l00208">Loki::LevelMutexInfo::GetLevel()</a>, and <a class="el" href="a00071.html#c0e21e08ee9974533a4da5008452bd04">Loki::LevelMutexInfo::Lock()</a>.</p>
<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>
</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="c929c01961dc1b2a2ee1a39333a79c0b"></a><!-- doxytag: member="Loki::MutexLocker::Lock" ref="c929c01961dc1b2a2ee1a39333a79c0b" args="(void)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool Loki::MutexLocker::Lock </td>
<td>(</td>
<td class="paramtype">void </td>
<td class="paramname"> </td>
<td> ) </td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
You can call this to lock (or relock) a mutex. In theory, you can lock and unlock a mutex several times within a function in order to give other threads access to a resource while this function does not need it. <dl class="return" compact><dt><b>Returns:</b></dt><dd>True if mutex is locked by this, else false if not locked. </dd></dl>
<p>References <a class="el" href="a00071.html#c0e21e08ee9974533a4da5008452bd04">Loki::LevelMutexInfo::Lock()</a>.</p>
<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>
</div>
</div><p>
<a class="anchor" name="f5ea31fe3fac046cf646722cc8befa09"></a><!-- doxytag: member="Loki::MutexLocker::Unlock" ref="f5ea31fe3fac046cf646722cc8befa09" args="(void)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool Loki::MutexLocker::Unlock </td>
<td>(</td>
<td class="paramtype">void </td>
<td class="paramname"> </td>
<td> ) </td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
You can call this to unlock a mutex before the destructor does it. By unlocking the mutexes before returning, the function can do other operations without making other threads wait too long. <dl class="return" compact><dt><b>Returns:</b></dt><dd>True if unlocked by this, else false if not unlocked by this. (Which is not the same as whether the mutex itself is locked or not by another thread.) </dd></dl>
<p>References <a class="el" href="a00071.html#01c9af5cb0f6870585b864b4557e9242">Loki::LevelMutexInfo::Unlock()</a>.</p>
<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>
</div>
</div><p>
<hr>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="a00158.html">LevelMutex.h</a><li><a class="el" href="a00157.html">LevelMutex.cpp</a></ul>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 29 18:51:43 2009 for Loki by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>
|