<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>mrpt::synch::CSemaphore Class Reference</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <div align="left"><a href="http://www.mrpt.org/">Main MRPT website</a> > <b>C++ reference</b> </div> <div align="right"> <a href="index.html"><img border="0" src="mrpt_logo.png" alt="MRPT logo"></a> </div> <!-- Generated by Doxygen 1.7.5 --> <script type="text/javascript"> var searchBox = new SearchBox("searchBox", "search",false,'Search'); </script> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</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> <div id="MSearchBox" class="MSearchBoxInactive"> <div class="left"> <form id="FSearchBox" action="search.php" method="get"> <img id="MSearchSelect" src="search/mag.png" alt=""/> <input type="text" id="MSearchField" name="query" value="Search" size="20" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)"/> </form> </div><div class="right"></div> </div> </li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <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="inherits.html"><span>Class Hierarchy</span></a></li> <li><a href="functions.html"><span>Class Members</span></a></li> </ul> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="namespacemrpt.html">mrpt</a> </li> <li class="navelem"><a class="el" href="namespacemrpt_1_1synch.html">synch</a> </li> <li class="navelem"><a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html">CSemaphore</a> </li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="#pub-methods">Public Member Functions</a> | <a href="#pro-attribs">Protected Attributes</a> </div> <div class="headertitle"> <div class="title">mrpt::synch::CSemaphore Class Reference<div class="ingroups"><a class="el" href="group__synch__grp.html">Synchronization, multi-threading synch tools</a></div></div> </div> </div> <div class="contents"> <!-- doxytag: class="mrpt::synch::CSemaphore" --><hr/><a name="details" id="details"></a><h2>Detailed Description</h2> <div class="textblock"><p>A semaphore for inter-thread synchronization. </p> <p>The state of a semaphore object is signaled when its count is greater than zero, and nonsignaled when its count is equal to zero. The initialCount parameter specifies the initial count. Each time a waiting thread is released because of the semaphore's signaled state, the count of the semaphore is decreased by one. Use the release function to increment a semaphore's count by a specified amount. The count can never be less than zero or greater than the value specified in the maxCount parameter. </p> </div> <p><code>#include <<a class="el" href="_c_semaphore_8h_source.html">mrpt/synch/CSemaphore.h</a>></code></p> <p><a href="classmrpt_1_1synch_1_1_c_semaphore-members.html">List of all members.</a></p> <table class="memberdecls"> <tr><td colspan="2"><h2><a name="pub-methods"></a> Public Member Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html#abc33414f4477e385609e2284e704e669">CSemaphore</a> (unsigned int initialCount, unsigned int maxCount, const <a class="el" href="classstd_1_1string.html">std::string</a> &name=<a class="el" href="classstd_1_1string.html">std::string</a>(""))</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Creates a semaphore. <a href="#abc33414f4477e385609e2284e704e669"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">virtual </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html#a21097aba9e59c22aa6d89554d2977341">~CSemaphore</a> ()</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Destructor. <a href="#a21097aba9e59c22aa6d89554d2977341"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html#ac7df910d79e935db246381e1d2361a52">waitForSignal</a> (unsigned int timeout_ms=0)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Blocks until the count of the semaphore to be non-zero. <a href="#ac7df910d79e935db246381e1d2361a52"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html#af622ff89814558ec46ae98bd7764e97b">release</a> (unsigned int increaseCount=1)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Increments the count of the semaphore by a given amount. <a href="#af622ff89814558ec46ae98bd7764e97b"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classstd_1_1string.html">std::string</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html#aebabb04b45d41e8085a36faefc3778d5">getName</a> () const </td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Get the name of the named semaphore or an empty string if it's unnamed. <a href="#aebabb04b45d41e8085a36faefc3778d5"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html#ad33d2e60018742dd69735da0c6f10931">isNamed</a> () const </td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Return true if this is a named semaphore. <a href="#ad33d2e60018742dd69735da0c6f10931"></a><br/></td></tr> <tr><td colspan="2"><h2><a name="pro-attribs"></a> Protected Attributes</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classmrpt_1_1utils_1_1_c_referenced_mem_block.html">utils::CReferencedMemBlock</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html#a82f71a788dc159ed7bbf5fdd19f138f7">m_data</a></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classstd_1_1string.html">std::string</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html#aa6be1b8896adf5c78ab0f0318cb39b7b">m_name</a></td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">The name of the named semaphore, or empty if unnamed. <a href="#aa6be1b8896adf5c78ab0f0318cb39b7b"></a><br/></td></tr> </table> <hr/><h2>Constructor & Destructor Documentation</h2> <a class="anchor" id="abc33414f4477e385609e2284e704e669"></a><!-- doxytag: member="mrpt::synch::CSemaphore::CSemaphore" ref="abc33414f4477e385609e2284e704e669" args="(unsigned int initialCount, unsigned int maxCount, const std::string &name=std::string(""))" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">mrpt::synch::CSemaphore::CSemaphore </td> <td>(</td> <td class="paramtype">unsigned int </td> <td class="paramname"><em>initialCount</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">unsigned int </td> <td class="paramname"><em>maxCount</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">const <a class="el" href="classstd_1_1string.html">std::string</a> & </td> <td class="paramname"><em>name</em> = <code><a class="el" href="classstd_1_1string.html">std::string</a>("")</code> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>Creates a semaphore. </p> <p>If <em>name</em> is not an empty string, a named semaphore is created. In that case if the semaphore didn't exist it's created. Otherwise, the existing semaphore is linked to this object and then <em>initialCount</em> and <em>maxCount</em> are ignored. </p> </div> </div> <a class="anchor" id="a21097aba9e59c22aa6d89554d2977341"></a><!-- doxytag: member="mrpt::synch::CSemaphore::~CSemaphore" ref="a21097aba9e59c22aa6d89554d2977341" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">virtual mrpt::synch::CSemaphore::~CSemaphore </td> <td>(</td> <td class="paramname"></td><td>)</td> <td><code> [virtual]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Destructor. </p> </div> </div> <hr/><h2>Member Function Documentation</h2> <a class="anchor" id="aebabb04b45d41e8085a36faefc3778d5"></a><!-- doxytag: member="mrpt::synch::CSemaphore::getName" ref="aebabb04b45d41e8085a36faefc3778d5" args="() const " --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="classstd_1_1string.html">std::string</a> mrpt::synch::CSemaphore::getName </td> <td>(</td> <td class="paramname"></td><td>)</td> <td> const<code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Get the name of the named semaphore or an empty string if it's unnamed. </p> <p>Definition at line <a class="el" href="_c_semaphore_8h_source.html#l00084">84</a> of file <a class="el" href="_c_semaphore_8h_source.html">CSemaphore.h</a>.</p> </div> </div> <a class="anchor" id="ad33d2e60018742dd69735da0c6f10931"></a><!-- doxytag: member="mrpt::synch::CSemaphore::isNamed" ref="ad33d2e60018742dd69735da0c6f10931" args="() const " --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">bool mrpt::synch::CSemaphore::isNamed </td> <td>(</td> <td class="paramname"></td><td>)</td> <td> const<code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Return true if this is a named semaphore. </p> <p>Definition at line <a class="el" href="_c_semaphore_8h_source.html#l00087">87</a> of file <a class="el" href="_c_semaphore_8h_source.html">CSemaphore.h</a>.</p> </div> </div> <a class="anchor" id="af622ff89814558ec46ae98bd7764e97b"></a><!-- doxytag: member="mrpt::synch::CSemaphore::release" ref="af622ff89814558ec46ae98bd7764e97b" args="(unsigned int increaseCount=1)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void mrpt::synch::CSemaphore::release </td> <td>(</td> <td class="paramtype">unsigned int </td> <td class="paramname"><em>increaseCount</em> = <code>1</code></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Increments the count of the semaphore by a given amount. </p> </div> </div> <a class="anchor" id="ac7df910d79e935db246381e1d2361a52"></a><!-- doxytag: member="mrpt::synch::CSemaphore::waitForSignal" ref="ac7df910d79e935db246381e1d2361a52" args="(unsigned int timeout_ms=0)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">bool mrpt::synch::CSemaphore::waitForSignal </td> <td>(</td> <td class="paramtype">unsigned int </td> <td class="paramname"><em>timeout_ms</em> = <code>0</code></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Blocks until the count of the semaphore to be non-zero. </p> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">timeout_ms</td><td>The timeout in milliseconds, or set to zero to wait indefinidely. </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>true if the semaphore has been signaled, false on timeout or any other error. </dd></dl> </div> </div> <hr/><h2>Member Data Documentation</h2> <a class="anchor" id="a82f71a788dc159ed7bbf5fdd19f138f7"></a><!-- doxytag: member="mrpt::synch::CSemaphore::m_data" ref="a82f71a788dc159ed7bbf5fdd19f138f7" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="classmrpt_1_1utils_1_1_c_referenced_mem_block.html">utils::CReferencedMemBlock</a> <a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html#a82f71a788dc159ed7bbf5fdd19f138f7">mrpt::synch::CSemaphore::m_data</a><code> [protected]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_semaphore_8h_source.html#l00054">54</a> of file <a class="el" href="_c_semaphore_8h_source.html">CSemaphore.h</a>.</p> </div> </div> <a class="anchor" id="aa6be1b8896adf5c78ab0f0318cb39b7b"></a><!-- doxytag: member="mrpt::synch::CSemaphore::m_name" ref="aa6be1b8896adf5c78ab0f0318cb39b7b" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="classstd_1_1string.html">std::string</a> <a class="el" href="classmrpt_1_1synch_1_1_c_semaphore.html#aa6be1b8896adf5c78ab0f0318cb39b7b">mrpt::synch::CSemaphore::m_name</a><code> [protected]</code></td> </tr> </table> </div> <div class="memdoc"> <p>The name of the named semaphore, or empty if unnamed. </p> <p>Definition at line <a class="el" href="_c_semaphore_8h_source.html#l00055">55</a> of file <a class="el" href="_c_semaphore_8h_source.html">CSemaphore.h</a>.</p> </div> </div> </div> <br><hr><br> <table border="0" width="100%"> <tr> <td> Page generated by <a href="http://www.doxygen.org" target="_blank">Doxygen 1.7.5</a> for MRPT 0.9.5 SVN: at Sun Sep 25 17:20:18 UTC 2011</td><td></td> <td width="100"> </td> <td width="150"> </td></tr> </table> </body></html>