VR-Forces 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/spin_rw_mutex.h>
15 #include <tbb/tick_count.h>
16 #include <atomic>
17 
18 #include <boost/optional.hpp>
19 #include <boost/noncopyable.hpp>
20 
21 #include <list>
22 
23 #include <vrfutil/objectCounter.h>
24 
27 
28 namespace MAKVRinTerra
29 {
41 #ifdef DtObjectDebugger_Enable
42  : public DtObjectDebugger<DtUnusedFeatureTileTracker>
43 #endif
44  {
45  public:
48 
49  typedef std::shared_ptr<DtUnusedFeatureTileTracker> Ptr;
50  typedef std::weak_ptr<DtUnusedFeatureTileTracker> WeakPtr;
51  typedef std::shared_ptr<Trackable> TrackablePtr;
52  typedef std::list<TrackablePtr> TrackableList;
53  typedef std::list<Trackable*> TrackableRawPtrList;
54 
59  const std::string& name = "tracker");
60 
64 
66  void start();
67 
69  unsigned length() const;
70 
72  unsigned size() const;
73 
75  unsigned totalLength() const;
76 
78  void setMaxSize(unsigned max);
79 
81  unsigned maxSize() const;
82 
84  void setMinUnusedTime(double);
85 
87  double minUnusedTime() const;
88 
90  unsigned long unloadUntilSize(unsigned maxSize, double minTime);
91  unsigned long unloadUntilSize(unsigned maxSize);
92 
94  void addSubtracker(const Ptr& subtracker);
95 
97  void info(std::ostream&) const;
98 
100  void print(std::ostream&) const;
101 
102  private:
103  friend class Trackable;
104 
105  typedef tbb::spin_rw_mutex Mutex;
106 
108  bool add(Trackable&);
109 
110  bool add(const std::shared_ptr<Trackable>&);
111 
113  bool remove(Trackable&);
114 
116  bool removeAndUnload(Trackable&);
117 
119  void run();
120 
121  mutable Mutex myMutex;
123 
125  std::unique_ptr<std::thread> myPageOutThread;
126 
127  std::atomic<unsigned> myMaxSize;
128  std::atomic<double> myMinUnusedTime;
129 
131  typedef std::vector<Ptr> SubTrackerList;
133 
136 
137  std::unique_ptr<DtConsoleCommandManager> myCommandManager;
138  std::unique_ptr<DtConsoleCommandOwner> myCommandOwner;
139  };
140 
143  : private boost::noncopyable
144 #ifdef DtObjectDebugger_Enable
145  , public DtObjectDebugger<DtUnusedFeatureTileTracker::Trackable>
146 #endif
147  {
148  public:
150  static bool UnloadTryCatch(Trackable&);
151 
153  virtual ~Trackable();
154 
156  virtual std::string label() const = 0;
157 
159  virtual void load() = 0;
160 
162  virtual bool unload() = 0;
163 
165  virtual bool loading() const = 0;
166 
168  virtual bool loaded() const = 0;
169 
173  virtual unsigned size() const = 0;
174 
180  virtual std::shared_ptr<Trackable> getPtr() const = 0;
181 
184  std::shared_ptr<Sentinel> getSentinel(bool loadIfNotPresent=true) const;
185 
188  void addToUnusedList();
189 
191  unsigned useCount() const;
192 
194  tbb::tick_count unusedTime() const;
195 
196  protected:
198 
199  private:
201  friend class Sentinel;
202 
203  typedef tbb::spin_rw_mutex Mutex;
204 
206  void sentinelDestroyed();
207 
209  bool notInList() const { return !myIterator; }
210  TrackableList::iterator iterator() const { return *myIterator; }
211 
212  mutable Mutex myMutex;
213 
215 
217  std::weak_ptr<Sentinel> mySentinel;
218  boost::optional<TrackableList::iterator> myIterator;
219  boost::optional<TrackableRawPtrList::iterator> myTrackableListIterator;
220 
222  tbb::tick_count myUnusedTime;
223  };
224 
226  : private boost::noncopyable
227 #ifdef DtObjectDebugger_Enable
228  , public DtObjectDebugger<DtUnusedFeatureTileTracker::Sentinel>
229 #endif
230  {
231  public:
232  typedef std::shared_ptr<Sentinel> Ptr;
233 
234  ~Sentinel();
235 
236  private:
237  friend class Trackable;
238 
239  explicit Sentinel(const std::shared_ptr<Trackable>&);
240 
241  const std::shared_ptr<Trackable> myTrackable;
242  };
243 }
244 
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:52
std::unique_ptr< std::thread > myPageOutThread
Definition: unusedFeatureTileTracker.h:125
tbb::spin_rw_mutex Mutex
Definition: unusedFeatureTileTracker.h:105
unsigned useCount() const
Number of references to the sentinel in existence.
const DtUnusedFeatureTileTracker::WeakPtr myTracker
Definition: unusedFeatureTileTracker.h:214
Definition: unusedFeatureTileTracker.h:225
Trackable(const DtUnusedFeatureTileTracker::Ptr &)
std::shared_ptr< DtUnusedFeatureTileTracker > Ptr
Definition: unusedFeatureTileTracker.h:49
Tracks objects so they can be deleted at a later time.
Definition: unusedFeatureTileTracker.h:40
TrackableList::iterator iterator() const
Definition: unusedFeatureTileTracker.h:210
voidpf void uLong size
Definition: ioapi.h:39
std::unique_ptr< DtConsoleCommandManager > myCommandManager
Definition: unusedFeatureTileTracker.h:137
std::shared_ptr< Trackable > TrackablePtr
Definition: unusedFeatureTileTracker.h:51
std::unique_ptr< DtConsoleCommandOwner > myCommandOwner
Definition: unusedFeatureTileTracker.h:138
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:31
Default on in debug, off in release.
Definition: objectCounter.h:27
void sentinelDestroyed()
called by sentinel destructor
std::shared_ptr< Sentinel > Ptr
Definition: unusedFeatureTileTracker.h:232
boost::optional< TrackableList::iterator > myIterator
Definition: unusedFeatureTileTracker.h:218
This is a class which maintains a list of string command names and the callback functions that are to...
Definition: consoleCommandManager.h:56
std::weak_ptr< DtUnusedFeatureTileTracker > WeakPtr
Definition: unusedFeatureTileTracker.h:50
std::weak_ptr< Sentinel > mySentinel
weak ptr to sentinel otherwise it would never be destroyed
Definition: unusedFeatureTileTracker.h:217
virtual bool unload()=0
Called by the tracker when it&#39;s time to unload.
virtual std::shared_ptr< Trackable > getPtr() const =0
Trackable must be managed by a shared pointer, std::enable_shared_from_this is encouraged for use in ...
void print(double **a, int r, int c, const char *str)
std::vector< Ptr > SubTrackerList
clear on exit
Definition: unusedFeatureTileTracker.h:131
Mixin interface for classes which wish to be tracked.
Definition: unusedFeatureTileTracker.h:142
virtual bool loading() const =0
Has this set been requested to load.
Sentinel(const std::shared_ptr< Trackable > &)
const std::shared_ptr< Trackable > myTrackable
Definition: unusedFeatureTileTracker.h:241
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:124
A utility class for use with DtConsoleCommandManager. This class takes ownership of an arbitrary numb...
Definition: consoleCommandManager.h:168
Mutex myTotalListMutex
Definition: unusedFeatureTileTracker.h:134
virtual std::string label() const =0
Only used for output, won&#39;t change operation.
std::list< Trackable * > TrackableRawPtrList
Definition: unusedFeatureTileTracker.h:53
bool notInList() const
keeps an iterator to itself in the unused list so we can quickly remove
Definition: unusedFeatureTileTracker.h:209
tbb::spin_rw_mutex Mutex
Definition: unusedFeatureTileTracker.h:203
tbb::tick_count unusedTime() const
Time at which object became unused.
TrackableRawPtrList myTrackables
Definition: unusedFeatureTileTracker.h:135
DT_DLL_VRVCORE double length(const makVrv::DtCoordinateSystem &, const std::vector< DtVector > &vertices)
Returns the total distance of a segmented line defined by the provided vector of vertices. Coordinates are in local database coordinates. The coordinate system is used to convert between the local database coordinates and geocentric. All distance is in 2D – the Z value is ignored.
boost::optional< TrackableRawPtrList::iterator > myTrackableListIterator
Definition: unusedFeatureTileTracker.h:219
std::atomic< double > myMinUnusedTime
Definition: unusedFeatureTileTracker.h:128
SubTrackerList mySubtrackers
Definition: unusedFeatureTileTracker.h:132
Mutex myMutex
Definition: unusedFeatureTileTracker.h:212
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:121
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...
std::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...
std::atomic< unsigned > myMaxSize
Definition: unusedFeatureTileTracker.h:127
tbb::tick_count myUnusedTime
time at which object became unused
Definition: unusedFeatureTileTracker.h:222
TrackableList myUnused
Definition: unusedFeatureTileTracker.h:122

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)