Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoCpuBufferObjectCache.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 : VSG (MMM YYYY)
22**=======================================================================*/
23
24#ifndef _SO_BUFFER_OBJECT_CACHE_H_
25#define _SO_BUFFER_OBJECT_CACHE_H_
26
27#include <Inventor/SbBase.h>
28#include <Inventor/STL/map>
29#include <Inventor/STL/list>
30
31class SoBufferObject;
34
35#ifdef _WIN32
36#pragma warning( push )
37#pragma warning(disable:4251)
38#endif
39
58{
59 public:
60
64 virtual void flush();
65
71 virtual void resize( const size_t newSize );
72
76 virtual size_t getSize( );
77
78 private:
82 SoCpuBufferObjectCache();
83
85 virtual ~SoCpuBufferObjectCache();
86
99 virtual SoCpuBufferObject* getBufferRef( const uint64_t bufferId );
100
113 virtual uint64_t addInCache( SoCpuBufferObject* bufferObject );
114
128 virtual bool releaseBufferRef ( const uint64_t bufferId );
129
138 SoCpuBufferObject* getBuffer(const uint64_t bufferId);
139
140 // internal perf counters access
141 void getInternalCounter( uint64_t &nbCacheAccess, uint64_t& nbCacheDefault);
142 void resetInternalCounter( );
143
144 // Force a delete from cache (mainly used as a double checked in SoCpuBufferCache destructor
145 // costly because we have to search for the bufferId first.
146 virtual bool deleteFromCache( const uint64_t bufferId );
147
148 // Retrieve bufferId from its signature.
149 uint64_t getMappingIdfromSig(const uint64_t& cacheSig);
150
151private:
152
153 // implementation of getBuffer for getBuffer and getBufferRef
154 // notes it is upd to the caller to lock the cacheList mutex
155 SoCpuBufferObject* getBufferInternal(const uint64_t bufferId);
156
157 // internal cache management
158 typedef std::map<uint64_t, SoCpuBufferObject*> cacheListType;
159 typedef std::map<uint64_t, uint64_t> bufferSignatureMap;
160 typedef std::list<uint64_t> lruBufferIdsType;
161
162 cacheListType m_cacheList;
163 bufferSignatureMap m_bufferIdToSigMap;
164 bufferSignatureMap m_bufferSigToIdMap;
165 // List of sorted ids. The last one is the last used one.
166 lruBufferIdsType lruBufferIds;
167
168 // Max size of the cache
169 size_t m_maxCacheSize;
170
171 // Uniq Id management
172 uint64_t getUniqueId();
173 uint64_t m_lasUniqId;
174
175 // Remove the least recently used buffer.
176 void makeRoomInCache();
177
178 // Spinlock used to protect cache access
179 SbThreadSpinlock *m_cacheListLock;
180
181 // perf counter manager
182 uint64_t m_perfNbCacheAccess ;
183 uint64_t m_perfNbCacheDefault;
184};
185
186#ifdef WIN32
187#pragma warning( pop )
188#endif
189
190#endif //_SO_BUFFER_OBJECT_CACHE_H_
191
192
<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> Abstract base cl...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> CPU buffer objec...