Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > media > contrib-backports > by-pkgid > 4f5f2dc0f55b453456458df885792b0b > files > 471

ucommon-doc-5.0.4-1mdv2010.2.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>ucommon: ucommon/access.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<h1>ucommon/access.h</h1><a href="a00177.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (C) 2006-2010 David Sugar, Tycho Softworks.</span>
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// This file is part of GNU uCommon C++.</span>
<a name="l00004"></a>00004 <span class="comment">//</span>
<a name="l00005"></a>00005 <span class="comment">// GNU uCommon C++ is free software: you can redistribute it and/or modify</span>
<a name="l00006"></a>00006 <span class="comment">// it under the terms of the GNU Lesser General Public License as published</span>
<a name="l00007"></a>00007 <span class="comment">// by the Free Software Foundation, either version 3 of the License, or</span>
<a name="l00008"></a>00008 <span class="comment">// (at your option) any later version.</span>
<a name="l00009"></a>00009 <span class="comment">//</span>
<a name="l00010"></a>00010 <span class="comment">// GNU uCommon C++ is distributed in the hope that it will be useful,</span>
<a name="l00011"></a>00011 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00012"></a>00012 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00013"></a>00013 <span class="comment">// GNU Lesser General Public License for more details.</span>
<a name="l00014"></a>00014 <span class="comment">//</span>
<a name="l00015"></a>00015 <span class="comment">// You should have received a copy of the GNU Lesser General Public License</span>
<a name="l00016"></a>00016 <span class="comment">// along with GNU uCommon C++.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<a name="l00017"></a>00017 
<a name="l00031"></a>00031 <span class="comment">// we do this twice because of some bizarre issue in just this file that</span>
<a name="l00032"></a>00032 <span class="comment">// otherwise breaks doxygen and lists all items outside the namespace...</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;<a class="code" href="a00194.html" title="Various miscellaneous platform specific headers and defines.">ucommon/platform.h</a>&gt;</span>
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <span class="preprocessor">#ifndef _UCOMMON_ACCESS_H_</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define _UCOMMON_ACCESS_H_</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span>
<a name="l00038"></a>00038 <span class="preprocessor">#ifndef _UCOMMON_CONFIG_H_</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#include &lt;<a class="code" href="a00194.html" title="Various miscellaneous platform specific headers and defines.">ucommon/platform.h</a>&gt;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#endif</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span>
<a name="l00042"></a>00042 NAMESPACE_UCOMMON
<a name="l00043"></a>00043 
<a name="l00050"></a><a class="code" href="a00049.html">00050</a> <span class="keyword">class </span>__EXPORT <a class="code" href="a00049.html" title="An exclusive locking protocol interface base.">ExclusiveProtocol</a>
<a name="l00051"></a>00051 {
<a name="l00052"></a>00052 <span class="keyword">protected</span>:
<a name="l00053"></a>00053     <span class="keyword">virtual</span> ~<a class="code" href="a00049.html" title="An exclusive locking protocol interface base.">ExclusiveProtocol</a>();
<a name="l00054"></a>00054 
<a name="l00055"></a>00055 <span class="keyword">public</span>:
<a name="l00059"></a>00059     <span class="keyword">virtual</span> <span class="keywordtype">void</span> Exlock(<span class="keywordtype">void</span>) = 0;
<a name="l00060"></a>00060 
<a name="l00064"></a>00064     <span class="keyword">virtual</span> <span class="keywordtype">void</span> Unlock(<span class="keywordtype">void</span>) = 0;
<a name="l00065"></a>00065 
<a name="l00069"></a><a class="code" href="a00049.html#a7927879554dd291789dc21a828d66e66">00069</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> Lock(<span class="keywordtype">void</span>)
<a name="l00070"></a>00070         {Exlock();};
<a name="l00071"></a>00071 };
<a name="l00072"></a>00072 
<a name="l00079"></a><a class="code" href="a00128.html">00079</a> <span class="keyword">class </span>__EXPORT <a class="code" href="a00128.html" title="An exclusive locking protocol interface base.">SharedProtocol</a>
<a name="l00080"></a>00080 {
<a name="l00081"></a>00081 <span class="keyword">protected</span>:
<a name="l00082"></a>00082     <span class="keyword">virtual</span> ~<a class="code" href="a00128.html" title="An exclusive locking protocol interface base.">SharedProtocol</a>();
<a name="l00083"></a>00083 
<a name="l00084"></a>00084 <span class="keyword">public</span>:
<a name="l00088"></a>00088     <span class="keyword">virtual</span> <span class="keywordtype">void</span> Shlock(<span class="keywordtype">void</span>) = 0;
<a name="l00089"></a>00089 
<a name="l00093"></a>00093     <span class="keyword">virtual</span> <span class="keywordtype">void</span> Unlock(<span class="keywordtype">void</span>) = 0;
<a name="l00094"></a>00094 
<a name="l00101"></a>00101     <span class="keyword">virtual</span> <span class="keywordtype">void</span> Share(<span class="keywordtype">void</span>);
<a name="l00102"></a>00102 
<a name="l00110"></a>00110     <span class="keyword">virtual</span> <span class="keywordtype">void</span> Exclusive(<span class="keywordtype">void</span>);
<a name="l00111"></a>00111 
<a name="l00115"></a><a class="code" href="a00128.html#aa388c6608baa4f5594992f40864c9e80">00115</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> Lock(<span class="keywordtype">void</span>)
<a name="l00116"></a>00116         {Shlock();};
<a name="l00117"></a>00117 };
<a name="l00118"></a>00118 
<a name="l00126"></a><a class="code" href="a00048.html">00126</a> <span class="keyword">class </span>__EXPORT <a class="code" href="a00048.html" title="A kind of smart pointer object to support exclusive locking protocol.">exclusive_lock</a>
<a name="l00127"></a>00127 {
<a name="l00128"></a>00128 <span class="keyword">private</span>:
<a name="l00129"></a>00129     <a class="code" href="a00049.html" title="An exclusive locking protocol interface base.">ExclusiveProtocol</a> *<a class="code" href="a00208.html#a93b9eec9d0b7db95ce778265f806afd6" title="Convenience function to exclusively lock an object through it&amp;#39;s protocol.">lock</a>;
<a name="l00130"></a>00130 
<a name="l00131"></a>00131 <span class="keyword">public</span>:
<a name="l00136"></a>00136     <a class="code" href="a00048.html" title="A kind of smart pointer object to support exclusive locking protocol.">exclusive_lock</a>(<a class="code" href="a00049.html" title="An exclusive locking protocol interface base.">ExclusiveProtocol</a> *<span class="keywordtype">object</span>);
<a name="l00137"></a>00137 
<a name="l00141"></a>00141     ~<a class="code" href="a00048.html" title="A kind of smart pointer object to support exclusive locking protocol.">exclusive_lock</a>();
<a name="l00142"></a>00142 
<a name="l00147"></a><a class="code" href="a00048.html#ae4bf8b4b8628aa9903bb63d7b3ada5e9">00147</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> operator!()<span class="keyword"> const</span>
<a name="l00148"></a>00148 <span class="keyword">        </span>{<span class="keywordflow">return</span> <a class="code" href="a00208.html#a93b9eec9d0b7db95ce778265f806afd6" title="Convenience function to exclusively lock an object through it&amp;#39;s protocol.">lock</a> == NULL;};
<a name="l00149"></a>00149 
<a name="l00154"></a><a class="code" href="a00048.html#af679076ecdf5b5dbf40f8e80990f4939">00154</a>     <span class="keyword">inline</span> operator bool()<span class="keyword"> const</span>
<a name="l00155"></a>00155 <span class="keyword">        </span>{<span class="keywordflow">return</span> <a class="code" href="a00208.html#a93b9eec9d0b7db95ce778265f806afd6" title="Convenience function to exclusively lock an object through it&amp;#39;s protocol.">lock</a> != NULL;};
<a name="l00156"></a>00156 
<a name="l00162"></a>00162     <span class="keywordtype">void</span> <a class="code" href="a00208.html#a8df8e4b667d68be02961ff0d4cd84224" title="Convenience function to unlock shared object through it&amp;#39;s protocol.">release</a>(<span class="keywordtype">void</span>);
<a name="l00163"></a>00163 };
<a name="l00164"></a>00164 
<a name="l00172"></a><a class="code" href="a00123.html">00172</a> <span class="keyword">class </span>__EXPORT <a class="code" href="a00123.html" title="A kind of smart pointer object to support shared locking protocol.">shared_lock</a>
<a name="l00173"></a>00173 {
<a name="l00174"></a>00174 <span class="keyword">private</span>:
<a name="l00175"></a>00175     <a class="code" href="a00128.html" title="An exclusive locking protocol interface base.">SharedProtocol</a> *<a class="code" href="a00208.html#a93b9eec9d0b7db95ce778265f806afd6" title="Convenience function to exclusively lock an object through it&amp;#39;s protocol.">lock</a>;
<a name="l00176"></a>00176     <span class="keywordtype">int</span> state;
<a name="l00177"></a>00177     <span class="keywordtype">bool</span> <a class="code" href="a00208.html#a7bbf6bb584edfaa7d0cf79c1312ea26f" title="Convenience function to exclusively schedule conditional access.">modify</a>;
<a name="l00178"></a>00178 
<a name="l00179"></a>00179 <span class="keyword">public</span>:
<a name="l00184"></a>00184     <a class="code" href="a00123.html" title="A kind of smart pointer object to support shared locking protocol.">shared_lock</a>(<a class="code" href="a00128.html" title="An exclusive locking protocol interface base.">SharedProtocol</a> *<span class="keywordtype">object</span>);
<a name="l00185"></a>00185 
<a name="l00189"></a>00189     ~<a class="code" href="a00123.html" title="A kind of smart pointer object to support shared locking protocol.">shared_lock</a>();
<a name="l00190"></a>00190 
<a name="l00195"></a><a class="code" href="a00123.html#a71d26fe47338fd1dbc78423ffe83024d">00195</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> operator!()<span class="keyword"> const</span>
<a name="l00196"></a>00196 <span class="keyword">        </span>{<span class="keywordflow">return</span> <a class="code" href="a00208.html#a93b9eec9d0b7db95ce778265f806afd6" title="Convenience function to exclusively lock an object through it&amp;#39;s protocol.">lock</a> == NULL;};
<a name="l00197"></a>00197 
<a name="l00202"></a><a class="code" href="a00123.html#a8eaeb708052403dd028a1b779613e773">00202</a>     <span class="keyword">inline</span> operator bool()<span class="keyword"> const</span>
<a name="l00203"></a>00203 <span class="keyword">        </span>{<span class="keywordflow">return</span> <a class="code" href="a00208.html#a93b9eec9d0b7db95ce778265f806afd6" title="Convenience function to exclusively lock an object through it&amp;#39;s protocol.">lock</a> != NULL;};
<a name="l00204"></a>00204 
<a name="l00210"></a>00210     <span class="keywordtype">void</span> <a class="code" href="a00208.html#a8df8e4b667d68be02961ff0d4cd84224" title="Convenience function to unlock shared object through it&amp;#39;s protocol.">release</a>(<span class="keywordtype">void</span>);
<a name="l00211"></a>00211 
<a name="l00215"></a>00215     <span class="keywordtype">void</span> <a class="code" href="a00208.html#a38f16b6c76465ba13751ff3b5be4a41e" title="Convenience function to exclusive lock shared object through it&amp;#39;s protocol.">exclusive</a>(<span class="keywordtype">void</span>);
<a name="l00216"></a>00216 
<a name="l00220"></a>00220     <span class="keywordtype">void</span> <a class="code" href="a00208.html#aa738a981d717c379a3facda88eafbdea" title="Convenience function to restore shared locking for object through it&amp;#39;s protocol...">share</a>(<span class="keywordtype">void</span>);
<a name="l00221"></a>00221 };
<a name="l00222"></a>00222 
<a name="l00227"></a><a class="code" href="a00208.html#a93b9eec9d0b7db95ce778265f806afd6">00227</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00208.html#a93b9eec9d0b7db95ce778265f806afd6" title="Convenience function to exclusively lock an object through it&amp;#39;s protocol.">lock</a>(<a class="code" href="a00049.html" title="An exclusive locking protocol interface base.">ExclusiveProtocol</a> *<span class="keywordtype">object</span>)
<a name="l00228"></a>00228     {<span class="keywordtype">object</span>-&gt;Exlock();}
<a name="l00229"></a>00229 
<a name="l00234"></a><a class="code" href="a00208.html#a06fc306b76334e4410e554d683ae790b">00234</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00208.html#a06fc306b76334e4410e554d683ae790b" title="Convenience function to unlock an exclusive object through it&amp;#39;s protocol.">unlock</a>(<a class="code" href="a00049.html" title="An exclusive locking protocol interface base.">ExclusiveProtocol</a> *<span class="keywordtype">object</span>)
<a name="l00235"></a>00235     {<span class="keywordtype">object</span>-&gt;Unlock();}
<a name="l00236"></a>00236 
<a name="l00241"></a><a class="code" href="a00208.html#a5422fe5f7269f2606c8317e29e4147bf">00241</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00208.html#a5422fe5f7269f2606c8317e29e4147bf" title="Convenience function to access (lock) shared object through it&amp;#39;s protocol.">access</a>(<a class="code" href="a00128.html" title="An exclusive locking protocol interface base.">SharedProtocol</a> *<span class="keywordtype">object</span>)
<a name="l00242"></a>00242     {<span class="keywordtype">object</span>-&gt;Shlock();}
<a name="l00243"></a>00243 
<a name="l00248"></a><a class="code" href="a00208.html#a8df8e4b667d68be02961ff0d4cd84224">00248</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00208.html#a8df8e4b667d68be02961ff0d4cd84224" title="Convenience function to unlock shared object through it&amp;#39;s protocol.">release</a>(<a class="code" href="a00128.html" title="An exclusive locking protocol interface base.">SharedProtocol</a> *<span class="keywordtype">object</span>)
<a name="l00249"></a>00249     {<span class="keywordtype">object</span>-&gt;Unlock();}
<a name="l00250"></a>00250 
<a name="l00255"></a><a class="code" href="a00208.html#a38f16b6c76465ba13751ff3b5be4a41e">00255</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00208.html#a38f16b6c76465ba13751ff3b5be4a41e" title="Convenience function to exclusive lock shared object through it&amp;#39;s protocol.">exclusive</a>(<a class="code" href="a00128.html" title="An exclusive locking protocol interface base.">SharedProtocol</a> *<span class="keywordtype">object</span>)
<a name="l00256"></a>00256     {<span class="keywordtype">object</span>-&gt;Exclusive();}
<a name="l00257"></a>00257 
<a name="l00262"></a><a class="code" href="a00208.html#aa738a981d717c379a3facda88eafbdea">00262</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00208.html#aa738a981d717c379a3facda88eafbdea" title="Convenience function to restore shared locking for object through it&amp;#39;s protocol...">share</a>(<a class="code" href="a00128.html" title="An exclusive locking protocol interface base.">SharedProtocol</a> *<span class="keywordtype">object</span>)
<a name="l00263"></a>00263     {<span class="keywordtype">object</span>-&gt;Share();}
<a name="l00264"></a>00264 
<a name="l00268"></a><a class="code" href="a00208.html#ac1b206748a4675583711dd2a60c0d435">00268</a> <span class="keyword">typedef</span> <a class="code" href="a00048.html" title="A kind of smart pointer object to support exclusive locking protocol.">exclusive_lock</a> <a class="code" href="a00048.html" title="A kind of smart pointer object to support exclusive locking protocol.">exlock_t</a>;
<a name="l00269"></a>00269 
<a name="l00273"></a><a class="code" href="a00208.html#a0aa2b11125533b17b59cea4e63182e37">00273</a> <span class="keyword">typedef</span> <a class="code" href="a00123.html" title="A kind of smart pointer object to support shared locking protocol.">shared_lock</a> <a class="code" href="a00123.html" title="A kind of smart pointer object to support shared locking protocol.">shlock_t</a>;
<a name="l00274"></a>00274 
<a name="l00279"></a><a class="code" href="a00208.html#a447e496c6053ef4532637ed44bec2b63">00279</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00208.html#a8df8e4b667d68be02961ff0d4cd84224" title="Convenience function to unlock shared object through it&amp;#39;s protocol.">release</a>(<a class="code" href="a00048.html" title="A kind of smart pointer object to support exclusive locking protocol.">exlock_t</a> &amp;reference)
<a name="l00280"></a>00280     {reference.<a class="code" href="a00048.html#af482434acdffdbf45128c0790940525a" title="Release a held lock programmatically.">release</a>();}
<a name="l00281"></a>00281 
<a name="l00286"></a><a class="code" href="a00208.html#a40cad4d2f99609499746d66063c5a04b">00286</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00208.html#a8df8e4b667d68be02961ff0d4cd84224" title="Convenience function to unlock shared object through it&amp;#39;s protocol.">release</a>(<a class="code" href="a00123.html" title="A kind of smart pointer object to support shared locking protocol.">shlock_t</a> &amp;reference)
<a name="l00287"></a>00287     {reference.<a class="code" href="a00123.html#ab228bedc31fa65db1608778ae5d21ffc" title="Release a held lock programmatically.">release</a>();}
<a name="l00288"></a>00288 
<a name="l00289"></a>00289 <span class="comment">// Special macros to allow member functions of an object with a protocol</span>
<a name="l00290"></a>00290 <span class="comment">// to create self locking states while the member functions are called by</span>
<a name="l00291"></a>00291 <span class="comment">// placing an exclusive_lock or shared_lock smart object on their stack</span>
<a name="l00292"></a>00292 <span class="comment">// frame to reference their self.</span>
<a name="l00293"></a>00293 
<a name="l00294"></a>00294 <span class="preprocessor">#define exclusive_object()  exlock_t __autolock__ = this</span>
<a name="l00295"></a>00295 <span class="preprocessor"></span><span class="preprocessor">#define protected_object()  shlock_t __autolock__ = this</span>
<a name="l00296"></a>00296 <span class="preprocessor"></span><span class="preprocessor">#define exclusive_access(x) exlock_t __autolock__ = &amp;x</span>
<a name="l00297"></a>00297 <span class="preprocessor"></span><span class="preprocessor">#define protected_access(x) shlock_t __autolock__ = &amp;x</span>
<a name="l00298"></a>00298 <span class="preprocessor"></span>
<a name="l00299"></a>00299 END_NAMESPACE
<a name="l00300"></a>00300 
<a name="l00301"></a>00301 <span class="preprocessor">#endif</span>
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Thu Jul 14 16:38:56 2011 for ucommon by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>