VR-Forces 4.1.1 Class Documentation
asyncLoadingFeatureSet.h
Go to the documentation of this file.
1 
2 
3 
4 
5 #pragma once
6 
7 #include <features/featureSet.h>
8 
9 #include <tbb/mutex.h>
10 #include <tbb/spin_mutex.h>
11 #include <tbb/tbb_thread.h>
12 #include <tbb/compat/condition_variable>
13 #include <tbb/task.h>
14 
15 namespace MAKVRinTerra
16 {
18  template <typename F>
20  : public DtFeatureSetTemplate<F>
21  , public boost::enable_shared_from_this<DtAsyncLoadingFeatureSet<F> >
22  {
23  public:
24  typedef boost::shared_ptr<DtAsyncLoadingFeatureSet> Ptr;
25  typedef boost::weak_ptr<DtAsyncLoadingFeatureSet> WPtr;
28  typedef boost::function<FeatureSet* (FeatureSet*)> TileFactory;
29  typedef boost::function<void (const FeatureSet&)> Callback;
30  typedef typename FeatureSet::Empty Empty;
31 
33  virtual void start() = 0;
34 
36  virtual bool loading() const;
37 
38  void forEachFeature(ForEachFunction, DtWaitType) const;
39  void forEachFeatureParallel(ForEachFunction, DtWaitType) const;
40  DtQuery schema() const;
41  FeatureSet* filter(const DtQuery&, DtLoadType) const;
42  FeatureSet* clone() const;
43  bool loaded(double) const;
44  unsigned numberOfFeatures() const;
45 
46  protected:
47  typedef tbb::spin_rw_mutex RWMutex;
48  typedef tbb::mutex Mutex;
49  typedef tbb::interface5::condition_variable ConditionVariable;
50  typedef tbb::interface5::unique_lock<Mutex> ScopedLock;
51 
52  struct Caller;
53 
54  static void Run(WPtr);
55 
57  virtual void run(const Ptr&);
58 
60  FeatureSet* input, DtQuery query, Callback callback, TileFactory factory);
61 
62  mutable RWMutex myRWMutex;
63  mutable Mutex myMutex;
65 
66  std::auto_ptr<FeatureSet> myInputFeatureSet;
69  boost::scoped_ptr<FeatureSet> myFeatureSet;
73  };
74 
75  template <typename F>
77  : public DtAsyncLoadingFeatureSet<F>
78  {
79  public:
80  typedef boost::shared_ptr<DtThreadLoadingFeatureSet> Ptr;
84 
89  static Ptr Make(
90  FeatureSet* input,
91  DtQuery query = true,
92  Callback callback = Callback(),
93  TileFactory factory = &FeatureSet::Storage::Make);
94 
95  void start();
96 
97  protected:
100 
102  FeatureSet* input, DtQuery query, Callback callback, TileFactory factory);
103 
104  boost::scoped_ptr<tbb::tbb_thread> myThread;
105  };
106 
107  template <typename F>
109  : public DtAsyncLoadingFeatureSet<F>
110  {
111  public:
112  typedef boost::shared_ptr<DtTaskLoadingFeatureSet> Ptr;
113  typedef boost::shared_ptr<DtTaskLoadingFeatureSet> WPtr;
118 
119  static Ptr Make(
120  FeatureSet* input,
121  DtQuery query = true,
122  Callback callback = Callback(),
123  TileFactory factory = &FeatureSet::Storage::Make);
124 
125  void start();
126 
127  protected:
128  class Task : public tbb::task
129  {
130  public:
131  explicit Task(BaseWPtr);
132 
133  tbb::task* execute();
134 
135  private:
137  };
138 
139  friend class Task;
140 
142  FeatureSet* input, DtQuery query, Callback callback, TileFactory factory);
143 
144  typedef tbb::spin_mutex Mutex;
145 
148  };
149 
150  template <typename F>
152  : public DtAsyncLoadingFeatureSet<F>
153  {
154  public:
155  typedef boost::shared_ptr<DtQueueLoadingFeatureSet> Ptr;
156  typedef boost::shared_ptr<DtQueueLoadingFeatureSet> WPtr;
162 
163  class Task;
164 
165  class Queue : public boost::enable_shared_from_this<Queue>
166  {
167  public:
168  explicit Queue(unsigned maxTasks);
169 
170  void add(BasePtr);
171  bool pop(BaseWPtr&);
172 
173  friend class Task;
174 
175  private:
176  void taskDestroyed();
177 
178  typedef tbb::spin_mutex Mutex;
179  typedef std::list<typename DtAsyncLoadingFeatureSet<F>::WPtr> WPtrList;
180 
181  mutable Mutex myMutex;
183  unsigned myMaxTasks;
184  unsigned myTasks;
185  };
186 
187  static Ptr Make(
188  boost::shared_ptr<Queue> queue,
189  FeatureSet* input,
190  DtQuery query = true,
191  Callback callback = Callback(),
192  TileFactory factory = &FeatureSet::Storage::Make);
193 
194  void start();
195 
196  class Task : public tbb::task
197  {
198  public:
199  explicit Task(boost::shared_ptr<Queue>);
200 
201  ~Task();
202 
203  tbb::task* execute();
204 
205  private:
206  boost::shared_ptr<Queue> myQueue;
207  };
208 
209  friend class Task;
210 
212  boost::shared_ptr<Queue> queue,
213  FeatureSet* input, DtQuery query, Callback callback, TileFactory factory);
214 
215  typedef tbb::spin_mutex Mutex;
216 
219  boost::shared_ptr<Queue> myQueue;
220  };
221 }

Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)