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> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="globals.html">Globals</a> </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> 1000002 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span> 1100003 1200004 <span class="comment">// O S C L _ T L S</span> 1300005 1400006 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span> 1500007 1600022 <span class="preprocessor">#ifndef OSCL_TLS_H_INCLUDED</span> 1700023 <span class="preprocessor"></span><span class="preprocessor">#define OSCL_TLS_H_INCLUDED</span> 1800024 <span class="preprocessor"></span> 1900025 <span class="preprocessor">#ifndef OSCL_BASE_H_INCLUDED</span> 2000026 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__base_8h.html">oscl_base.h</a>"</span> 2100027 <span class="preprocessor">#endif</span> 2200028 <span class="preprocessor"></span> 2300029 <span class="preprocessor">#ifndef OSCL_DEFALLOC_H_INCLUDED</span> 2400030 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__defalloc_8h.html">oscl_defalloc.h</a>"</span> 2500031 <span class="preprocessor">#endif</span> 2600032 <span class="preprocessor"></span> 2700033 2800034 <span class="preprocessor">#if (OSCL_TLS_IS_KEYED)</span> 2900035 <span class="preprocessor"></span> 3000036 <span class="comment">//Keyed TLS requires global variable support</span> 3100037 <span class="preprocessor">#else</span> 3200038 <span class="preprocessor"></span> 3300039 <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>; 3500041 3600042 <span class="preprocessor">#endif //OSCL_TLS_IS_KEYED</span> 3700043 <span class="preprocessor"></span> 3800044 3900045 <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> 5300059 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> 5500061 <span class="preprocessor"></span> 5600062 <span class="comment">//There may be additional slots defined in the osclconfig.h for the build.</span> 5700063 <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> 5900065 <span class="preprocessor"></span><span class="preprocessor">#endif</span> 6000066 <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> 6200068 <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> 6400070 { 6500071 <span class="keyword">public</span>: 6600072 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&); 6700073 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); 6800074 }; 6900075 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> 7100077 { 7200078 <span class="keyword">public</span>: 7300079 <span class="comment">/*</span> 7400080 <span class="comment"> ** Get an entry</span> 7500081 <span class="comment"> ** @param ID: identifier</span> 7600082 <span class="comment"> ** @param error (output) 0 for success or an error from TPVBaseErrorEnum</span> 7700083 <span class="comment"> ** @returns: the entry value</span> 7800084 <span class="comment"> */</span> 7900085 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 &error); 8000086 <span class="comment">/*</span> 8100087 <span class="comment"> ** Set an entry</span> 8200088 <span class="comment"> ** @param ID: identifier</span> 8300089 <span class="comment"> ** @param error (output) 0 for success or an error from TPVBaseErrorEnum</span> 8400090 <span class="comment"> ** @returns: the entry value</span> 8500091 <span class="comment"> */</span> 8600092 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 &error); 8700093 8800094 <span class="keyword">private</span>: 8900095 <a class="code" href="classOsclTLSRegistry.html">OsclTLSRegistry</a>() 9000096 {} 9100097 <span class="keyword">typedef</span> <a class="code" href="group__osclbase.html#a25">OsclAny</a>* registry_type; 9200098 <span class="keyword">typedef</span> registry_type* registry_pointer_type; 9300099 9400100 <span class="preprocessor">#if ( OSCL_TLS_IS_KEYED)</span> 9500101 <span class="preprocessor"></span> <span class="keyword">class </span>TlsKey 9600102 { 9700103 <span class="keyword">public</span>: 9800104 TlsKey(): iRefCnt(0), iOsclTlsKey(<a class="code" href="group__osclbase.html#a81">NULL</a>) 9900105 {} 10000106 _OsclBasicLock iLock; 10100107 uint32 iRefCnt; 10200108 <a class="code" href="group__osclbase.html#a10">TOsclTlsKey</a> *iOsclTlsKey; 10300109 }; 10400110 10500111 <span class="comment">//The key is a global variable.</span> 10600112 <span class="keyword">static</span> TlsKey* iTlsKey; 10700113 <span class="preprocessor">#endif</span> 10800114 <span class="preprocessor"></span> 10900115 <span class="keyword">private</span>: 11000116 OSCL_IMPORT_REF <span class="keyword">static</span> <span class="keywordtype">void</span> initialize(<a class="code" href="classOscl__DefAlloc.html">Oscl_DefAlloc</a> &alloc, int32 &error); 11100117 OSCL_IMPORT_REF <span class="keyword">static</span> <span class="keywordtype">void</span> cleanup(<a class="code" href="classOscl__DefAlloc.html">Oscl_DefAlloc</a> &alloc, int32 &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>; 11300119 11400120 }; 115<a name="l00121"></a><a class="code" href="classOsclTLS.html">00121</a> 11600122 <span class="keyword">template</span> < <span class="keyword">class</span> T, u<span class="keywordtype">int</span>32 ID, <span class="keyword">class</span> Registry = OsclTLSRegistry > <span class="keyword">class </span><a class="code" href="classOsclTLS.html">OsclTLS</a> 11700123 { 11800124 <span class="keyword">private</span>: 11900125 <span class="comment">// make the copy constructor and assignment operator private</span> 12000126 <a class="code" href="classOsclTLS.html">OsclTLS</a>& operator=(<a class="code" href="classOsclTLS.html">OsclTLS</a>& _Y) 12100127 { 12200128 <span class="keywordflow">return</span>(*this); 12300129 } 12400130 125<a name="l00131"></a><a class="code" href="classOsclTLS.html#n0">00131</a> <span class="keyword">protected</span>: 12600132 T* <a class="code" href="classOsclTLS.html#n0">_Ptr</a>; 12700133 128<a name="l00134"></a><a class="code" href="classOsclTLS.html#a0">00134</a> <span class="keyword">public</span>: 12900135 <a class="code" href="classOsclTLS.html#a0">OsclTLS</a>() 13000136 { 13100137 int32 err; 13200138 <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)); 13300139 } 134<a name="l00140"></a><a class="code" href="classOsclTLS.html#a1">00140</a> 13500141 <a class="code" href="classOsclTLS.html#a1">~OsclTLS</a>() {}; 13600142 13700150 T& <a class="code" href="classOsclTLS.html#a2">operator*</a>()<span class="keyword"> const</span> 13800151 <span class="keyword"> </span>{ 13900152 <span class="keywordflow">return</span>(*_Ptr); 14000153 } 14100154 14200162 T *<a class="code" href="classOsclTLS.html#a3">operator-></a>()<span class="keyword"> const</span> 14300163 <span class="keyword"> </span>{ 14400164 <span class="keywordflow">return</span>(_Ptr); 14500165 } 14600166 14700167 14800174 <span class="keywordtype">bool</span> <a class="code" href="classOsclTLS.html#a4">set</a>() 14900175 { 15000176 int32 err; 15100177 <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)); 15200178 <span class="keywordflow">return</span> (<a class="code" href="classOsclTLS.html#n0">_Ptr</a> ? <span class="keyword">true</span> : <span class="keyword">false</span>); 15300179 } 15400180 15500181 }; 15600182 15700187 <span class="preprocessor">#endif</span> 15800188 <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