<!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>Crystal Space 1.2.1: csplugincommon/sndsys/queue.h Source File (Crystal Space 1.2.1 Public API Reference)</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="head"> <tr height="59"> <td class="head" width="202" valign="bottom" style="padding-left:0;"><a href="http://www.crystalspace3d.org/"><img src="csblur.png" width="236" height="59" alt="CrystalSpace" border="0"></a></td> <td class="head"><h2>Public API Reference</h2></td> </tr> <tr height="11"> <td colspan="2" class="headshadow" valign="top" style="padding-left:0;"><img src="csblurb.png" width="236" height="11" alt="" border="0"></td> </tr> </table> <div class="content"> <!-- Generated by Doxygen 1.5.3 --> <div class="tabs"> <ul> <li><a href="index.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><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul> </div> <h1>csplugincommon/sndsys/queue.h</h1><a href="queue_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> Copyright (C) 2004 by Andrew Mann</span> <a name="l00003"></a>00003 <span class="comment"></span> <a name="l00004"></a>00004 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00005"></a>00005 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00006"></a>00006 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00007"></a>00007 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00008"></a>00008 <span class="comment"></span> <a name="l00009"></a>00009 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00010"></a>00010 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00011"></a>00011 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00012"></a>00012 <span class="comment"> Library General Public License for more details.</span> <a name="l00013"></a>00013 <span class="comment"></span> <a name="l00014"></a>00014 <span class="comment"> You should have received a copy of the GNU Library General Public</span> <a name="l00015"></a>00015 <span class="comment"> License along with this library; if not, write to the Free</span> <a name="l00016"></a>00016 <span class="comment"> Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span> <a name="l00017"></a>00017 <span class="comment">*/</span> <a name="l00018"></a>00018 <a name="l00019"></a>00019 <a name="l00025"></a>00025 <span class="preprocessor">#ifndef SNDSYS_QUEUE_H</span> <a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define SNDSYS_QUEUE_H</span> <a name="l00027"></a>00027 <span class="preprocessor"></span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="mutex_8h.html" title="Mutual-exclusion object.">csutil/threading/mutex.h</a>"</span> <a name="l00030"></a>00030 <span class="preprocessor">#include "csutil/threading/condition.h"</span> <a name="l00031"></a>00031 <a name="l00032"></a>00032 <span class="keyword">namespace </span>CS <a name="l00033"></a>00033 { <a name="l00034"></a>00034 <span class="keyword">namespace </span>SndSys <a name="l00035"></a>00035 { <a name="l00036"></a>00036 <a name="l00038"></a><a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c">00038</a> <span class="keyword">typedef</span> <span class="keyword">enum</span> <a name="l00039"></a>00039 { <a name="l00041"></a><a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7ca10a73804e7448d15ef55cc3d55e9514">00041</a> <a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7ca10a73804e7448d15ef55cc3d55e9514">QUEUE_SUCCESS</a> = 0, <a name="l00042"></a>00042 <a name="l00046"></a><a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c6adb0e394b00c5de53430ebdfcf0cf51">00046</a> <a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c6adb0e394b00c5de53430ebdfcf0cf51">QUEUE_ERR_CLOSED</a> = -1, <a name="l00047"></a>00047 <a name="l00049"></a><a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c0f5e1aa6f8683385538b03d739e08d30">00049</a> <a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c0f5e1aa6f8683385538b03d739e08d30">QUEUE_ERR_NOMEM</a> = -2, <a name="l00050"></a>00050 <a name="l00055"></a><a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c424c7aba9dc598fd03fdf1280fcadf47">00055</a> <a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c424c7aba9dc598fd03fdf1280fcadf47">QUEUE_ERR_DUPE</a> = -3 <a name="l00056"></a>00056 } <a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c">QueueErrorType</a>; <a name="l00057"></a>00057 <a name="l00058"></a>00058 <a name="l00059"></a>00059 <span class="comment">// Advance declaration of class QueueIterator</span> <a name="l00060"></a>00060 <span class="keyword">template</span><<span class="keyword">typename</span> T> <span class="keyword">class </span>QueueIterator; <a name="l00061"></a>00061 <a name="l00063"></a>00063 <span class="keyword">template</span><<span class="keyword">typename</span> T> <a name="l00064"></a><a class="code" href="classCS_1_1SndSys_1_1QEntry.html">00064</a> <span class="keyword">class </span><a class="code" href="classCS_1_1SndSys_1_1QEntry.html">QEntry</a> <a name="l00065"></a>00065 { <a name="l00066"></a>00066 <span class="keyword">public</span>: <a name="l00067"></a><a class="code" href="classCS_1_1SndSys_1_1QEntry.html#68a472a34f6dab74ba8867a700345f07">00067</a> T * <a class="code" href="classCS_1_1SndSys_1_1QEntry.html#68a472a34f6dab74ba8867a700345f07">data</a>; <a name="l00068"></a><a class="code" href="classCS_1_1SndSys_1_1QEntry.html#7e0668ed138e2e33da2ca9287b9f4046">00068</a> <a class="code" href="classCS_1_1SndSys_1_1QEntry.html">QEntry</a> *<a class="code" href="classCS_1_1SndSys_1_1QEntry.html#5455e2c660b7da8d1e491262dd1f024e">next</a>, *<a class="code" href="classCS_1_1SndSys_1_1QEntry.html#7e0668ed138e2e33da2ca9287b9f4046">prev</a>; <a name="l00069"></a>00069 }; <a name="l00070"></a>00070 <a name="l00095"></a>00095 <span class="keyword">template</span><<span class="keyword">typename</span> T> <a name="l00096"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html">00096</a> <span class="keyword">class </span><a class="code" href="classCS_1_1SndSys_1_1Queue.html">Queue</a> <a name="l00097"></a>00097 { <a name="l00098"></a>00098 <span class="keyword">public</span>: <a name="l00099"></a>00099 <a name="l00101"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#797658784eb71da7e9376e04c2f048e6">00101</a> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#797658784eb71da7e9376e04c2f048e6" title="Queue construction requires no parameters.">Queue</a>() : <a name="l00102"></a>00102 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>(0), <a class="code" href="classCS_1_1SndSys_1_1Queue.html#fb8643a7080346f9046b3c3eb3dc53fa" title="Pointer to the newest entry in the queue.">m_pTail</a>(0), <a class="code" href="classCS_1_1SndSys_1_1Queue.html#7ed210a3a0f527877aefdabd8a371de5" title="Number of entries currently in the queue.">m_EntryCount</a>(0), <a class="code" href="classCS_1_1SndSys_1_1Queue.html#656749073aabb0fba4f7c264a145c820" title="Flag indicating whether new entries may be added to this queue.">m_bClosed</a>(false), <a class="code" href="classCS_1_1SndSys_1_1Queue.html#9203a8b455810d1d786d44dbf5793a73">m_bDupeCheck</a>(false) <a name="l00103"></a>00103 { <a name="l00104"></a>00104 <a name="l00105"></a>00105 } <a name="l00106"></a>00106 <a name="l00107"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#202cd92a38bfa5bcac553cb6663a40c5">00107</a> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#202cd92a38bfa5bcac553cb6663a40c5">~Queue</a>() <a name="l00108"></a>00108 { <a name="l00109"></a>00109 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#be5e3c2036214db5c8c5eba8ceb9bfda">Clear</a>(); <a name="l00110"></a>00110 } <a name="l00111"></a>00111 <a name="l00118"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#be5e3c2036214db5c8c5eba8ceb9bfda">00118</a> <span class="keywordtype">void</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#be5e3c2036214db5c8c5eba8ceb9bfda">Clear</a>() <a name="l00119"></a>00119 { <a name="l00120"></a>00120 <a class="code" href="classCS_1_1SndSys_1_1QEntry.html">QEntry<T></a> *del; <a name="l00121"></a>00121 <a name="l00122"></a>00122 <a class="code" href="classCS_1_1Threading_1_1ScopedLock.html" title="This is a utility class for locking a Mutex.">CS::Threading::RecursiveMutexScopedLock</a> lock (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f" title="The mutex which restricts access to all queue operations.">m_pAccessMutex</a>); <a name="l00123"></a>00123 <a name="l00124"></a>00124 <span class="keywordflow">while</span> (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>) <a name="l00125"></a>00125 { <a name="l00126"></a>00126 del=<a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>; <a name="l00127"></a>00127 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>=<a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>->next; <a name="l00128"></a>00128 <span class="keyword">delete</span> del; <a name="l00129"></a>00129 } <a name="l00130"></a>00130 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#fb8643a7080346f9046b3c3eb3dc53fa" title="Pointer to the newest entry in the queue.">m_pTail</a>=0; <a name="l00131"></a>00131 <a name="l00132"></a>00132 <span class="comment">// Wake all waiting threads, queue is cleared</span> <a name="l00133"></a>00133 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#d1026bbc7dc6fb7d51cbcfa085153c84" title="The condition used for waiting on and signaling availability of entries.">m_pEntryReadyCondition</a>.<a class="code" href="classCS_1_1Threading_1_1Condition.html#7434ea57fb4d50d997dfe9c5146d0107" title="Notify and wake up all threads currently waiting for the condition.">NotifyAll</a> (); <a name="l00134"></a>00134 } <a name="l00135"></a>00135 <a name="l00137"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#6fa11ca09e82a911ee28e85634ddc2aa">00137</a> <a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c">QueueErrorType</a> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#6fa11ca09e82a911ee28e85634ddc2aa" title="Add the specified pointer to the end of the queue.">QueueEntry</a>(T* pData) <a name="l00138"></a>00138 { <a name="l00139"></a>00139 <a class="code" href="classCS_1_1Threading_1_1ScopedLock.html" title="This is a utility class for locking a Mutex.">CS::Threading::RecursiveMutexScopedLock</a> lock (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f" title="The mutex which restricts access to all queue operations.">m_pAccessMutex</a>); <a name="l00140"></a>00140 <a name="l00141"></a>00141 <span class="keywordflow">if</span> (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#656749073aabb0fba4f7c264a145c820" title="Flag indicating whether new entries may be added to this queue.">m_bClosed</a>) <span class="keywordflow">return</span> <a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c6adb0e394b00c5de53430ebdfcf0cf51">QUEUE_ERR_CLOSED</a>; <a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="keywordflow">if</span> (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#9203a8b455810d1d786d44dbf5793a73">m_bDupeCheck</a> && <a class="code" href="classCS_1_1SndSys_1_1Queue.html#6d049ba0d13f55d1b3e12b9485b6e11a" title="Compares pointers, and not the objects they point to.">Find</a>(pData)) <a name="l00144"></a>00144 { <a name="l00145"></a>00145 <span class="keywordflow">return</span> <a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c424c7aba9dc598fd03fdf1280fcadf47">QUEUE_ERR_DUPE</a>; <a name="l00146"></a>00146 } <a name="l00147"></a>00147 <a name="l00148"></a>00148 <a class="code" href="classCS_1_1SndSys_1_1QEntry.html">QEntry<T></a> *pNewEntry= <span class="keyword">new</span> <a class="code" href="classCS_1_1SndSys_1_1QEntry.html">QEntry<T></a>(); <a name="l00149"></a>00149 <span class="keywordflow">if</span> (!pNewEntry) <a name="l00150"></a>00150 { <a name="l00151"></a>00151 <span class="keywordflow">return</span> <a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7c0f5e1aa6f8683385538b03d739e08d30">QUEUE_ERR_NOMEM</a>; <a name="l00152"></a>00152 } <a name="l00153"></a>00153 pNewEntry-><a class="code" href="classCS_1_1SndSys_1_1QEntry.html#68a472a34f6dab74ba8867a700345f07">data</a>=pData; <a name="l00154"></a>00154 pNewEntry-><a class="code" href="classCS_1_1SndSys_1_1QEntry.html#7e0668ed138e2e33da2ca9287b9f4046">prev</a>=<a class="code" href="classCS_1_1SndSys_1_1Queue.html#fb8643a7080346f9046b3c3eb3dc53fa" title="Pointer to the newest entry in the queue.">m_pTail</a>; <a name="l00155"></a>00155 pNewEntry-><a class="code" href="classCS_1_1SndSys_1_1QEntry.html#5455e2c660b7da8d1e491262dd1f024e">next</a>=0; <a name="l00156"></a>00156 <a name="l00157"></a>00157 <span class="keywordflow">if</span> (!<a class="code" href="classCS_1_1SndSys_1_1Queue.html#fb8643a7080346f9046b3c3eb3dc53fa" title="Pointer to the newest entry in the queue.">m_pTail</a>) <a name="l00158"></a>00158 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>=pNewEntry; <a name="l00159"></a>00159 <span class="keywordflow">else</span> <a name="l00160"></a>00160 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#fb8643a7080346f9046b3c3eb3dc53fa" title="Pointer to the newest entry in the queue.">m_pTail</a>->next=pNewEntry; <a name="l00161"></a>00161 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#fb8643a7080346f9046b3c3eb3dc53fa" title="Pointer to the newest entry in the queue.">m_pTail</a>=pNewEntry; <a name="l00162"></a>00162 <a name="l00163"></a>00163 <a name="l00164"></a>00164 <span class="comment">// Signal one waiting thread to wake up</span> <a name="l00165"></a>00165 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#d1026bbc7dc6fb7d51cbcfa085153c84" title="The condition used for waiting on and signaling availability of entries.">m_pEntryReadyCondition</a>.<a class="code" href="classCS_1_1Threading_1_1Condition.html#8713c7f7c44839dc1d003522e0984711" title="Notify and wake up one thread waiting for the condition.">NotifyOne</a> (); <a name="l00166"></a>00166 <a name="l00167"></a>00167 <span class="keywordflow">return</span> <a class="code" href="namespaceCS_1_1SndSys.html#e0f22d90228350dcd6fbc5acd8589e7ca10a73804e7448d15ef55cc3d55e9514">QUEUE_SUCCESS</a>; <a name="l00168"></a>00168 } <a name="l00169"></a>00169 <a name="l00179"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#3c9ce58e3e187375c943a2670f88e3ac">00179</a> T * <a class="code" href="classCS_1_1SndSys_1_1Queue.html#3c9ce58e3e187375c943a2670f88e3ac">DequeueEntry</a>(<span class="keywordtype">bool</span> bWait=<span class="keyword">false</span>) <a name="l00180"></a>00180 { <a name="l00181"></a>00181 <a class="code" href="classCS_1_1SndSys_1_1QEntry.html">QEntry<T></a> *pRemoved; <a name="l00182"></a>00182 T* pData=0; <a name="l00183"></a>00183 <a name="l00184"></a>00184 <a class="code" href="classCS_1_1Threading_1_1ScopedLock.html" title="This is a utility class for locking a Mutex.">CS::Threading::RecursiveMutexScopedLock</a> lock (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f" title="The mutex which restricts access to all queue operations.">m_pAccessMutex</a>); <a name="l00185"></a>00185 <a name="l00186"></a>00186 <span class="comment">// Wait for an entry to be available if specified</span> <a name="l00187"></a>00187 <span class="keywordflow">if</span> (!<a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a> && bWait) <a name="l00188"></a>00188 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#d1026bbc7dc6fb7d51cbcfa085153c84" title="The condition used for waiting on and signaling availability of entries.">m_pEntryReadyCondition</a>.<a class="code" href="classCS_1_1Threading_1_1Condition.html#37100c936bfb1e6c7b7a3f5aaabd75ff" title="Wait for some change of condition.">Wait</a> (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f" title="The mutex which restricts access to all queue operations.">m_pAccessMutex</a>); <a name="l00189"></a>00189 <a name="l00190"></a>00190 <span class="comment">// Remove the m_pHead entry from the queue, shift</span> <a name="l00191"></a>00191 <span class="comment">// the head pointer to the next entry</span> <a name="l00192"></a>00192 <span class="keywordflow">if</span> (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>) <a name="l00193"></a>00193 { <a name="l00194"></a>00194 <a name="l00195"></a>00195 pRemoved=<a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>; <a name="l00196"></a>00196 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>=<a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>->next; <a name="l00197"></a>00197 <span class="comment">// Make sure the Next and Previous linked list pointers</span> <a name="l00198"></a>00198 <span class="comment">// remain valid.</span> <a name="l00199"></a>00199 <span class="keywordflow">if</span> (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>) <a name="l00200"></a>00200 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>->prev=0; <a name="l00201"></a>00201 <span class="keywordflow">else</span> <a name="l00202"></a>00202 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#fb8643a7080346f9046b3c3eb3dc53fa" title="Pointer to the newest entry in the queue.">m_pTail</a>=0; <a name="l00203"></a>00203 pData=pRemoved-><a class="code" href="classCS_1_1SndSys_1_1QEntry.html#68a472a34f6dab74ba8867a700345f07">data</a>; <a name="l00204"></a>00204 <span class="comment">// Delete the entry wrapper object</span> <a name="l00205"></a>00205 <span class="keyword">delete</span> pRemoved; <a name="l00206"></a>00206 } <a name="l00207"></a>00207 <span class="keywordflow">return</span> pData; <a name="l00208"></a>00208 } <a name="l00209"></a>00209 <a name="l00211"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#abd8d5d95c556eb2cbb902b05b45e6de">00211</a> <span class="keywordtype">size_t</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#abd8d5d95c556eb2cbb902b05b45e6de" title="Retrieve the number of entries in the queue.">Length</a>() { <span class="keywordflow">return</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#7ed210a3a0f527877aefdabd8a371de5" title="Number of entries currently in the queue.">m_EntryCount</a>; } <a name="l00212"></a>00212 <a name="l00214"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#6d049ba0d13f55d1b3e12b9485b6e11a">00214</a> <span class="keywordtype">bool</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#6d049ba0d13f55d1b3e12b9485b6e11a" title="Compares pointers, and not the objects they point to.">Find</a>(T *data) <a name="l00215"></a>00215 { <a name="l00216"></a>00216 <a class="code" href="classCS_1_1Threading_1_1ScopedLock.html" title="This is a utility class for locking a Mutex.">CS::Threading::RecursiveMutexScopedLock</a> lock (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f" title="The mutex which restricts access to all queue operations.">m_pAccessMutex</a>); <a name="l00217"></a>00217 <a class="code" href="classCS_1_1SndSys_1_1QEntry.html">QEntry<T></a> *cur=<a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>; <a name="l00218"></a>00218 <span class="keywordflow">while</span> (cur) <a name="l00219"></a>00219 { <a name="l00220"></a>00220 <span class="keywordflow">if</span> (((cur-><a class="code" href="classCS_1_1SndSys_1_1QEntry.html#68a472a34f6dab74ba8867a700345f07">data</a>)) == (data)) <a name="l00221"></a>00221 { <a name="l00222"></a>00222 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00223"></a>00223 } <a name="l00224"></a>00224 cur=cur-><a class="code" href="classCS_1_1SndSys_1_1QEntry.html#5455e2c660b7da8d1e491262dd1f024e">next</a>; <a name="l00225"></a>00225 } <a name="l00226"></a>00226 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00227"></a>00227 } <a name="l00228"></a>00228 <a name="l00230"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#8460e64c36abe9eac89b8d7b53278f20">00230</a> <span class="keywordtype">void</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#8460e64c36abe9eac89b8d7b53278f20" title="Close the queue so that no further entries may be added.">SetClosed</a>(<span class="keywordtype">bool</span> Closed) <a name="l00231"></a>00231 { <a name="l00232"></a>00232 <a class="code" href="classCS_1_1Threading_1_1ScopedLock.html" title="This is a utility class for locking a Mutex.">CS::Threading::RecursiveMutexScopedLock</a> lock (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f" title="The mutex which restricts access to all queue operations.">m_pAccessMutex</a>); <a name="l00233"></a>00233 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#656749073aabb0fba4f7c264a145c820" title="Flag indicating whether new entries may be added to this queue.">m_bClosed</a>=Closed; <a name="l00234"></a>00234 } <a name="l00235"></a>00235 <a name="l00238"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#c61bdd1f8527bbe894277163d85fbe8c">00238</a> <span class="keywordtype">bool</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#c61bdd1f8527bbe894277163d85fbe8c">GetClosed</a>() <a name="l00239"></a>00239 { <a name="l00240"></a>00240 <span class="keywordtype">bool</span> Closed; <a name="l00241"></a>00241 <a class="code" href="classCS_1_1Threading_1_1ScopedLock.html" title="This is a utility class for locking a Mutex.">CS::Threading::RecursiveMutexScopedLock</a> lock (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f" title="The mutex which restricts access to all queue operations.">m_pAccessMutex</a>); <a name="l00242"></a>00242 Closed=<a class="code" href="classCS_1_1SndSys_1_1Queue.html#656749073aabb0fba4f7c264a145c820" title="Flag indicating whether new entries may be added to this queue.">m_bClosed</a>; <a name="l00243"></a>00243 <a name="l00244"></a>00244 <span class="keywordflow">return</span> Closed; <a name="l00245"></a>00245 } <a name="l00246"></a>00246 <a name="l00253"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#c45f24a87141b79d3b6d5927f0d5e361">00253</a> <span class="keywordtype">void</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#c45f24a87141b79d3b6d5927f0d5e361" title="Turn on/off duplicate entry pointer checking.">SetDupecheck</a>(<span class="keywordtype">bool</span> Check) <a name="l00254"></a>00254 { <a name="l00255"></a>00255 <a class="code" href="classCS_1_1Threading_1_1ScopedLock.html" title="This is a utility class for locking a Mutex.">CS::Threading::RecursiveMutexScopedLock</a> lock (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f" title="The mutex which restricts access to all queue operations.">m_pAccessMutex</a>); <a name="l00256"></a>00256 <a class="code" href="classCS_1_1SndSys_1_1Queue.html#9203a8b455810d1d786d44dbf5793a73">m_bDupeCheck</a>=Check; <a name="l00257"></a>00257 } <a name="l00258"></a>00258 <a name="l00260"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#3b1c3ada8c5aa3e2ad6c595ffc7b2887">00260</a> <span class="keywordtype">bool</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#3b1c3ada8c5aa3e2ad6c595ffc7b2887" title="Retrieve the status of duplicate pointer checking.">GetDupecheck</a>() <a name="l00261"></a>00261 { <a name="l00262"></a>00262 <span class="keywordtype">bool</span> val; <a name="l00263"></a>00263 <a class="code" href="classCS_1_1Threading_1_1ScopedLock.html" title="This is a utility class for locking a Mutex.">CS::Threading::RecursiveMutexScopedLock</a> lock (<a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f" title="The mutex which restricts access to all queue operations.">m_pAccessMutex</a>); <a name="l00264"></a>00264 val=<a class="code" href="classCS_1_1SndSys_1_1Queue.html#656749073aabb0fba4f7c264a145c820" title="Flag indicating whether new entries may be added to this queue.">m_bClosed</a>; <a name="l00265"></a>00265 <span class="keywordflow">return</span> val; <a name="l00266"></a>00266 } <a name="l00267"></a>00267 <a name="l00272"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#f5c7873438801b0820c0ebc2571c3e84">00272</a> <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html">QueueIterator<T></a>* <a class="code" href="classCS_1_1SndSys_1_1Queue.html#f5c7873438801b0820c0ebc2571c3e84">GetIterator</a>() <a name="l00273"></a>00273 { <a name="l00274"></a>00274 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html">QueueIterator<T></a>(<span class="keyword">this</span>); <a name="l00275"></a>00275 } <a name="l00276"></a>00276 <a name="l00277"></a>00277 <span class="keyword">protected</span>: <a name="l00279"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6">00279</a> <a class="code" href="classCS_1_1SndSys_1_1QEntry.html">QEntry<T></a> *<a class="code" href="classCS_1_1SndSys_1_1Queue.html#34bdcdf452d4da025e8a9ed4f01907c6" title="Pointer to the oldest entry in the queue.">m_pHead</a>; <a name="l00281"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#fb8643a7080346f9046b3c3eb3dc53fa">00281</a> <a class="code" href="classCS_1_1SndSys_1_1QEntry.html">QEntry<T></a> *<a class="code" href="classCS_1_1SndSys_1_1Queue.html#fb8643a7080346f9046b3c3eb3dc53fa" title="Pointer to the newest entry in the queue.">m_pTail</a>; <a name="l00283"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#7ed210a3a0f527877aefdabd8a371de5">00283</a> <span class="keywordtype">size_t</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#7ed210a3a0f527877aefdabd8a371de5" title="Number of entries currently in the queue.">m_EntryCount</a>; <a name="l00285"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#656749073aabb0fba4f7c264a145c820">00285</a> <span class="keyword">volatile</span> <span class="keywordtype">bool</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#656749073aabb0fba4f7c264a145c820" title="Flag indicating whether new entries may be added to this queue.">m_bClosed</a>; <a name="l00288"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#9203a8b455810d1d786d44dbf5793a73">00288</a> <span class="keyword">volatile</span> <span class="keywordtype">bool</span> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#9203a8b455810d1d786d44dbf5793a73">m_bDupeCheck</a>; <a name="l00289"></a>00289 <a name="l00290"></a>00290 <span class="comment">// A recursive mutex is used so that the duplicate entry check can hold a</span> <a name="l00291"></a>00291 <span class="comment">// lock m_EntryCount of 2</span> <a name="l00292"></a>00292 <a name="l00294"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f">00294</a> <a class="code" href="classCS_1_1Threading_1_1MutexImpl.html" title="General mutex class.">CS::Threading::RecursiveMutex</a> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#e9fb3111698d328d2b8062df4402284f" title="The mutex which restricts access to all queue operations.">m_pAccessMutex</a>; <a name="l00296"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#d1026bbc7dc6fb7d51cbcfa085153c84">00296</a> <a class="code" href="classCS_1_1Threading_1_1Condition.html" title="Condition variable.">CS::Threading::Condition</a> <a class="code" href="classCS_1_1SndSys_1_1Queue.html#d1026bbc7dc6fb7d51cbcfa085153c84" title="The condition used for waiting on and signaling availability of entries.">m_pEntryReadyCondition</a>; <a name="l00297"></a>00297 <a name="l00298"></a>00298 <a name="l00299"></a><a class="code" href="classCS_1_1SndSys_1_1Queue.html#8ad2dc581d508c66de7abccf64e7d4cb">00299</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html">QueueIterator</a><T>; <a name="l00300"></a>00300 }; <a name="l00301"></a>00301 <a name="l00302"></a>00302 <a name="l00303"></a>00303 <a name="l00308"></a>00308 <span class="keyword">template</span><<span class="keyword">typename</span> T> <a name="l00309"></a><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html">00309</a> <span class="keyword">class </span><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html">QueueIterator</a> <a name="l00310"></a>00310 { <a name="l00311"></a>00311 <span class="keyword">public</span>: <a name="l00312"></a><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#74a679cb27e7d7ba98214e5d17d7da79">00312</a> <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#74a679cb27e7d7ba98214e5d17d7da79">QueueIterator</a>(<a class="code" href="classCS_1_1SndSys_1_1Queue.html">Queue<T></a> *queue) <a name="l00313"></a>00313 { <a name="l00314"></a>00314 <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#c5f4af6756176fb3703a2df963d15511">q</a>=queue; <a name="l00315"></a>00315 <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>=0; <a name="l00316"></a>00316 <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#c5f4af6756176fb3703a2df963d15511">q</a>->Lock(); <a name="l00317"></a>00317 } <a name="l00318"></a>00318 <a name="l00319"></a><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#b2ef73961e5ac0cb5a793952df9160c1">00319</a> <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#b2ef73961e5ac0cb5a793952df9160c1">~QueueIterator</a>() <a name="l00320"></a>00320 { <a name="l00321"></a>00321 <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#c5f4af6756176fb3703a2df963d15511">q</a>->Unlock(); <a name="l00322"></a>00322 } <a name="l00323"></a>00323 <a name="l00324"></a><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#4e5aa5970bc2944b3afd7eedcd72c638">00324</a> T * <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#4e5aa5970bc2944b3afd7eedcd72c638">First</a>() <a name="l00325"></a>00325 { <a name="l00326"></a>00326 <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>=<a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#c5f4af6756176fb3703a2df963d15511">q</a>->m_pHead; <a name="l00327"></a>00327 <span class="keywordflow">return</span> <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>; <a name="l00328"></a>00328 } <a name="l00329"></a>00329 <a name="l00330"></a><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#b69feebdff10cfc7df26f6b170d20fbc">00330</a> T * <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#b69feebdff10cfc7df26f6b170d20fbc">Last</a>() <a name="l00331"></a>00331 { <a name="l00332"></a>00332 <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>=<a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#c5f4af6756176fb3703a2df963d15511">q</a>->m_pTail; <a name="l00333"></a>00333 <span class="keywordflow">return</span> <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>; <a name="l00334"></a>00334 } <a name="l00335"></a>00335 <a name="l00336"></a><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#94022c9fd464f65d49422e1ed29564a8">00336</a> T *<a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#94022c9fd464f65d49422e1ed29564a8">Next</a>() <a name="l00337"></a>00337 { <a name="l00338"></a>00338 <span class="keywordflow">if</span> (<a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>) <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>=<a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>->next; <a name="l00339"></a>00339 <span class="keywordflow">return</span> <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>; <a name="l00340"></a>00340 } <a name="l00341"></a>00341 <a name="l00342"></a>00342 <a name="l00343"></a><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#f450623570990560ef1112ad93d09362">00343</a> T * <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#f450623570990560ef1112ad93d09362">Prev</a>() <a name="l00344"></a>00344 { <a name="l00345"></a>00345 <span class="keywordflow">if</span> (<a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>) <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>=<a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>->prev; <a name="l00346"></a>00346 <span class="keywordflow">return</span> <a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>; <a name="l00347"></a>00347 } <a name="l00348"></a>00348 <a name="l00349"></a>00349 <span class="keyword">protected</span>: <a name="l00350"></a><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">00350</a> <a class="code" href="classCS_1_1SndSys_1_1QEntry.html">QEntry<T></a> *<a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#726d6a45af816db97537a5aeb7422054">current</a>; <a name="l00351"></a><a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#c5f4af6756176fb3703a2df963d15511">00351</a> <a class="code" href="classCS_1_1SndSys_1_1Queue.html">Queue<T></a> *<a class="code" href="classCS_1_1SndSys_1_1QueueIterator.html#c5f4af6756176fb3703a2df963d15511">q</a>; <a name="l00352"></a>00352 }; <a name="l00353"></a>00353 <a name="l00354"></a>00354 <a name="l00355"></a>00355 <a name="l00356"></a>00356 } <a name="l00357"></a>00357 <span class="comment">// END namespace CS::SndSys</span> <a name="l00358"></a>00358 } <a name="l00359"></a>00359 <span class="comment">// END namespace CS</span> <a name="l00360"></a>00360 <a name="l00361"></a>00361 <a name="l00362"></a>00362 <a name="l00363"></a>00363 <span class="preprocessor">#endif // #ifndef SNDSYS_QUEUE_H</span> <a name="l00364"></a>00364 <span class="preprocessor"></span> </pre></div><hr size="1"><address><small>Generated for Crystal Space 1.2.1 by <a href="http://www.doxygen.org/index.html">doxygen</a> 1.5.3 </small></address> </div></body> </html>