VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)