Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SbThreadLocalStorage.h
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-2024 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
31typedef void SoInitTLSClassCB();
33typedef void SoExitTLSClassCB();
34
44#define SB_THREAD_INIT_CLASS(_className_,_structName_) \
45 SbThreadLocalStorage::createStorage(_className_::MT_Id, sizeof(struct _className_::_structName_), _className_::initTLSClass, _className_::exitTLSClass, OIV_FUNCTION );
46
56#define SB_THREAD_IS_INITIALIZED(_className_) \
57 SbThreadLocalStorage::isInitialized(_className_::MT_Id)
58
68#define SB_THREAD_EXIT_CLASS(_className_) \
69 SbThreadLocalStorage::deleteStorage( _className_::MT_Id, OIV_FUNCTION );
70
76#define GET_THREAD_LOCAL_VAR(_className_, _structName_, _varName_) \
77 ((static_cast<struct _className_::_structName_ *> (SbThreadLocalStorage::getStorage(_className_::MT_Id)))->_varName_)
78
84#define GET_THREAD_LOCAL_STORAGE(_className_) \
85 (static_cast<void *> (SbThreadLocalStorage::getStorage(_className_::MT_Id)))
86
92#define SB_THREAD_TLS_HEADER() \
93private: \
94 \
95 static size_t MT_Id; \
96 \
97 static void initTLSClass(); \
98 \
99 static void exitTLSClass()
100
101
107#define SB_THREAD_TLS_SOURCE( _className_ ) \
108 \
109 size_t _className_::MT_Id = -1
110
116#ifndef SoNodeTLS
117#define SoNodeTLS SbThreadLocalStorage
118#endif
119
235{
236 public:
245 static void createStorage(size_t& classThreadId, const size_t byteSize, SoInitTLSClassCB* initFunc=NULL, SoExitTLSClassCB* exitFunc=NULL, const char* funcName=NULL);
246
251 static void deleteStorage( size_t& classThreadId, const char* funcName=NULL );
252
260 static bool isInitialized(const size_t classThreadId);
261
270 static void *getStorage(const size_t classThreadId);
271
272private:
289 static void initThreadLocalStorage();
290
299 static void closeThreadLocalStorage();
300
301private:
307 static void initClass();
308
313 static void exitClass();
314
319 template<typename StructName, typename ClassName>
320 static StructName*
321 getStruct()
322 {
323 return static_cast<StructName*>(SbThreadLocalStorage::getStorage(ClassName::MT_Id));
324 }
325
330 template<typename StructName, typename ClassName>
331 static StructName*
332 getStruct(const ClassName*)
333 {
334 return getStruct<StructName, ClassName>();
335 }
336
340 static bool isInitialized();
341
342};
343
344#endif //_SB_THREAD_LOCAL_STORAGE_H_
345
346
347
348
<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.