VR-Forces 4.2 Class Documentation
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 <boost/optional.hpp>
15 #include <list>
16 
17 #include <tbb/spin_rw_mutex.h>
18 #include <tbb/tbb_thread.h>
19 
20 namespace MAKVRinTerra
21 {
33  {
34  public:
37 
38  typedef boost::shared_ptr<DtUnusedFeatureTileTracker> Ptr;
39  typedef boost::weak_ptr<DtUnusedFeatureTileTracker> WeakPtr;
40  typedef boost::shared_ptr<Trackable> TrackablePtr;
41  typedef std::list<TrackablePtr> TrackableList;
42 
48  DtUnusedFeatureTileTracker(unsigned maxSize = 500000, unsigned numKeepLoading = 20);
49 
53 
55  void start();
56 
58  unsigned length() const;
59 
61  unsigned size() const;
62 
64  void setMaxSize(unsigned max);
65 
67  void unloadUntilSize(unsigned maxSize);
68 
69  private:
70  friend class Trackable;
71 
72  typedef tbb::spin_rw_mutex Mutex;
73 
75  bool add(Trackable&);
76 
78  bool remove(Trackable&);
79 
81  void run();
82 
83  mutable Mutex myMutex;
85 
86  bool myDoneFlag;
87  unsigned myMaxSize;
88  unsigned myNumKeepLoading;
89  boost::scoped_ptr<tbb::tbb_thread> myPageOutThread;
90  };
91 
93  class DtUnusedFeatureTileTracker::Trackable : private boost::noncopyable
94  {
95  public:
97  virtual ~Trackable();
98 
100  virtual void load() = 0;
101 
103  virtual void unload() = 0;
104 
106  virtual bool loading() const = 0;
107 
109  virtual bool loaded() const = 0;
110 
114  virtual unsigned size() const = 0;
115 
121  virtual boost::shared_ptr<Trackable> getPtr() = 0;
122 
125  boost::shared_ptr<Sentinel> getSentinel();
126 
128  unsigned useCount() const;
129 
130  protected:
132 
133  private:
135  friend class Sentinel;
136 
137  typedef tbb::spin_rw_mutex Mutex;
138 
140  void sentinelDestroyed();
141 
143  bool hasIterator() const { return myIterator; }
144  TrackableList::iterator iterator() const { return *myIterator; }
145 
146  mutable Mutex myMutex;
147 
149 
151  boost::weak_ptr<Sentinel> mySentinel;
152  boost::optional<TrackableList::iterator> myIterator;
153  };
154 
155  class DtUnusedFeatureTileTracker::Sentinel : private boost::noncopyable
156  {
157  public:
158  typedef boost::shared_ptr<Sentinel> Ptr;
159 
160  ~Sentinel();
161 
162  private:
163  friend class Trackable;
164 
165  Sentinel(boost::shared_ptr<Trackable>);
166 
167  boost::shared_ptr<Trackable> myTrackable;
168  };
169 }

Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)