Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoCpuBufferObjectCache.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-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
140private:
141
142 // internal perf counters access
143 void getInternalCounter( uint64_t &nbCacheAccess, uint64_t& nbCacheDefault);
144 void resetInternalCounter( );
145
146 // Force a delete from cache (mainly used as a double checked in SoCpuBufferCache destructor
147 // costly because we have to search for the bufferId first.
148 virtual bool deleteFromCache( const uint64_t bufferId );
149
150 // Retrieve bufferId from its signature.
151 uint64_t getMappingIdfromSig(const uint64_t& cacheSig);
152
153private:
154
155 // implementation of getBuffer for getBuffer and getBufferRef
156 // notes it is upd to the caller to lock the cacheList mutex
157 SoCpuBufferObject* getBufferInternal(const uint64_t bufferId);
158
159 // internal cache management
160 typedef std::map<uint64_t, SoCpuBufferObject*> cacheListType;
161 typedef std::map<uint64_t, uint64_t> bufferSignatureMap;
162 typedef std::list<uint64_t> lruBufferIdsType;
163
164 cacheListType m_cacheList;
165 bufferSignatureMap m_bufferIdToSigMap;
166 bufferSignatureMap m_bufferSigToIdMap;
167 // List of sorted ids. The last one is the last used one.
168 lruBufferIdsType lruBufferIds;
169
170 // Max size of the cache
171 size_t m_maxCacheSize;
172
173 // Uniq Id management
174 uint64_t getUniqueId();
175 uint64_t m_lasUniqId;
176
177 // Remove the least recently used buffer.
178 void makeRoomInCache();
179
180 // Spinlock used to protect cache access
181 SbThreadSpinlock *m_cacheListLock;
182
183 // perf counter manager
184 uint64_t m_perfNbCacheAccess ;
185 uint64_t m_perfNbCacheDefault;
186};
187
188#ifdef WIN32
189#pragma warning( pop )
190#endif
191
192#endif //_SO_BUFFER_OBJECT_CACHE_H_
193
194
virtual size_t getSize()
Return the max size of the cache (number of buffers).
virtual void resize(const size_t newSize)
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> CPUBufferObject ...
<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...