Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoDeviceContextSharedGroup.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-2019 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : Nicolas DAGUISE (Oct 2010)
22**=======================================================================*/
23
24#if !defined SO_DEVICE_CONTEXT_SHARE_GROUP_H
25#define SO_DEVICE_CONTEXT_SHARE_GROUP_H
26
27#include <Inventor/misc/SoRefCounter.h>
28#include <Inventor/STL/set>
29#include <Inventor/threads/SbThreadMutex.h>
30#include <Inventor/devices/SoSharedGroupReferenceList.h>
31#include <Inventor/SbEventHandler.h>
32
33class SoDeviceContext;
34class SoBaseContextCache;
36
37#ifdef _MSC_VER
38#pragma warning( push )
39#pragma warning(disable:4251)
40#endif
41
53{
54public:
56 typedef std::set<SoDeviceContext*> SoDeviceContextSet;
57
60
63
65 void add(SoDeviceContext* ctx);
66
69
71 void setId( int id );
72
74 int getId() const;
75
78
81
83 bool contains(const SoDeviceContext* ctx) const;
84
90 void ref(SoBaseContextCache* object = NULL);
91
102 void unref(SoBaseContextCache* object = NULL);
103
104
108 bool contains(SoBaseContextCache* object) const;
109
114 virtual void dispose();
115
116private:
117 typedef int SharedGroupId;
118
120 void setDisposeCallback(void (*f)(SoDeviceContextSharedGroup*));
121
123 void setDestroyNotificationCallback(void (*f)(SoDeviceContextSharedGroup*));
124
125 void setTargetMergedGroup(SoDeviceContextSharedGroup* sharedGroup);
126
130 void addToPendingDeleteList(SoBaseContextObject *obj);
131
135 static void checkRefIssues(SoBaseContextObject* object);
136 static void checkRefIssues(SoBaseContextCache* cache);
137
139 void clearPendingDeleteList();
140
141 void setDisposing( bool b );
142
144 SbThreadId_t getThreadId() const;
145
147 static int getNewSharedIdGroup();
148
150 static void printSharedGroups();
151
155 bool hasValidContext() const;
156
158 SoDeviceContext* getPrimaryValidContext() const;
159
160 // return debugging trace level requested
161 static int getDebuggingLevel()
162 { return s_debuggingLevel; }
163
165 inline static int getFallbackContextGlobalSharedId()
166 {
167 return -2;
168 }
169
175 static SoDeviceContextSharedGroup* getSharedGroupFromId( SharedGroupId id );
176
177private:
178
181
186 void forceReleaseAttachedObject();
187
188 bool m_isDisposing;
189
190private:
191
192 void commonConstructor();
193
194 // Returns the context to use for delete operation
195 // - if currently binded context is in the shared group then use it
196 // - else use the first available context in the group (getPrimaryValidContext())
197 SoDeviceContext* getDeviceContextToBindForDelete() const;
198
199 SoDeviceContextSet m_ctxSet;
200 int m_id;
201 SoDeviceContextSharedGroup* m_mergedGroup;
202
204 typedef std::list<SoDeviceContextSharedGroup*> SoDeviceContexSharedGroupList;
205 static SbThreadSpinlock s_sharedGroupListLock;
206 static SoDeviceContexSharedGroupList s_sharedGroupList;
207 static int s_sharedGroupId;
208
210 typedef std::list<SoBaseContextCache*> SoBaseContextCacheList;
211 SoBaseContextCacheList m_listContextedObject;
212 bool m_isClearingPendingList;
213
215 SoSharedGroupReferenceList m_intrusivelistContextedObject;
216
218 typedef std::set<SoBaseContextObject*> SoBaseContextObjectList;
219 SoBaseContextObjectList m_waitingToBeFreed;
220
222 SbThreadId_t m_threadId;
223
230 mutable SbThreadMutex m_sharedGroupMembersMutex;
231
232 // Controlled by environment variable IV_DEBUG_SHARED_GROUP
233 // 0 means disabled
234 // 1 means show weird situation
235 // 2 means show more trace
236 static int s_debuggingLevel;
237
239 SbEventHandler<SoDeviceContextSharedGroup*> m_destroyNotificationCallback;
240 SbEventHandler<SoDeviceContextSharedGroup*> m_disposeNotificationCallback;
241};
242
243// INLINE METHODS
244inline void SoDeviceContextSharedGroup::setDisposing( bool b )
245{
246 m_isDisposing = b;
247}
248
249inline SbThreadId_t SoDeviceContextSharedGroup::getThreadId() const
250{
251 return m_threadId;
252}
253
254#ifdef _MSC_VER
255#pragma warning( pop )
256#endif
257
258#endif // SO_DEVICE_CONTEXT_SHARE_GROUP_H
259
260
Class representing an event.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable spinloc...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Context dependen...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Shared context m...
SoDeviceContextSharedGroup()
Creates a new SharedGroup.
std::set< SoDeviceContext * > SoDeviceContextSet
Type definition for SoDeviceContext set management.
const SoDeviceContextSet & getContexts() const
Gets the list of contexts managed by this shared group.
void ref(SoBaseContextCache *object=NULL)
Increment reference count.
bool contains(SoBaseContextCache *object) const
Returns TRUE if the specified object is already in the list of notified objects.
bool contains(const SoDeviceContext *ctx) const
Returns TRUE if the passed context is part of the shared group.
SoDeviceContext * getPrimaryContext() const
Returns the first context found in the shared group.
virtual void dispose()
Force all attached objects to release the context, by calling their respective release function,...
SoDeviceContextSharedGroup(int id)
Creates a new SharedGroup with specific id.
void unref(SoBaseContextCache *object=NULL)
Decrement reference count.
void add(SoDeviceContext *ctx)
Adds a device context to the group.
void remove(SoDeviceContext *ctx)
Removes a device context from the group.
void setId(int id)
Sets a specific id for this shared group.
int getId() const
Gets the id of this shared group.
Base class for ref-counted objects.