Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SbThreadStorageBase.h
Go to the documentation of this file.
1#ifndef HIDDEN_FROM_DOC
2
3/*=======================================================================
4 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
5 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
6 *** ***
7 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
8 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
9 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
10 *** ***
11 *** RESTRICTED RIGHTS LEGEND ***
12 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
13 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
14 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
15 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
16 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
17 *** ***
18 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
19 *** BORDEAUX, FRANCE ***
20 *** ALL RIGHTS RESERVED ***
21**=======================================================================*/
22/*=======================================================================
23** Author : Nicolas DAGUISE (Oct 2008)
24**=======================================================================*/
25
26
27#ifndef _SB_THREAD_STORAGE_BASE_H_
28#define _SB_THREAD_STORAGE_BASE_H_
29
33#include <Inventor/STL/list>
34#include <deque>
35
36#if defined(_WIN32)
37#pragma warning( push )
38#pragma warning(disable:4251)
39#endif //_WIN32
40
41// Opaque storage structure to handle the list of SbThreadStorageBase
42class SbThreadStorageMapStruct;
43
51class SbThreadStorageBase
52{
54
55public:
56
58 void cleanStorage();
59
60private:
62 SbThreadStorageBase();
63private:
65 SbThreadStorageBase(const SbThreadStorageBase& tocopy);
66private:
68 virtual ~SbThreadStorageBase();
69
71 virtual void deleteStorage(void* p) = 0;
72
73private:
75 static void initClass();
77 static void exitClass();
78
79 void* getValue() const;
80 void Register( void* );
81
82 typedef std::list< SbThreadStorageMapStruct* > SbThreadStorageGlobalList;
83
84 struct MTstruct
85 {
86 SbThreadStorageMapStruct* threadStorageMapStruct;
87 };
88
89private:
90 // helper to erase all values of a storage
91 void erase();
92 // helper to set the value for the current thread
93 void setAll(void* p);
94 // helper to get the value for the current thread
95 void* get (const SbThreadStorageGlobalList::const_iterator& it_i);
96
97 // global list to keep track of all storage
98 static SbThreadStorageGlobalList s_threadStorageGlobalList;
99 // mutex for s_threadStorageGlobalList access
100 static SbThreadSpinlock s_threadStorageGlobalMutex;
101
102private:
103 // ID in the storage (same in all thread)
104 size_t m_storageID;
105
106 // get an available storage ID
107 static size_t getID();
108
109 // last ID available.
110 // Must access with lock for thread-safety.
111 static size_t s_storageID;
112
113 // list of ID previously used and available for reuse.
114 // if none are available then s_storageID is used and incremented for next round.
115 // Must access with lock for thread-safety.
116 typedef std::deque<size_t> SbThreadStorageFreeIDList;
117 static SbThreadStorageFreeIDList s_freeStorageIDList;
118};
119
120#if defined(_WIN32)
121#pragma warning(pop)
122#endif //_WIN32
123
124
125#endif //_SB_THREAD_STORAGE_BASE_H_
126
127
128#endif // HIDDEN_FROM_DOC
129
130
#define SB_THREAD_TLS_HEADER()
Defines headers for required member variables in thread storage management.
const SbVec3f & get(int index) const
valueRef getValue() const
Definition SoSubField.h:234
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable spinloc...