⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classpsemaphore.html

📁 pwlib开发文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>PSemaphore class Reference</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center><hr><h1>PSemaphore Class Reference</h1><code>#include &lt;<a class="el" href="semaphor_8h-source.html">semaphor.h</a>&gt;</code><p><p>Inheritance diagram for PSemaphore:<p><center><img src="classPSemaphore.png" usemap="#PSemaphore_map" border="0" alt=""></center><map name="PSemaphore_map"><area href="classPObject.html" alt="PObject" shape="rect" coords="136,0,235,24"><area href="classPMutex.html" alt="PMutex" shape="rect" coords="54,112,153,136"><area href="classPSyncPoint.html" alt="PSyncPoint" shape="rect" coords="218,112,317,136"><area href="classPCondMutex.html" alt="PCondMutex" shape="rect" coords="0,168,99,192"><area href="classPVXMLCache.html" alt="PVXMLCache" shape="rect" coords="109,168,208,192"><area href="classPSyncPointAck.html" alt="PSyncPointAck" shape="rect" coords="218,168,317,192"><area href="classPIntCondMutex.html" alt="PIntCondMutex" shape="rect" coords="0,224,99,248"></map><a href="classPSemaphore-members.html">List of all members.</a><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr><tr><td colspan=2><br><h2>Public Methods</h2></td></tr><tr><td nowrap align=right valign=top>unsigned&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#a0">GetInitial</a> () const</td></tr><tr><td nowrap align=right valign=top>unsigned&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#a1">GetMaxCount</a> () const</td></tr><tr><td colspan="2"><div class="groupHeader">Construction</div></td></tr><tr><td nowrap align=right valign=top>&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#z345_0">PSemaphore</a> (unsigned initial, unsigned maximum)</td></tr><tr><td nowrap align=right valign=top>&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#z345_1">PSemaphore</a> (const PSemaphore &amp;)</td></tr><tr><td nowrap align=right valign=top>&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#z345_2">~PSemaphore</a> ()</td></tr><tr><td colspan="2"><div class="groupHeader">Operations</div></td></tr><tr><td nowrap align=right valign=top>virtual void&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#z347_0">Wait</a> ()</td></tr><tr><td nowrap align=right valign=top>virtual BOOL&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#z347_1">Wait</a> (const <a class="el" href="classPTimeInterval.html">PTimeInterval</a> &amp;timeout)</td></tr><tr><td nowrap align=right valign=top>virtual void&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#z347_2">Signal</a> ()</td></tr><tr><td nowrap align=right valign=top>virtual BOOL&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#z347_3">WillBlock</a> () const</td></tr><tr><td colspan=2><br><h2>Protected Methods</h2></td></tr><tr><td nowrap align=right valign=top>&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#b0">PQUEUE</a> (ThreadQueue, <a class="el" href="classPThread.html">PThread</a>)</td></tr><tr><td colspan=2><br><h2>Protected Attributes</h2></td></tr><tr><td nowrap align=right valign=top>unsigned&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#n0">initialVar</a></td></tr><tr><td nowrap align=right valign=top>unsigned&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#n1">maxCountVar</a></td></tr><tr><td nowrap align=right valign=top>ThreadQueue&nbsp;</td><td valign=bottom><a class="el" href="classPSemaphore.html#n2">waitQueue</a></td></tr></table><hr><a name="_details"></a><h2>Detailed Description</h2>This class defines a thread synchonisation object. This is in the form of a integer semaphore. The semaphore has a count and a maximum value. The various combinations of count and usage of the <a class="el" href="classPSemaphore.html#z347_0">Wait()</a># and <a class="el" href="classPSemaphore.html#z347_2">Signal()</a># functions determine the type of synchronisation mechanism to be employed.<p>The <a class="el" href="classPSemaphore.html#z347_0">Wait()</a># operation is that if the semaphore count is &gt; 0, decrement the semaphore and return. If it is = 0 then wait (block).<p>The <a class="el" href="classPSemaphore.html#z347_2">Signal()</a># operation is that if there are waiting threads then unblock the first one that was blocked. If no waiting threads and the count is less than the maximum then increment the semaphore.<p>The most common is to create a mutual exclusion zone. A mutex is where a piece of code or data cannot be accessed by more than one thread at a time. To prevent this the PSemaphore is used in the following manner: \begin{verbatim} PSemaphore mutex(1, 1); // Maximum value of 1 and initial value of 1.<p>...<p>mutex.Wait();<p>... critical section - only one thread at a time here.<p>mutex.Signal();<p>... \end{verbatim} The first thread will pass through the <a class="el" href="classPSemaphore.html#z347_0">Wait()</a># function, a second thread will block on that function until the first calls the <a class="el" href="classPSemaphore.html#z347_2">Signal()</a># function, releasing the second thread. <p><hr><h2>Constructor &amp; Destructor Documentation</h2><a name="z345_0" doxytag="PSemaphore::PSemaphore"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0">  <tr>    <td class="md">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> PSemaphore::PSemaphore </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">unsigned&nbsp;</td>          <td class="mdname" nowrap>&nbsp; <em>initial</em>, </td>        </tr>        <tr>          <td></td>          <td></td>          <td class="md" nowrap>unsigned&nbsp;</td>          <td class="mdname" nowrap>&nbsp; <em>maximum</em></td>        </tr>        <tr>          <td></td>          <td class="md">)&nbsp;</td>          <td class="md" colspan="2"></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Create a new semaphore with maximum count and initial value specified. If the initial value is larger than the maximum value then is is set to the maximum value. <dl compact><dt><b>Parameters: </b></dt><dd><table border=0 cellspacing=2 cellpadding=0><tr><td valign=top><em>maximum</em>&nbsp;</td><td>Initial value for semaphore count. Maximum value for semaphore count. </td></tr></table></dl>    </td>  </tr></table><a name="z345_1" doxytag="PSemaphore::PSemaphore"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0">  <tr>    <td class="md">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> PSemaphore::PSemaphore </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">const PSemaphore &amp;&nbsp;</td>          <td class="mdname1" valign="top" nowrap>&nbsp;          </td>          <td class="md" valign="top">)&nbsp;</td>          <td class="md" nowrap></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Create a new Semaphore with the same initial and maximum values as the original     </td>  </tr></table><a name="z345_2" doxytag="PSemaphore::~PSemaphore"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0">  <tr>    <td class="md">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> PSemaphore::~PSemaphore </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>&nbsp;          </td>          <td class="md" valign="top">)&nbsp;</td>          <td class="md" nowrap></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Destroy the semaphore. This will assert if there are still waiting threads on the semaphore.     </td>  </tr></table><hr><h2>Member Function Documentation</h2><a name="a0" doxytag="PSemaphore::GetInitial"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0">  <tr>    <td class="md">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> unsigned PSemaphore::GetInitial </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>&nbsp;          </td>          <td class="md" valign="top">)&nbsp;</td>          <td class="md" nowrap> const<code> [inline]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><a name="a1" doxytag="PSemaphore::GetMaxCount"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0">  <tr>    <td class="md">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> unsigned PSemaphore::GetMaxCount </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>&nbsp;          </td>          <td class="md" valign="top">)&nbsp;</td>          <td class="md" nowrap> const<code> [inline]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><a name="b0" doxytag="PSemaphore::PQUEUE"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0">  <tr>    <td class="md">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> PSemaphore::PQUEUE </td>          <td class="md" valign="top">(&nbsp;</td>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -