VR-Forces 4.8 Class Documentation
 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) 2013 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  : public DtObjectDebugger<DtUnusedFeatureTileTracker>
45  {
46  public:
49 
50  typedef boost::shared_ptr<DtUnusedFeatureTileTracker> Ptr;
51  typedef boost::weak_ptr<DtUnusedFeatureTileTracker> WeakPtr;
52  typedef boost::shared_ptr<Trackable> TrackablePtr;
53  typedef std::list<TrackablePtr> TrackableList;
54  typedef std::list<Trackable*> TrackableRawPtrList;
55 
60  const std::string& name = "tracker");
61 
65 
67  void start();
68 
70  unsigned length() const;
71 
73  unsigned size() const;
74 
76  unsigned totalLength() const;
77 
79  void setMaxSize(unsigned max);
80 
82  unsigned maxSize() const;
83 
85  void setMinUnusedTime(double);
86 
88  double minUnusedTime() const;
89 
91  unsigned long unloadUntilSize(unsigned maxSize, double minTime);
92  unsigned long unloadUntilSize(unsigned maxSize);
93 
95  void addSubtracker(const Ptr& subtracker);
96 
98  void info(std::ostream&) const;
99 
101  void print(std::ostream&) const;
102 
103  private:
104  friend class Trackable;
105 
106  typedef tbb::spin_rw_mutex Mutex;
107 
109  bool add(Trackable&);
110 
111  bool add(const boost::shared_ptr<Trackable>&);
112 
114  bool remove(Trackable&);
115 
117  bool removeAndUnload(Trackable&);
118 
120  void run();
121 
122  mutable Mutex myMutex;
124 
126  boost::scoped_ptr<tbb::tbb_thread> myPageOutThread;
127 
128  tbb::atomic<unsigned> myMaxSize;
129  tbb::atomic<double> myMinUnusedTime;
130 
132  typedef std::vector<Ptr> SubTrackerList;
134 
137 
138  boost::scoped_ptr<DtConsoleCommandManager> myCommandManager;
139  boost::scoped_ptr<DtConsoleCommandOwner> myCommandOwner;
140  };
141 
144  : private boost::noncopyable
145  , public DtObjectDebugger<DtUnusedFeatureTileTracker::Trackable>
146  {
147  public:
149  static bool UnloadTryCatch(Trackable&);
150 
152  virtual ~Trackable();
153 
155  virtual std::string label() const = 0;
156 
158  virtual void load() = 0;
159 
161  virtual bool unload() = 0;
162 
164  virtual bool loading() const = 0;
165 
167  virtual bool loaded() const = 0;
168 
172  virtual unsigned size() const = 0;
173 
179  virtual boost::shared_ptr<Trackable> getPtr() const = 0;
180 
183  boost::shared_ptr<Sentinel> getSentinel(bool loadIfNotPresent=true) const;
184 
187  void addToUnusedList();
188 
190  unsigned useCount() const;
191 
193  tbb::tick_count unusedTime() const;
194 
195  protected:
197 
198  private:
200  friend class Sentinel;
201 
202  typedef tbb::spin_rw_mutex Mutex;
203 
205  void sentinelDestroyed();
206 
208  bool notInList() const { return !myIterator; }
209  TrackableList::iterator iterator() const { return *myIterator; }
210 
211  mutable Mutex myMutex;
212 
214 
216  boost::weak_ptr<Sentinel> mySentinel;
217  boost::optional<TrackableList::iterator> myIterator;
218  boost::optional<TrackableRawPtrList::iterator> myTrackableListIterator;
219 
221  tbb::tick_count myUnusedTime;
222  };
223 
225  : private boost::noncopyable
226  , public DtObjectDebugger<DtUnusedFeatureTileTracker::Sentinel>
227  {
228  public:
229  typedef boost::shared_ptr<Sentinel> Ptr;
230 
231  ~Sentinel();
232 
233  private:
234  friend class Trackable;
235 
236  explicit Sentinel(const boost::shared_ptr<Trackable>&);
237 
238  const boost::shared_ptr<Trackable> myTrackable;
239  };
240 }
241 
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:36
std::list< TrackablePtr > TrackableList
Definition: unusedFeatureTileTracker.h:53
boost::weak_ptr< Sentinel > mySentinel
weak ptr to sentinel otherwise it would never be destroyed
Definition: unusedFeatureTileTracker.h:216
boost::shared_ptr< Sentinel > getSentinel(bool loadIfNotPresent=true) const
Returns the sentinel.
tbb::spin_rw_mutex Mutex
Definition: unusedFeatureTileTracker.h:106
unsigned useCount() const
Number of references to the sentinel in existence.
const DtUnusedFeatureTileTracker::WeakPtr myTracker
Definition: unusedFeatureTileTracker.h:213
boost::weak_ptr< DtUnusedFeatureTileTracker > WeakPtr
Definition: unusedFeatureTileTracker.h:51
Definition: unusedFeatureTileTracker.h:224
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:209
voidpf void uLong size
Definition: ioapi.h:39
boost::shared_ptr< Sentinel > Ptr
Definition: unusedFeatureTileTracker.h:229
#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:217
This is a class which maintains a list of string command names and the callback functions that are to...
Definition: consoleCommandManager.h:48
boost::scoped_ptr< tbb::tbb_thread > myPageOutThread
Definition: unusedFeatureTileTracker.h:126
virtual bool unload()=0
Called by the tracker when it&#39;s time to unload.
boost::scoped_ptr< DtConsoleCommandManager > myCommandManager
Definition: unusedFeatureTileTracker.h:138
boost::shared_ptr< DtUnusedFeatureTileTracker > Ptr
Definition: unusedFeatureTileTracker.h:50
std::vector< Ptr > SubTrackerList
clear on exit
Definition: unusedFeatureTileTracker.h:132
Mixin interface for classes which wish to be tracked.
Definition: unusedFeatureTileTracker.h:143
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:125
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.
Definition: consoleCommandManager.h:157
Mutex myTotalListMutex
Definition: unusedFeatureTileTracker.h:135
virtual std::string label() const =0
Only used for output, won&#39;t change operation.
boost::shared_ptr< Trackable > TrackablePtr
Definition: unusedFeatureTileTracker.h:52
std::list< Trackable * > TrackableRawPtrList
Definition: unusedFeatureTileTracker.h:54
bool notInList() const
keeps an iterator to itself in the unused list so we can quickly remove
Definition: unusedFeatureTileTracker.h:208
tbb::spin_rw_mutex Mutex
Definition: unusedFeatureTileTracker.h:202
tbb::atomic< unsigned > myMaxSize
Definition: unusedFeatureTileTracker.h:128
tbb::tick_count unusedTime() const
Time at which object became unused.
TrackableRawPtrList myTrackables
Definition: unusedFeatureTileTracker.h:136
Sentinel(const boost::shared_ptr< Trackable > &)
boost::optional< TrackableRawPtrList::iterator > myTrackableListIterator
Definition: unusedFeatureTileTracker.h:218
SubTrackerList mySubtrackers
Definition: unusedFeatureTileTracker.h:133
boost::scoped_ptr< DtConsoleCommandOwner > myCommandOwner
Definition: unusedFeatureTileTracker.h:139
Mutex myMutex
Definition: unusedFeatureTileTracker.h:211
const boost::shared_ptr< Trackable > myTrackable
Definition: unusedFeatureTileTracker.h:238
tbb::atomic< double > myMinUnusedTime
Definition: unusedFeatureTileTracker.h:129
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:122
virtual unsigned size() const =0
Size of data stored in this object.
tbb::tick_count myUnusedTime
time at which object became unused
Definition: unusedFeatureTileTracker.h:221
TrackableList myUnused
Definition: unusedFeatureTileTracker.h:123
void print(double **a, int r, int c, char *str)

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)