Main Page   Modules   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

oscl_tls.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
00003 
00004 //                     O S C L _ T L S
00005 
00006 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
00007 
00022 #ifndef OSCL_TLS_H_INCLUDED
00023 #define OSCL_TLS_H_INCLUDED
00024 
00025 #ifndef OSCL_BASE_H_INCLUDED
00026 #include "oscl_base.h"
00027 #endif
00028 
00029 #ifndef OSCL_DEFALLOC_H_INCLUDED
00030 #include "oscl_defalloc.h"
00031 #endif
00032 
00033 
00034 #if (OSCL_TLS_IS_KEYED)
00035 
00036 //Keyed TLS requires global variable support
00037 #else
00038 
00039 //unused value.
00040 typedef OsclAny TOsclTlsKey;
00041 
00042 #endif //OSCL_TLS_IS_KEYED
00043 
00044 
00045 // list of TLS objects
00046 const uint32 OSCL_TLS_ID_MAGICNUM       = 0;
00047 const uint32 OSCL_TLS_ID_ERRORHOOK      = 1;
00048 const uint32 OSCL_TLS_ID_PVLOGGER       = 2;
00049 const uint32 OSCL_TLS_ID_TEST           = 3;
00050 const uint32 OSCL_TLS_ID_PVSCHEDULER    = 4;
00051 const uint32 OSCL_TLS_ID_PVERRORTRAP    = 5;
00052 const uint32 OSCL_TLS_ID_SDPMEDIAPARSER = 6;
00053 const uint32 OSCL_TLS_ID_PAYLOADPARSER  = 7;
00054 const uint32 OSCL_TLS_ID_PVMFRECOGNIZER = 8;
00055 const uint32 OSCL_TLS_ID_WMDRM          = 9;
00056 const uint32 OSCL_TLS_ID_OSCLREGISTRY   = 10;
00057 const uint32 OSCL_TLS_ID_SQLITE3        = 11;
00058 const uint32 OSCL_TLS_ID_BASE_LAST      = 11; // should always equal the largest ID defined here
00059 
00060 #define OSCL_TLS_BASE_SLOTS OSCL_TLS_ID_BASE_LAST +1
00061 
00062 //There may be additional slots defined in the osclconfig.h for the build.
00063 #ifndef OSCL_TLS_EXTERNAL_SLOTS
00064 #define OSCL_TLS_EXTERNAL_SLOTS 0
00065 #endif
00066 
00067 #define OSCL_TLS_MAX_SLOTS ( OSCL_TLS_BASE_SLOTS + OSCL_TLS_EXTERNAL_SLOTS)
00068 
00069 class TLSStorageOps
00070 {
00071     public:
00072         OSCL_IMPORT_REF static void save_registry(TOsclTlsKey* key, OsclAny* ptr, int32&);
00073         OSCL_IMPORT_REF static OsclAny* get_registry(TOsclTlsKey* key);
00074 };
00075 
00076 class OsclTLSRegistry
00077 {
00078     public:
00079         /*
00080         ** Get an entry
00081         ** @param ID: identifier
00082         ** @param error (output) 0 for success or an error from TPVBaseErrorEnum
00083         ** @returns: the entry value
00084         */
00085         OSCL_IMPORT_REF static OsclAny* getInstance(uint32 ID, int32 &error);
00086         /*
00087         ** Set an entry
00088         ** @param ID: identifier
00089         ** @param error (output) 0 for success or an error from TPVBaseErrorEnum
00090         ** @returns: the entry value
00091         */
00092         OSCL_IMPORT_REF static void registerInstance(OsclAny* ptr, uint32 ID, int32 &error);
00093 
00094     private:
00095         OsclTLSRegistry()
00096         {}
00097         typedef OsclAny* registry_type;
00098         typedef registry_type* registry_pointer_type;
00099 
00100 #if ( OSCL_TLS_IS_KEYED)
00101         class TlsKey
00102         {
00103             public:
00104                 TlsKey(): iRefCnt(0), iOsclTlsKey(NULL)
00105                 {}
00106                 _OsclBasicLock iLock;
00107                 uint32 iRefCnt;
00108                 TOsclTlsKey *iOsclTlsKey;
00109         };
00110 
00111         //The key is a global variable.
00112         static TlsKey* iTlsKey;
00113 #endif
00114 
00115     private:
00116         OSCL_IMPORT_REF static void initialize(Oscl_DefAlloc &alloc, int32 &error);
00117         OSCL_IMPORT_REF static void cleanup(Oscl_DefAlloc &alloc, int32 &error);
00118         friend class OsclBase;
00119 
00120 };
00121 
00122 template < class T, uint32 ID, class Registry = OsclTLSRegistry > class OsclTLS
00123 {
00124     private:
00125         // make the copy constructor and assignment operator private
00126         OsclTLS& operator=(OsclTLS& _Y)
00127         {
00128             return(*this);
00129         }
00130 
00131     protected:
00132         T* _Ptr;
00133 
00134     public:
00135         OsclTLS()
00136         {
00137             int32 err;
00138             _Ptr = OSCL_STATIC_CAST(T*, Registry::getInstance(ID, err));
00139         }
00140 
00141         ~OsclTLS() {};
00142 
00150         T& operator*() const
00151         {
00152             return(*_Ptr);
00153         }
00154 
00162         T *operator->() const
00163         {
00164             return(_Ptr);
00165         }
00166 
00167 
00174         bool set()
00175         {
00176             int32 err;
00177             _Ptr = OSCL_STATIC_CAST(T*, Registry::getInstance(ID, err));
00178             return (_Ptr ? true : false);
00179         }
00180 
00181 };
00182 
00187 #endif
00188 

OSCL API
Posting Version: OPENCORE_20090310