VR-Forces 4.6.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
parallelTickManager.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
9 
12 
13 #pragma once
14 
15 #include "vrfcore/vrfcoreDefines.h"
16 
18 #include "vrfutil/profiler.h"
19 
20 #include <boost/noncopyable.hpp>
21 #include <boost/unordered/unordered_map.hpp>
22 
23 #include <tbb/mutex.h>
24 #include <tbb/tbb_thread.h>
25 #include <tbb/compat/condition_variable>
26 #include <tbb/enumerable_thread_specific.h>
27 
28 #include <vector>
29 
34 class DtCriticalSection;
35 class DtSimManager;
36 
60 class DT_DLL_vrfcore DtParallelTickManager : boost::noncopyable
61 {
62 public:
64  {
67  UNLOCKED
68  };
69 
73  {
74  friend class DtParallelTickManager;
75 
77  void run();
78 
79  public:
80  virtual ~CallbackInterface();
81 
83  virtual void runCallback() = 0;
84  };
85 
86  typedef boost::unordered_map<std::string, bool> EnabledMap;
87 
89  virtual ~DtParallelTickManager();
90 
92  virtual void setCallbackQueue(DtVrfCallbackQueue*);
93 
95  virtual DtVrfCallbackQueue* queue() const;
96 
103 
104  virtual void flushQueue(bool useThisThread);
105  virtual void flushQueue();
107 
109 
110  virtual bool mainThreadWait() const;
111  virtual void setMainThreadWait(bool);
113 
116 
117  virtual bool active() const;
118  virtual void setActive(bool);
120 
129  virtual bool enabled(const std::string&, bool def) const;
130 
132  virtual bool executeCommand(const std::string&, bool on);
133 
135  virtual void printInfo(std::ostream&) const;
136 
144 
145  virtual void addCallback(CallbackInterface*);
146  virtual void addCallback(CallbackInterface&);
147 
148  virtual void addCallback(CallbackInterface*, const std::string& tag, bool def=true);
149  virtual void addCallback(CallbackInterface&, const std::string& tag, bool def=true);
150 
151  void addCallback(CallbackInterface*, const char* tag, bool def=true);
152  void addCallback(CallbackInterface&, const char* tag, bool def=true);
153 
154  template <typename Container>
155  void addCallbacks(Container& cont)
156  {
157  typedef typename Container::iterator iterator;
158  for (iterator i=cont.begin(), end=cont.end(); i != end; ++i)
159  addCallback(*i);
160  }
161 
162  template <typename Container>
163  void addCallbacks(Container& cont, const std::string& tag, bool def=true)
164  {
165  bool runNow = !enabled(tag, def);
166  typedef typename Container::iterator iterator;
167  if (runNow)
168  {
169  for (iterator i = cont.begin(), end = cont.end(); i != end; ++i)
170  {
171  RunJob(*i);
172  }
173  }
174  else
175  {
176  for (iterator i = cont.begin(), end = cont.end(); i != end; ++i)
177  {
178  addCallback(*i);
179  }
180  }
181  }
182 
183  template <typename Container>
184  void addCallbacks(Container& cont, const char* tag, bool def=true)
185  {
186  addCallbacks(cont, std::string(tag), def);
187  }
189 
191 
192  virtual void lock();
193  virtual void unlock();
194  virtual void readLock();
195  virtual void readUnlock();
196  virtual void upgradeToWriter();
197  virtual void downgradeToReader();
198 
199  virtual void changeAccess(AccessType from, AccessType to);
201 
202  class ThreadLocalInfo;
203 
204  virtual ThreadLocalInfo& threadLocalInfo();
205 
206 private:
207  static void RunJob(CallbackInterface*);
208  static void RunJob(CallbackInterface&);
209 
210  tbb::atomic<int> myAccessCount;
211 
212  typedef tbb::cache_aligned_allocator<ThreadLocalInfo*> ThreadLocalAllocator;
213  //typedef tbb::enumerable_thread_specific<
215  typedef tbb::enumerable_thread_specific<
216  ThreadLocalInfo*,
218  tbb::ets_key_per_instance> ThreadLocalContainer;
219 
221 
224 
227 
230 };
231 
240 class DT_DLL_vrfcore DtCriticalSection : boost::noncopyable
241 {
242 public:
244 
246  explicit DtCriticalSection(DtSimManager*, AccessType initState);
247 
249  explicit DtCriticalSection(DtSimManager*);
250 
253 
257 
259 
261  void reset(AccessType access);
262 
264  void unlock();
265 
267  void lockShared();
268 
270  void lock();
271 
273  void release()
274  {
275  reset(from);
276  }
277 
278 protected:
279  explicit DtCriticalSection(DtParallelTickManager*, AccessType to);
281 
282  friend class DtParallelTickManager;
283 
286 
289 };
290 
291 class DT_DLL_vrfcore DtParallelTickManager::ThreadLocalInfo : boost::noncopyable
292 {
293 public:
294  explicit ThreadLocalInfo(DtParallelTickManager* m);
295 
296  DtParallelTickManager::AccessType state() const;
297 
298 private:
299  friend class DtCriticalSection;
300 
301  void push(DtCriticalSection& cs);
302  void pop(DtCriticalSection& cs);
303 
304  typedef std::vector<DtCriticalSection*> Stack;
306 };

Document ID: Generated on Wed Jul 25 16:57:45 EDT 2018 from SVN revision 190790
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)