00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _SB_THREAD_LOCAL_STORAGE_H_
00026 #define _SB_THREAD_LOCAL_STORAGE_H_
00027
00028 #include <Inventor/SbBase.h>
00029
00030 typedef void SoInitTLSClassCB();
00031 typedef void SoExitTLSClassCB();
00032
00039 #define SB_THREAD_INIT_CLASS(_className_,_structName_) \
00040 SbThreadLocalStorage::createStorage(_className_::MT_Id, sizeof(struct _className_::_structName_), _className_::initTLSClass, _className_::exitTLSClass, OIV_FUNCTION );
00041
00048 #define SB_THREAD_IS_INITIALIZED(_className_) \
00049 SbThreadLocalStorage::isInitialized(_className_::MT_Id)
00050
00057 #define SB_THREAD_EXIT_CLASS(_className_) \
00058 SbThreadLocalStorage::deleteStorage( _className_::MT_Id, OIV_FUNCTION );
00059
00063 #define GET_THREAD_LOCAL_VAR(_className_, _structName_, _varName_) \
00064 ((static_cast<struct _className_::_structName_ *> (SbThreadLocalStorage::getStorage(_className_::MT_Id)))->_varName_)
00065
00069 #define GET_THREAD_LOCAL_STORAGE(_className_) \
00070 (static_cast<void *> (SbThreadLocalStorage::getStorage(_className_::MT_Id)))
00071
00075 #define SB_THREAD_TLS_HEADER() \
00076 private: \
00077 \
00078 static size_t MT_Id; \
00079 \
00080 static void initTLSClass(); \
00081 \
00082 static void exitTLSClass()
00083
00084
00088 #define SB_THREAD_TLS_SOURCE( _className_ ) \
00089 \
00090 size_t _className_::MT_Id = -1
00091
00093 #ifndef SoNodeTLS
00094 #define SoNodeTLS SbThreadLocalStorage
00095 #endif
00096
00211 class SbThreadLocalStorage
00212 {
00213 public:
00222 static void createStorage(size_t& classThreadId, const size_t byteSize, SoInitTLSClassCB* initFunc=NULL, SoExitTLSClassCB* exitFunc=NULL, const char* funcName=NULL);
00223
00228 static void deleteStorage( size_t& classThreadId, const char* funcName=NULL );
00229
00237 static bool isInitialized(const size_t classThreadId);
00238
00247 static void *getStorage(const size_t classThreadId);
00248
00249 private:
00266 static void initThreadLocalStorage();
00267
00276 static void closeThreadLocalStorage();
00277
00278 private:
00284 static void initClass();
00285
00290 static void exitClass();
00291
00296 template<typename StructName, typename ClassName>
00297 static StructName*
00298 getStruct()
00299 {
00300 return static_cast<StructName*>(SbThreadLocalStorage::getStorage(ClassName::MT_Id));
00301 }
00302
00307 template<typename StructName, typename ClassName>
00308 static StructName*
00309 getStruct(const ClassName*)
00310 {
00311 return getStruct<StructName, ClassName>();
00312 }
00313
00317 static bool isInitialized();
00318
00319 };
00320
00321 #endif //_SB_THREAD_LOCAL_STORAGE_H_
00322
00323
00324
00325
00326