VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
unusedFeatureTileTracker.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
9 
10 #pragma once
11 
13 
14 #include <tbb/tbb_thread.h>
15 #include <tbb/spin_rw_mutex.h>
16 #include <tbb/atomic.h>
17 
18 #include <boost/optional.hpp>
19 #include <boost/shared_ptr.hpp>
20 #include <boost/weak_ptr.hpp>
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/noncopyable.hpp>
23 
24 #include <list>
25 
26 #include <vrfutil/objectCounter.h>
27 
30 
31 namespace MAKVRinTerra
32 {
44 #ifdef DtObjectDebugger_Enable
45  : public DtObjectDebugger<DtUnusedFeatureTileTracker>
46 #endif
47  {
48  public:
51 
52  typedef boost::shared_ptr<DtUnusedFeatureTileTracker> Ptr;
53  typedef boost::weak_ptr<DtUnusedFeatureTileTracker> WeakPtr;
54  typedef boost::shared_ptr<Trackable> TrackablePtr;
55  typedef std::list<TrackablePtr> TrackableList;
56  typedef std::list<Trackable*> TrackableRawPtrList;
57 
62  const std::string& name = "tracker");
63 
67 
69  void start();
70 
72  unsigned length() const;
73 
75  unsigned size() const;
76 
78  unsigned totalLength() const;
79 
81  void setMaxSize(unsigned max);
82 
84  unsigned maxSize() const;
85 
87  void setMinUnusedTime(double);
88 
90  double minUnusedTime() const;
91 
93  unsigned long unloadUntilSize(unsigned maxSize, double minTime);
94  unsigned long unloadUntilSize(unsigned maxSize);
95 
97  void addSubtracker(const Ptr& subtracker);
98 
100  void info(std::ostream&) const;
101 
103  void print(std::ostream&) const;
104 
105  private:
106  friend class Trackable;
107 
108  typedef tbb::spin_rw_mutex Mutex;
109 
111  bool add(Trackable&);
112 
113  bool add(const boost::shared_ptr<Trackable>&);
114 
116  bool remove(Trackable&);
117 
119  bool removeAndUnload(Trackable&);
120 
122  void run();
123 
124  mutable Mutex myMutex;
126 
128  boost::scoped_ptr<tbb::tbb_thread> myPageOutThread;
129 
130  tbb::atomic<unsigned> myMaxSize;
131  tbb::atomic<double> myMinUnusedTime;
132 
134  typedef std::vector<Ptr> SubTrackerList;
136 
139 
140  boost::scoped_ptr<DtConsoleCommandManager> myCommandManager;
141  boost::scoped_ptr<DtConsoleCommandOwner> myCommandOwner;
142  };
143 
146  : private boost::noncopyable
147 #ifdef DtObjectDebugger_Enable
148  , public DtObjectDebugger<DtUnusedFeatureTileTracker::Trackable>
149 #endif
150  {
151  public:
153  static bool UnloadTryCatch(Trackable&);
154 
156  virtual ~Trackable();
157 
159  virtual std::string label() const = 0;
160 
162  virtual void load() = 0;
163 
165  virtual bool unload() = 0;
166 
168  virtual bool loading() const = 0;
169 
171  virtual bool loaded() const = 0;
172 
176  virtual unsigned size() const = 0;
177 
183  virtual boost::shared_ptr<Trackable> getPtr() const = 0;
184 
187  boost::shared_ptr<Sentinel> getSentinel(bool loadIfNotPresent=true) const;
188 
191  void addToUnusedList();
192 
194  unsigned useCount() const;
195 
197  tbb::tick_count unusedTime() const;
198 
199  protected:
201 
202  private:
204  friend class Sentinel;
205 
206  typedef tbb::spin_rw_mutex Mutex;
207 
209  void sentinelDestroyed();
210 
212  bool notInList() const { return !myIterator; }
213  TrackableList::iterator iterator() const { return *myIterator; }
214 
215  mutable Mutex myMutex;
216 
218 
220  boost::weak_ptr<Sentinel> mySentinel;
221  boost::optional<TrackableList::iterator> myIterator;
222  boost::optional<TrackableRawPtrList::iterator> myTrackableListIterator;
223 
225  tbb::tick_count myUnusedTime;
226  };
227 
229  : private boost::noncopyable
230 #ifdef DtObjectDebugger_Enable
231  , public DtObjectDebugger<DtUnusedFeatureTileTracker::Sentinel>
232 #endif
233  {
234  public:
235  typedef boost::shared_ptr<Sentinel> Ptr;
236 
237  ~Sentinel();
238 
239  private:
240  friend class Trackable;
241 
242  explicit Sentinel(const boost::shared_ptr<Trackable>&);
243 
244  const boost::shared_ptr<Trackable> myTrackable;
245  };
246 }
247 
virtual bool loaded() const =0
Has this object completed loading.
#define DT_DLL_features
stop complaining about multiple independent base classes for boost::noncopyable this should probably ...
Definition: featuresDefines.h:41
std::list< TrackablePtr > TrackableList
Definition: unusedFeatureTileTracker.h:55
boost::weak_ptr< Sentinel > mySentinel
weak ptr to sentinel otherwise it would never be destroyed
Definition: unusedFeatureTileTracker.h:220
boost::shared_ptr< Sentinel > getSentinel(bool loadIfNotPresent=true) const
Returns the sentinel. If the sentinel does not exist then this function will cause loading to start...
tbb::spin_rw_mutex Mutex
Definition: unusedFeatureTileTracker.h:108
unsigned useCount() const
Number of references to the sentinel in existence.
const DtUnusedFeatureTileTracker::WeakPtr myTracker
Definition: unusedFeatureTileTracker.h:217
boost::weak_ptr< DtUnusedFeatureTileTracker > WeakPtr
Definition: unusedFeatureTileTracker.h:53
Definition: unusedFeatureTileTracker.h:228
Trackable(const DtUnusedFeatureTileTracker::Ptr &)
Tracks objects so they can be deleted at a later time.
Definition: unusedFeatureTileTracker.h:43
TrackableList::iterator iterator() const
Definition: unusedFeatureTileTracker.h:213
voidpf void uLong size
Definition: ioapi.h:39
boost::shared_ptr< Sentinel > Ptr
Definition: unusedFeatureTileTracker.h:235
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:265
Default on in debug, off in release.
Definition: objectCounter.h:31
void sentinelDestroyed()
called by sentinel destructor
boost::optional< TrackableList::iterator > myIterator
Definition: unusedFeatureTileTracker.h:221
This is a class which maintains a list of string command names and the callback functions that are to...
Definition: consoleCommandManager.h:56
boost::scoped_ptr< tbb::tbb_thread > myPageOutThread
Definition: unusedFeatureTileTracker.h:128
virtual bool unload()=0
Called by the tracker when it&#39;s time to unload.
boost::scoped_ptr< DtConsoleCommandManager > myCommandManager
Definition: unusedFeatureTileTracker.h:140
boost::shared_ptr< DtUnusedFeatureTileTracker > Ptr
Definition: unusedFeatureTileTracker.h:52
std::vector< Ptr > SubTrackerList
clear on exit
Definition: unusedFeatureTileTracker.h:134
Mixin interface for classes which wish to be tracked.
Definition: unusedFeatureTileTracker.h:145
virtual bool loading() const =0
Has this set been requested to load.
void addToUnusedList()
Add this object to the unused list, does not cause loading Use this to prevent an object from being d...
bool myDoneFlag
Definition: unusedFeatureTileTracker.h:127
virtual boost::shared_ptr< Trackable > getPtr() const =0
Trackable must be managed by a shared pointer, boost::enable_shared_from_this is encouraged for use i...
A utility class for use with DtConsoleCommandManager. This class takes ownership of an arbitrary numb...
Definition: consoleCommandManager.h:166
Mutex myTotalListMutex
Definition: unusedFeatureTileTracker.h:137
virtual std::string label() const =0
Only used for output, won&#39;t change operation.
boost::shared_ptr< Trackable > TrackablePtr
Definition: unusedFeatureTileTracker.h:54
std::list< Trackable * > TrackableRawPtrList
Definition: unusedFeatureTileTracker.h:56
bool notInList() const
keeps an iterator to itself in the unused list so we can quickly remove
Definition: unusedFeatureTileTracker.h:212
tbb::spin_rw_mutex Mutex
Definition: unusedFeatureTileTracker.h:206
tbb::atomic< unsigned > myMaxSize
Definition: unusedFeatureTileTracker.h:130
tbb::tick_count unusedTime() const
Time at which object became unused.
TrackableRawPtrList myTrackables
Definition: unusedFeatureTileTracker.h:138
Sentinel(const boost::shared_ptr< Trackable > &)
boost::optional< TrackableRawPtrList::iterator > myTrackableListIterator
Definition: unusedFeatureTileTracker.h:222
SubTrackerList mySubtrackers
Definition: unusedFeatureTileTracker.h:135
boost::scoped_ptr< DtConsoleCommandOwner > myCommandOwner
Definition: unusedFeatureTileTracker.h:141
Mutex myMutex
Definition: unusedFeatureTileTracker.h:215
const boost::shared_ptr< Trackable > myTrackable
Definition: unusedFeatureTileTracker.h:244
tbb::atomic< double > myMinUnusedTime
Definition: unusedFeatureTileTracker.h:131
virtual void load()=0
Called when the sentinel is created.
static bool UnloadTryCatch(Trackable &)
Call unload, catch exceptions and print errors.
Mutex myMutex
Definition: unusedFeatureTileTracker.h:124
virtual unsigned size() const =0
Size of data stored in this object. This value is in no particular units, it is only compared to to t...
tbb::tick_count myUnusedTime
time at which object became unused
Definition: unusedFeatureTileTracker.h:225
TrackableList myUnused
Definition: unusedFeatureTileTracker.h:125
void print(double **a, int r, int c, char *str)

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)