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

📄 _command_8h-source.html

📁 用vc++写的一个简单的线程池的代码
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<a name="l00176"></a>00176         {<a name="l00177"></a>00177                 <a class="code" href="class_plugin_thread_pool_1_1_command.html#5aaecab58914d6fca0996d12d5c802b9">method1</a> = p_method;<a name="l00178"></a>00178                 <a class="code" href="class_plugin_thread_pool_1_1_command.html#03e2cf02a2ff39a8d614d56bd0345682">m_par1</a> = par1;<a name="l00179"></a>00179                 <a name="l00180"></a>00180         }<a name="l00181"></a>00181 <a name="l00182"></a>00182         <span class="comment">//just to illustrate the usage with a method signature taking more than one parameter</span><a name="l00183"></a><a class="code" href="class_plugin_thread_pool_1_1_command.html#16303fccc096391663a44d236b7a6bb2">00183</a>         <span class="keyword">explicit</span> <a class="code" href="class_plugin_thread_pool_1_1_command.html#58aab3290ff60ca553e827432cfd2569">Command</a>(T* pObj,<a class="code" href="class_plugin_thread_pool_1_1binder3.html">F3</a>* p_method,<span class="keywordtype">long</span> timeout,<span class="keyword">const</span> <span class="keywordtype">char</span>* key,<span class="keywordtype">long</span> priority = <a class="code" href="namespace_plugin_thread_pool.html#ce744b8830668fc53d7c97b3c77d7ce4">PRIO_NORMAL</a> ):<a name="l00184"></a>00184                                 <a class="code" href="class_plugin_thread_pool_1_1_command.html#960a60f376ad7a916bd3c97f11d2a824">m_objptr</a>(pObj),<a class="code" href="class_plugin_thread_pool_1_1_command.html#0813562408adb30c60ad501c8b533b00">m_timeout</a>(timeout),<a class="code" href="class_plugin_thread_pool_1_1_command.html#a79238db30e99d1c03f72050ba48a898">m_key</a>(key),<a class="code" href="class_plugin_thread_pool_1_1_command.html#199d3a70de4ff59db4f85f09a9fe0bdf">m_value</a>(priority),<a class="code" href="class_plugin_thread_pool_1_1_command.html#5aaecab58914d6fca0996d12d5c802b9">method1</a>(0),<a class="code" href="class_plugin_thread_pool_1_1_command.html#09eb6f552921e01ef734cfb42790caa2">method0</a>(0),<a class="code" href="class_plugin_thread_pool_1_1_command.html#7552d1a7c1afc09dcdd886e7ade68789">method</a>(0)<a name="l00185"></a>00185         {<a name="l00186"></a>00186                         <a class="code" href="class_plugin_thread_pool_1_1_command.html#e81dab19d4e8944a4c349c220599946e">method3</a> = p_method;<a name="l00187"></a>00187         }<a name="l00188"></a>00188 <a name="l00190"></a>00190         <a name="l00191"></a><a class="code" href="class_plugin_thread_pool_1_1_command.html#bae83347a5d0fd5063355525f06a4ed0">00191</a>         <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="class_plugin_thread_pool_1_1_command.html#bae83347a5d0fd5063355525f06a4ed0">execute</a>()<a name="l00192"></a>00192         {<a name="l00193"></a>00193 <a name="l00194"></a>00194                 <span class="keywordflow">if</span>(<a class="code" href="class_plugin_thread_pool_1_1_command.html#7552d1a7c1afc09dcdd886e7ade68789">method</a>)<a name="l00195"></a>00195                 {<a name="l00196"></a>00196                         (<a class="code" href="class_plugin_thread_pool_1_1_command.html#960a60f376ad7a916bd3c97f11d2a824">m_objptr</a>-&gt;*<a class="code" href="class_plugin_thread_pool_1_1_command.html#7552d1a7c1afc09dcdd886e7ade68789">method</a>)();<a name="l00197"></a>00197                 }<a name="l00198"></a>00198                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="class_plugin_thread_pool_1_1_command.html#09eb6f552921e01ef734cfb42790caa2">method0</a>)<a name="l00199"></a>00199                 {<a name="l00200"></a>00200                         (*method0)();<a name="l00201"></a>00201                 }<a name="l00202"></a>00202                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="class_plugin_thread_pool_1_1_command.html#5aaecab58914d6fca0996d12d5c802b9">method1</a>)<a name="l00203"></a>00203                 {<a name="l00204"></a>00204                         (*method1)(<a class="code" href="class_plugin_thread_pool_1_1_command.html#03e2cf02a2ff39a8d614d56bd0345682">m_par1</a>);<a name="l00205"></a>00205                 }<a name="l00206"></a>00206                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="class_plugin_thread_pool_1_1_command.html#e81dab19d4e8944a4c349c220599946e">method3</a>)<a name="l00207"></a>00207                 {<a name="l00208"></a>00208                         (*method3)();<a name="l00209"></a>00209                 }<a name="l00210"></a>00210 <a name="l00211"></a>00211         }<a name="l00212"></a>00212 <a name="l00216"></a>00216         <a name="l00217"></a><a class="code" href="class_plugin_thread_pool_1_1_command.html#2830b94ad2a119732a997ee16caf71ac">00217</a>         <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="class_plugin_thread_pool_1_1_command.html#2830b94ad2a119732a997ee16caf71ac">GetTimeOut</a>()<a name="l00218"></a>00218         {<a name="l00219"></a>00219                 <span class="keywordflow">return</span> <a class="code" href="class_plugin_thread_pool_1_1_command.html#0813562408adb30c60ad501c8b533b00">m_timeout</a>;<a name="l00220"></a>00220         }<a name="l00221"></a>00221 <a name="l00223"></a>00223 <a name="l00224"></a><a class="code" href="class_plugin_thread_pool_1_1_command.html#febd44d2f529c23fe396c5b2b7b6371f">00224</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_plugin_thread_pool_1_1_command.html#febd44d2f529c23fe396c5b2b7b6371f">GetKey</a>()<a name="l00225"></a>00225         {<a name="l00226"></a>00226                 <span class="keywordflow">return</span> <a class="code" href="class_plugin_thread_pool_1_1_command.html#fddd2bd375dcf04591dd54a690ac8525">RSHash</a>(<a class="code" href="class_plugin_thread_pool_1_1_command.html#a79238db30e99d1c03f72050ba48a898">m_key</a>);<a name="l00227"></a>00227         }<a name="l00228"></a>00228 <a name="l00229"></a>00229         <a name="l00230"></a><a class="code" href="class_plugin_thread_pool_1_1_command.html#c0f4bb7f637556ceabce1575f5ea6112">00230</a>          <span class="keywordtype">bool</span> operator &lt; (const Command&lt;T&gt;&amp; a) <span class="keyword">const</span><a name="l00231"></a>00231         {<a name="l00232"></a>00232                 <span class="keywordflow">return</span> <a class="code" href="class_plugin_thread_pool_1_1_command.html#199d3a70de4ff59db4f85f09a9fe0bdf">m_value</a> &lt; a.m_value;<a name="l00233"></a>00233         }<a name="l00234"></a>00234 <a name="l00237"></a>00237         <a name="l00238"></a><a class="code" href="class_plugin_thread_pool_1_1_command.html#89490137659a8ff9d66c16eb7d72b0c5">00238</a>         <a class="code" href="class_plugin_thread_pool_1_1_command.html#89490137659a8ff9d66c16eb7d72b0c5">~Command</a>(){}; <a name="l00239"></a>00239 <a name="l00240"></a>00240 <span class="keyword">private</span>:<a name="l00243"></a>00243 <a name="l00244"></a><a class="code" href="class_plugin_thread_pool_1_1_command.html#fddd2bd375dcf04591dd54a690ac8525">00244</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_plugin_thread_pool_1_1_command.html#fddd2bd375dcf04591dd54a690ac8525">RSHash</a>(<span class="keyword">const</span> std::string&amp; str)<a name="l00245"></a>00245         {<a name="l00246"></a>00246            <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> b    = 378551;<a name="l00247"></a>00247            <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> a    = 63689;<a name="l00248"></a>00248            <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> hash = 0;<a name="l00249"></a>00249 <a name="l00250"></a>00250            <span class="keywordflow">for</span>(size_t i = 0; i &lt; str.length(); i++)<a name="l00251"></a>00251            {<a name="l00252"></a>00252                   hash = hash * a + str[i];<a name="l00253"></a>00253                   a    = a * b;<a name="l00254"></a>00254            }<a name="l00255"></a>00255 <a name="l00256"></a>00256            <span class="keywordflow">return</span> hash;<a name="l00257"></a>00257         }<a name="l00258"></a>00258 <a name="l00261"></a><a class="code" href="class_plugin_thread_pool_1_1_command_1_1_compare.html">00261</a>         <span class="keyword">class </span><a class="code" href="class_plugin_thread_pool_1_1_command_1_1_compare.html">Compare</a><a name="l00262"></a>00262         {<a name="l00263"></a>00263         <span class="keyword">public</span>:<a name="l00264"></a>00264                 <a name="l00265"></a><a class="code" href="class_plugin_thread_pool_1_1_command_1_1_compare.html#8990f88878dea6014d95d1cb6dc1fc9e">00265</a>                 <span class="keywordtype">bool</span> <a class="code" href="class_plugin_thread_pool_1_1_command_1_1_compare.html#8990f88878dea6014d95d1cb6dc1fc9e">operator()</a>(<span class="keyword">const</span> <a class="code" href="class_plugin_thread_pool_1_1_command.html">Command&lt;T&gt;</a>* a1,<span class="keyword">const</span> <a class="code" href="class_plugin_thread_pool_1_1_command.html">Command&lt;T&gt;</a>* a2)<span class="keyword"> const</span><a name="l00266"></a>00266 <span class="keyword">                </span>{<a name="l00267"></a>00267                         <span class="keywordflow">return</span>  *a1 &lt; *a2;<a name="l00268"></a>00268                 }<a name="l00269"></a>00269         };<a name="l00270"></a>00270 <a name="l00271"></a>00271 };<a name="l00272"></a>00272 <a name="l00273"></a>00273 }<a name="l00274"></a>00274 <a name="l00275"></a>00275 <a name="l00276"></a>00276 <span class="preprocessor">#endif </span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Jan 20 13:16:01 2008 for ThreadPool by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address></body></html>

⌨️ 快捷键说明

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