Files
rtabmap/api/latest/classUScopeMutex.html
T

396 lines
21 KiB
HTML

<!-- HTML header for doxygen 1.9.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>RTAB-Map: UScopeMutex Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
<link href="custom.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">window.RTABMAP_DOC_ROOT="";</script>
<script type="text/javascript" src="../versions.js"></script>
<script type="text/javascript" src="version-switcher.js"></script>
<script type="text/javascript" src="doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript">DoxygenAwesomeDarkModeToggle.init();</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">RTAB-Map<span id="projectnumber">&#160;0.23.13</span>
</div>
<div id="projectbrief">Real-Time Appearance-Based Mapping</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('classUScopeMutex.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classUScopeMutex-members.html">List of all members</a> </div>
<div class="headertitle"><div class="title">UScopeMutex Class Reference</div></div>
</div><!--header-->
<div class="contents">
<p><code>#include &lt;<a class="el" href="UMutex_8h_source.html">UMutex.h</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a0edb03132a8182e53bb0c5e960fd2a4b" id="r_a0edb03132a8182e53bb0c5e960fd2a4b"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classUScopeMutex.html#a0edb03132a8182e53bb0c5e960fd2a4b">UScopeMutex</a> (const <a class="el" href="classUMutex.html">UMutex</a> &amp;mutex, bool lockNow=true)</td></tr>
<tr class="separator:a0edb03132a8182e53bb0c5e960fd2a4b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aec8a249b8238c90ff7cdd6dea01afb58" id="r_aec8a249b8238c90ff7cdd6dea01afb58"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classUScopeMutex.html#aec8a249b8238c90ff7cdd6dea01afb58">UScopeMutex</a> (<a class="el" href="classUMutex.html">UMutex</a> *mutex)</td></tr>
<tr class="separator:aec8a249b8238c90ff7cdd6dea01afb58"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a39bf03b3225db08d8a07da0777aee5f5" id="r_a39bf03b3225db08d8a07da0777aee5f5"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classUScopeMutex.html#a39bf03b3225db08d8a07da0777aee5f5">~UScopeMutex</a> ()</td></tr>
<tr class="separator:a39bf03b3225db08d8a07da0777aee5f5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6515d46f7117d390679f9bf79273488e" id="r_a6515d46f7117d390679f9bf79273488e"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classUScopeMutex.html#a6515d46f7117d390679f9bf79273488e">lock</a> () &amp;</td></tr>
<tr class="separator:a6515d46f7117d390679f9bf79273488e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab5520a99fb161894c6354d3772b819af" id="r_ab5520a99fb161894c6354d3772b819af"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classUScopeMutex.html#ab5520a99fb161894c6354d3772b819af">lockTry</a> () &amp;</td></tr>
<tr class="separator:ab5520a99fb161894c6354d3772b819af"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a05eed5425e47144d045c5376e7087248" id="r_a05eed5425e47144d045c5376e7087248"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classUScopeMutex.html#a05eed5425e47144d045c5376e7087248">unlock</a> () &amp;</td></tr>
<tr class="separator:a05eed5425e47144d045c5376e7087248"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a09b8bde74967224b7a050eca317c79e7" id="r_a09b8bde74967224b7a050eca317c79e7"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classUScopeMutex.html#a09b8bde74967224b7a050eca317c79e7">isLocked</a> () const</td></tr>
<tr class="separator:a09b8bde74967224b7a050eca317c79e7"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Automatically lock the referenced mutex on constructor and unlock mutex on destructor.</p>
<p>Example: </p><div class="fragment"><div class="line"><a class="code hl_class" href="classUMutex.html">UMutex</a> m; <span class="comment">// Mutex shared with another thread(s).</span></div>
<div class="line">...</div>
<div class="line">int myMethod()</div>
<div class="line">{</div>
<div class="line"> <a class="code hl_class" href="classUScopeMutex.html">UScopeMutex</a> sm(m); <span class="comment">// automatically lock the mutex m</span></div>
<div class="line"> <span class="keywordflow">if</span>(cond1)</div>
<div class="line"> {</div>
<div class="line"> <span class="keywordflow">return</span> 1; <span class="comment">// automatically unlock the mutex m</span></div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span>(cond2)</div>
<div class="line"> {</div>
<div class="line"> <span class="keywordflow">return</span> 2; <span class="comment">// automatically unlock the mutex m</span></div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">return</span> 0; <span class="comment">// automatically unlock the mutex m</span></div>
<div class="line">}</div>
<div class="ttc" id="aclassUMutex_html"><div class="ttname"><a href="classUMutex.html">UMutex</a></div><div class="ttdef"><b>Definition</b> <a href="UMutex_8h_source.html#l00054">UMutex.h:55</a></div></div>
<div class="ttc" id="aclassUScopeMutex_html"><div class="ttname"><a href="classUScopeMutex.html">UScopeMutex</a></div><div class="ttdef"><b>Definition</b> <a href="UMutex_8h_source.html#l00193">UMutex.h:194</a></div></div>
</div><!-- fragment --><p>The lock can also be deferred, for example to only try locking it. The destructor then unlocks the mutex only if this object locked it: </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> callback()</div>
<div class="line">{</div>
<div class="line"> <a class="code hl_class" href="classUScopeMutex.html">UScopeMutex</a> sm(m, <span class="keyword">false</span>); <span class="comment">// not locked yet</span></div>
<div class="line"> <span class="keywordflow">if</span>(sm.lockTry() == 0)</div>
<div class="line"> {</div>
<div class="line"> <span class="keywordflow">if</span>(cond1)</div>
<div class="line"> {</div>
<div class="line"> <span class="keywordflow">return</span>; <span class="comment">// automatically unlock the mutex m</span></div>
<div class="line"> }</div>
<div class="line"> ...</div>
<div class="line"> }</div>
<div class="line"> <span class="comment">// the mutex m is unlocked only if lockTry() succeeded</span></div>
<div class="line">}</div>
</div><!-- fragment --><p>The object must be named: a temporary would be destroyed, and the mutex unlocked, at the end of the expression. <a class="el" href="classUScopeMutex.html#a6515d46f7117d390679f9bf79273488e">lock()</a>, <a class="el" href="classUScopeMutex.html#ab5520a99fb161894c6354d3772b819af">lockTry()</a> and <a class="el" href="classUScopeMutex.html#a05eed5425e47144d045c5376e7087248">unlock()</a> can only be called on a named object, so that <code>if(<a class="el" href="classUScopeMutex.html">UScopeMutex(m, false)</a>.<a class="el" href="classUScopeMutex.html#ab5520a99fb161894c6354d3772b819af">lockTry()</a> == 0)</code> doesn't compile. In C++17, the object can be scoped to an if statement instead: </p><div class="fragment"><div class="line"><span class="keywordflow">if</span>(<a class="code hl_class" href="classUScopeMutex.html">UScopeMutex</a> sm(m, <span class="keyword">false</span>); sm.<a class="code hl_function" href="classUScopeMutex.html#ab5520a99fb161894c6354d3772b819af">lockTry</a>() == 0)</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// locked here</span></div>
<div class="line">} <span class="comment">// unlocked here, only if lockTry() succeeded</span></div>
<div class="ttc" id="aclassUScopeMutex_html_ab5520a99fb161894c6354d3772b819af"><div class="ttname"><a href="classUScopeMutex.html#ab5520a99fb161894c6354d3772b819af">UScopeMutex::lockTry</a></div><div class="ttdeci">int lockTry() &amp;</div><div class="ttdef"><b>Definition</b> <a href="UMutex_8h_source.html#l00246">UMutex.h:246</a></div></div>
</div><!-- fragment --><dl class="section see"><dt>See also</dt><dd><a class="el" href="classUMutex.html">UMutex</a> </dd></dl>
<p class="definition">Definition at line <a class="el" href="UMutex_8h_source.html#l00193">193</a> of file <a class="el" href="UMutex_8h_source.html">UMutex.h</a>.</p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a0edb03132a8182e53bb0c5e960fd2a4b" name="a0edb03132a8182e53bb0c5e960fd2a4b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0edb03132a8182e53bb0c5e960fd2a4b">&#9670;&#160;</a></span>UScopeMutex() <span class="overload">[1/2]</span></h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">UScopeMutex::UScopeMutex </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classUMutex.html">UMutex</a> &amp;&#160;</td>
<td class="paramname"><em>mutex</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">bool&#160;</td>
<td class="paramname"><em>lockNow</em> = <code>true</code>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">mutex</td><td>the mutex to lock. </td></tr>
<tr><td class="paramname">lockNow</td><td>if true (default), the mutex is locked here. If false, it is not locked until <a class="el" href="classUScopeMutex.html#a6515d46f7117d390679f9bf79273488e">lock()</a> or <a class="el" href="classUScopeMutex.html#ab5520a99fb161894c6354d3772b819af">lockTry()</a> is called. </td></tr>
</table>
</dd>
</dl>
<p class="definition">Definition at line <a class="el" href="UMutex_8h_source.html#l00201">201</a> of file <a class="el" href="UMutex_8h_source.html">UMutex.h</a>.</p>
</div>
</div>
<a id="aec8a249b8238c90ff7cdd6dea01afb58" name="aec8a249b8238c90ff7cdd6dea01afb58"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aec8a249b8238c90ff7cdd6dea01afb58">&#9670;&#160;</a></span>UScopeMutex() <span class="overload">[2/2]</span></h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">UScopeMutex::UScopeMutex </td>
<td>(</td>
<td class="paramtype"><a class="el" href="classUMutex.html">UMutex</a> *&#160;</td>
<td class="paramname"><em>mutex</em></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p class="definition">Definition at line <a class="el" href="UMutex_8h_source.html#l00211">211</a> of file <a class="el" href="UMutex_8h_source.html">UMutex.h</a>.</p>
</div>
</div>
<a id="a39bf03b3225db08d8a07da0777aee5f5" name="a39bf03b3225db08d8a07da0777aee5f5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a39bf03b3225db08d8a07da0777aee5f5">&#9670;&#160;</a></span>~UScopeMutex()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">UScopeMutex::~UScopeMutex </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Unlock the mutex, only if this object locked it. </p>
<p class="definition">Definition at line <a class="el" href="UMutex_8h_source.html#l00220">220</a> of file <a class="el" href="UMutex_8h_source.html">UMutex.h</a>.</p>
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a6515d46f7117d390679f9bf79273488e" name="a6515d46f7117d390679f9bf79273488e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6515d46f7117d390679f9bf79273488e">&#9670;&#160;</a></span>lock()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">int UScopeMutex::lock </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> &amp;</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Lock the mutex, if this object doesn't hold it already. </p><dl class="section return"><dt>Returns</dt><dd>0 on success, an error code otherwise. </dd></dl>
<p class="definition">Definition at line <a class="el" href="UMutex_8h_source.html#l00229">229</a> of file <a class="el" href="UMutex_8h_source.html">UMutex.h</a>.</p>
</div>
</div>
<a id="ab5520a99fb161894c6354d3772b819af" name="ab5520a99fb161894c6354d3772b819af"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab5520a99fb161894c6354d3772b819af">&#9670;&#160;</a></span>lockTry()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">int UScopeMutex::lockTry </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> &amp;</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Try locking the mutex, if this object doesn't hold it already. </p><dl class="section return"><dt>Returns</dt><dd>0 if the mutex is held by this object, EBUSY (or another error code) otherwise. </dd></dl>
<p class="definition">Definition at line <a class="el" href="UMutex_8h_source.html#l00246">246</a> of file <a class="el" href="UMutex_8h_source.html">UMutex.h</a>.</p>
</div>
</div>
<a id="a05eed5425e47144d045c5376e7087248" name="a05eed5425e47144d045c5376e7087248"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a05eed5425e47144d045c5376e7087248">&#9670;&#160;</a></span>unlock()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">int UScopeMutex::unlock </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> &amp;</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Unlock the mutex before this object goes out of scope, only if this object locked it. </p><dl class="section return"><dt>Returns</dt><dd>0 on success (or if this object didn't hold the mutex), an error code otherwise. </dd></dl>
<p class="definition">Definition at line <a class="el" href="UMutex_8h_source.html#l00262">262</a> of file <a class="el" href="UMutex_8h_source.html">UMutex.h</a>.</p>
</div>
</div>
<a id="a09b8bde74967224b7a050eca317c79e7" name="a09b8bde74967224b7a050eca317c79e7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a09b8bde74967224b7a050eca317c79e7">&#9670;&#160;</a></span>isLocked()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">bool UScopeMutex::isLocked </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>true if this object currently holds the mutex. </dd></dl>
<p class="definition">Definition at line <a class="el" href="UMutex_8h_source.html#l00275">275</a> of file <a class="el" href="UMutex_8h_source.html">UMutex.h</a>.</p>
</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li>utilite/include/rtabmap/utilite/<a class="el" href="UMutex_8h_source.html">UMutex.h</a></li>
</ul>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="classUScopeMutex.html">UScopeMutex</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8 </li>
</ul>
</div>
</body>
</html>