Home | History | Annotate | Download | only in oscl_html
      1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
      3 <title>oscl_tls.h Source File</title>
      4 <link href="doxygen.css" rel="stylesheet" type="text/css">
      5 </head><body>
      6 <!-- Generated by Doxygen 1.2.18 -->
      7 <center>
      8 <a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; </center>
      9 <hr><h1>oscl_tls.h</h1><a href="oscl__tls_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">// -*- c++ -*-</span>
     10 00002 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
     11 00003 
     12 00004 <span class="comment">//                     O S C L _ T L S</span>
     13 00005 
     14 00006 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
     15 00007 
     16 00022 <span class="preprocessor">#ifndef OSCL_TLS_H_INCLUDED</span>
     17 00023 <span class="preprocessor"></span><span class="preprocessor">#define OSCL_TLS_H_INCLUDED</span>
     18 00024 <span class="preprocessor"></span>
     19 00025 <span class="preprocessor">#ifndef OSCL_BASE_H_INCLUDED</span>
     20 00026 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__base_8h.html">oscl_base.h</a>"</span>
     21 00027 <span class="preprocessor">#endif</span>
     22 00028 <span class="preprocessor"></span>
     23 00029 <span class="preprocessor">#ifndef OSCL_DEFALLOC_H_INCLUDED</span>
     24 00030 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__defalloc_8h.html">oscl_defalloc.h</a>"</span>
     25 00031 <span class="preprocessor">#endif</span>
     26 00032 <span class="preprocessor"></span>
     27 00033 
     28 00034 <span class="preprocessor">#if (OSCL_TLS_IS_KEYED)</span>
     29 00035 <span class="preprocessor"></span>
     30 00036 <span class="comment">//Keyed TLS requires global variable support</span>
     31 00037 <span class="preprocessor">#else</span>
     32 00038 <span class="preprocessor"></span>
     33 00039 <span class="comment">//unused value.</span>
     34 <a name="l00040"></a><a class="code" href="group__osclbase.html#a10">00040</a> <span class="keyword">typedef</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a> <a class="code" href="group__osclbase.html#a10">TOsclTlsKey</a>;
     35 00041 
     36 00042 <span class="preprocessor">#endif //OSCL_TLS_IS_KEYED</span>
     37 00043 <span class="preprocessor"></span>
     38 00044 
     39 00045 <span class="comment">// list of TLS objects</span>
     40 <a name="l00046"></a><a class="code" href="group__osclbase.html#a11">00046</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a11">OSCL_TLS_ID_MAGICNUM</a>       = 0;
     41 <a name="l00047"></a><a class="code" href="group__osclbase.html#a12">00047</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a12">OSCL_TLS_ID_ERRORHOOK</a>      = 1;
     42 <a name="l00048"></a><a class="code" href="group__osclbase.html#a13">00048</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a13">OSCL_TLS_ID_PVLOGGER</a>       = 2;
     43 <a name="l00049"></a><a class="code" href="group__osclbase.html#a14">00049</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a14">OSCL_TLS_ID_TEST</a>           = 3;
     44 <a name="l00050"></a><a class="code" href="group__osclbase.html#a15">00050</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a15">OSCL_TLS_ID_PVSCHEDULER</a>    = 4;
     45 <a name="l00051"></a><a class="code" href="group__osclbase.html#a16">00051</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a16">OSCL_TLS_ID_PVERRORTRAP</a>    = 5;
     46 <a name="l00052"></a><a class="code" href="group__osclbase.html#a17">00052</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a17">OSCL_TLS_ID_SDPMEDIAPARSER</a> = 6;
     47 <a name="l00053"></a><a class="code" href="group__osclbase.html#a18">00053</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a18">OSCL_TLS_ID_PAYLOADPARSER</a>  = 7;
     48 <a name="l00054"></a><a class="code" href="group__osclbase.html#a19">00054</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a19">OSCL_TLS_ID_PVMFRECOGNIZER</a> = 8;
     49 <a name="l00055"></a><a class="code" href="group__osclbase.html#a20">00055</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a20">OSCL_TLS_ID_WMDRM</a>          = 9;
     50 <a name="l00056"></a><a class="code" href="group__osclbase.html#a21">00056</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a21">OSCL_TLS_ID_OSCLREGISTRY</a>   = 10;
     51 <a name="l00057"></a><a class="code" href="group__osclbase.html#a22">00057</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a22">OSCL_TLS_ID_SQLITE3</a>        = 11;
     52 <a name="l00058"></a><a class="code" href="group__osclbase.html#a23">00058</a> <span class="keyword">const</span> uint32 <a class="code" href="group__osclbase.html#a23">OSCL_TLS_ID_BASE_LAST</a>      = 11; <span class="comment">// should always equal the largest ID defined here</span>
     53 00059 
     54 <a name="l00060"></a><a class="code" href="group__osclbase.html#a106">00060</a> <span class="preprocessor">#define OSCL_TLS_BASE_SLOTS OSCL_TLS_ID_BASE_LAST +1</span>
     55 00061 <span class="preprocessor"></span>
     56 00062 <span class="comment">//There may be additional slots defined in the osclconfig.h for the build.</span>
     57 00063 <span class="preprocessor">#ifndef OSCL_TLS_EXTERNAL_SLOTS</span>
     58 <a name="l00064"></a><a class="code" href="group__osclbase.html#a107">00064</a> <span class="preprocessor"></span><span class="preprocessor">#define OSCL_TLS_EXTERNAL_SLOTS 0</span>
     59 00065 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
     60 00066 <span class="preprocessor"></span>
     61 <a name="l00067"></a><a class="code" href="group__osclbase.html#a108">00067</a> <span class="preprocessor">#define OSCL_TLS_MAX_SLOTS ( OSCL_TLS_BASE_SLOTS + OSCL_TLS_EXTERNAL_SLOTS)</span>
     62 00068 <span class="preprocessor"></span>
     63 <a name="l00069"></a><a class="code" href="classTLSStorageOps.html">00069</a> <span class="keyword">class </span><a class="code" href="classTLSStorageOps.html">TLSStorageOps</a>
     64 00070 {
     65 00071     <span class="keyword">public</span>:
     66 00072         OSCL_IMPORT_REF <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classTLSStorageOps.html#d0">save_registry</a>(<a class="code" href="group__osclbase.html#a10">TOsclTlsKey</a>* key, <a class="code" href="group__osclbase.html#a25">OsclAny</a>* ptr, int32&amp;);
     67 00073         OSCL_IMPORT_REF <span class="keyword">static</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* <a class="code" href="classTLSStorageOps.html#d1">get_registry</a>(<a class="code" href="group__osclbase.html#a10">TOsclTlsKey</a>* key);
     68 00074 };
     69 00075 
     70 <a name="l00076"></a><a class="code" href="classOsclTLSRegistry.html">00076</a> <span class="keyword">class </span><a class="code" href="classOsclTLSRegistry.html">OsclTLSRegistry</a>
     71 00077 {
     72 00078     <span class="keyword">public</span>:
     73 00079         <span class="comment">/*</span>
     74 00080 <span class="comment">        ** Get an entry</span>
     75 00081 <span class="comment">        ** @param ID: identifier</span>
     76 00082 <span class="comment">        ** @param error (output) 0 for success or an error from TPVBaseErrorEnum</span>
     77 00083 <span class="comment">        ** @returns: the entry value</span>
     78 00084 <span class="comment">        */</span>
     79 00085         OSCL_IMPORT_REF <span class="keyword">static</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* <a class="code" href="classOsclTLSRegistry.html#d0">getInstance</a>(uint32 ID, int32 &amp;error);
     80 00086         <span class="comment">/*</span>
     81 00087 <span class="comment">        ** Set an entry</span>
     82 00088 <span class="comment">        ** @param ID: identifier</span>
     83 00089 <span class="comment">        ** @param error (output) 0 for success or an error from TPVBaseErrorEnum</span>
     84 00090 <span class="comment">        ** @returns: the entry value</span>
     85 00091 <span class="comment">        */</span>
     86 00092         OSCL_IMPORT_REF <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classOsclTLSRegistry.html#d1">registerInstance</a>(<a class="code" href="group__osclbase.html#a25">OsclAny</a>* ptr, uint32 ID, int32 &amp;error);
     87 00093 
     88 00094     <span class="keyword">private</span>:
     89 00095         <a class="code" href="classOsclTLSRegistry.html">OsclTLSRegistry</a>()
     90 00096         {}
     91 00097         <span class="keyword">typedef</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* registry_type;
     92 00098         <span class="keyword">typedef</span> registry_type* registry_pointer_type;
     93 00099 
     94 00100 <span class="preprocessor">#if ( OSCL_TLS_IS_KEYED)</span>
     95 00101 <span class="preprocessor"></span>        <span class="keyword">class </span>TlsKey
     96 00102         {
     97 00103             <span class="keyword">public</span>:
     98 00104                 TlsKey(): iRefCnt(0), iOsclTlsKey(<a class="code" href="group__osclbase.html#a81">NULL</a>)
     99 00105                 {}
    100 00106                 _OsclBasicLock iLock;
    101 00107                 uint32 iRefCnt;
    102 00108                 <a class="code" href="group__osclbase.html#a10">TOsclTlsKey</a> *iOsclTlsKey;
    103 00109         };
    104 00110 
    105 00111         <span class="comment">//The key is a global variable.</span>
    106 00112         <span class="keyword">static</span> TlsKey* iTlsKey;
    107 00113 <span class="preprocessor">#endif</span>
    108 00114 <span class="preprocessor"></span>
    109 00115     <span class="keyword">private</span>:
    110 00116         OSCL_IMPORT_REF <span class="keyword">static</span> <span class="keywordtype">void</span> initialize(<a class="code" href="classOscl__DefAlloc.html">Oscl_DefAlloc</a> &amp;alloc, int32 &amp;error);
    111 00117         OSCL_IMPORT_REF <span class="keyword">static</span> <span class="keywordtype">void</span> cleanup(<a class="code" href="classOscl__DefAlloc.html">Oscl_DefAlloc</a> &amp;alloc, int32 &amp;error);
    112 <a name="l00118"></a><a class="code" href="classOsclTLSRegistry.html#l0">00118</a>         <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classOsclTLSRegistry.html#l0">OsclBase</a>;
    113 00119 
    114 00120 };
    115 <a name="l00121"></a><a class="code" href="classOsclTLS.html">00121</a> 
    116 00122 <span class="keyword">template</span> &lt; <span class="keyword">class</span> T, u<span class="keywordtype">int</span>32 ID, <span class="keyword">class</span> Registry = OsclTLSRegistry &gt; <span class="keyword">class </span><a class="code" href="classOsclTLS.html">OsclTLS</a>
    117 00123 {
    118 00124     <span class="keyword">private</span>:
    119 00125         <span class="comment">// make the copy constructor and assignment operator private</span>
    120 00126         <a class="code" href="classOsclTLS.html">OsclTLS</a>&amp; operator=(<a class="code" href="classOsclTLS.html">OsclTLS</a>&amp; _Y)
    121 00127         {
    122 00128             <span class="keywordflow">return</span>(*this);
    123 00129         }
    124 00130 
    125 <a name="l00131"></a><a class="code" href="classOsclTLS.html#n0">00131</a>     <span class="keyword">protected</span>:
    126 00132         T* <a class="code" href="classOsclTLS.html#n0">_Ptr</a>;
    127 00133 
    128 <a name="l00134"></a><a class="code" href="classOsclTLS.html#a0">00134</a>     <span class="keyword">public</span>:
    129 00135         <a class="code" href="classOsclTLS.html#a0">OsclTLS</a>()
    130 00136         {
    131 00137             int32 err;
    132 00138             <a class="code" href="classOsclTLS.html#n0">_Ptr</a> = <a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(T*, Registry::getInstance(ID, err));
    133 00139         }
    134 <a name="l00140"></a><a class="code" href="classOsclTLS.html#a1">00140</a> 
    135 00141         <a class="code" href="classOsclTLS.html#a1">~OsclTLS</a>() {};
    136 00142 
    137 00150         T&amp; <a class="code" href="classOsclTLS.html#a2">operator*</a>()<span class="keyword"> const</span>
    138 00151 <span class="keyword">        </span>{
    139 00152             <span class="keywordflow">return</span>(*_Ptr);
    140 00153         }
    141 00154 
    142 00162         T *<a class="code" href="classOsclTLS.html#a3">operator-&gt;</a>()<span class="keyword"> const</span>
    143 00163 <span class="keyword">        </span>{
    144 00164             <span class="keywordflow">return</span>(_Ptr);
    145 00165         }
    146 00166 
    147 00167 
    148 00174         <span class="keywordtype">bool</span> <a class="code" href="classOsclTLS.html#a4">set</a>()
    149 00175         {
    150 00176             int32 err;
    151 00177             <a class="code" href="classOsclTLS.html#n0">_Ptr</a> = <a class="code" href="group__osclbase.html#a86">OSCL_STATIC_CAST</a>(T*, Registry::getInstance(ID, err));
    152 00178             <span class="keywordflow">return</span> (<a class="code" href="classOsclTLS.html#n0">_Ptr</a> ? <span class="keyword">true</span> : <span class="keyword">false</span>);
    153 00179         }
    154 00180 
    155 00181 };
    156 00182 
    157 00187 <span class="preprocessor">#endif</span>
    158 00188 <span class="preprocessor"></span>
    159 </pre></div><hr size="1"><img src="pvlogo_small.jpg"><address style="align: right;"><small>OSCL API</small>
    160 <address style="align: left;"><small>Posting Version: OPENCORE_20090310 </small>
    161 </small></address>
    162 </body>
    163 </html>
    164