Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SbThreadLocalStorage.h
Go to the documentation of this file.
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2018 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : Nicolas DAGUISE (Oct 2008)
22**=======================================================================*/
23
24
25#ifndef _SB_THREAD_LOCAL_STORAGE_H_
26#define _SB_THREAD_LOCAL_STORAGE_H_
27
28#include <Inventor/SbBase.h>
29
30typedef void SoInitTLSClassCB();
31typedef void SoExitTLSClassCB();
32
39#define SB_THREAD_INIT_CLASS(_className_,_structName_) \
40 SbThreadLocalStorage::createStorage(_className_::MT_Id, sizeof(struct _className_::_structName_), _className_::initTLSClass, _className_::exitTLSClass, OIV_FUNCTION );
41
48#define SB_THREAD_IS_INITIALIZED(_className_) \
49 SbThreadLocalStorage::isInitialized(_className_::MT_Id)
50
57#define SB_THREAD_EXIT_CLASS(_className_) \
58 SbThreadLocalStorage::deleteStorage( _className_::MT_Id, OIV_FUNCTION );
59
63#define GET_THREAD_LOCAL_VAR(_className_, _structName_, _varName_) \
64 ((static_cast<struct _className_::_structName_ *> (SbThreadLocalStorage::getStorage(_className_::MT_Id)))->_varName_)
65
69#define GET_THREAD_LOCAL_STORAGE(_className_) \
70 (static_cast<void *> (SbThreadLocalStorage::getStorage(_className_::MT_Id)))
71
75#define SB_THREAD_TLS_HEADER() \
76private: \
77 \
78 static size_t MT_Id; \
79 \
80 static void initTLSClass(); \
81 \
82 static void exitTLSClass()
83
84
88#define SB_THREAD_TLS_SOURCE( _className_ ) \
89 \
90 size_t _className_::MT_Id = -1
91
93#ifndef SoNodeTLS
94#define SoNodeTLS SbThreadLocalStorage
95#endif
96
212{
213 public:
222 static void createStorage(size_t& classThreadId, const size_t byteSize, SoInitTLSClassCB* initFunc=NULL, SoExitTLSClassCB* exitFunc=NULL, const char* funcName=NULL);
223
228 static void deleteStorage( size_t& classThreadId, const char* funcName=NULL );
229
237 static bool isInitialized(const size_t classThreadId);
238
247 static void *getStorage(const size_t classThreadId);
248
249private:
266 static void initThreadLocalStorage();
267
276 static void closeThreadLocalStorage();
277
278private:
284 static void initClass();
285
290 static void exitClass();
291
296 template<typename StructName, typename ClassName>
297 static StructName*
298 getStruct()
299 {
300 return static_cast<StructName*>(SbThreadLocalStorage::getStorage(ClassName::MT_Id));
301 }
302
307 template<typename StructName, typename ClassName>
308 static StructName*
309 getStruct(const ClassName*)
310 {
311 return getStruct<StructName, ClassName>();
312 }
313
317 static bool isInitialized();
318
319};
320
321#endif //_SB_THREAD_LOCAL_STORAGE_H_
322
323
324
325
void SoExitTLSClassCB()
void SoInitTLSClassCB()
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Thread Local Sto...
static void * getStorage(const size_t classThreadId)
Returns a pointer on the storage for the given classThreadId.
static bool isInitialized(const size_t classThreadId)
Returns true if a TLS storage has already been allocated for the given classThreadId.
static void deleteStorage(size_t &classThreadId, const char *funcName=NULL)
Deletes the local storage for all threads.
static void createStorage(size_t &classThreadId, const size_t byteSize, SoInitTLSClassCB *initFunc=NULL, SoExitTLSClassCB *exitFunc=NULL, const char *funcName=NULL)
Creates or updates the local storage for the current thread.