VR-Forces 4.6 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*, bool runNow=false);
146  virtual void addCallback(CallbackInterface&, bool runNow=false);
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, bool runNow=false)
156  {
157  typedef typename Container::iterator iterator;
158  for (iterator i=cont.begin(), end=cont.end(); i != end; ++i)
159  addCallback(*i, runNow);
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  for (iterator i=cont.begin(), end=cont.end(); i != end; ++i)
168  addCallback(*i, runNow);
169  }
170 
171  template <typename Container>
172  void addCallbacks(Container& cont, const char* tag, bool def=true)
173  {
174  addCallbacks(cont, std::string(tag), def);
175  }
177 
179 
180  virtual void lock();
181  virtual void unlock();
182  virtual void readLock();
183  virtual void readUnlock();
184  virtual void upgradeToWriter();
185  virtual void downgradeToReader();
186 
187  virtual void changeAccess(AccessType from, AccessType to);
189 
190  class ThreadLocalInfo;
191 
192  virtual ThreadLocalInfo& threadLocalInfo();
193 
194 private:
196  virtual void createCallbackQueue(bool force=false);
197 
198  typedef tbb::mutex Mutex;
199  typedef tbb::interface5::condition_variable ConditionVariable;
200  typedef tbb::interface5::unique_lock<Mutex> ScopedLock;
201 
202  mutable Mutex myMutex;
206  unsigned myNumWriters;
207  unsigned myNumReaders;
209 
210  typedef tbb::cache_aligned_allocator<ThreadLocalInfo*> ThreadLocalAllocator;
211  //typedef tbb::enumerable_thread_specific<
213  typedef tbb::enumerable_thread_specific<
214  ThreadLocalInfo*,
216  tbb::ets_key_per_instance> ThreadLocalContainer;
217 
219 
222 
225 
228 };
229 
238 class DT_DLL_vrfcore DtCriticalSection : boost::noncopyable
239 {
240 public:
242 
244  explicit DtCriticalSection(DtSimManager*, AccessType initState);
245 
247  explicit DtCriticalSection(DtSimManager*);
248 
251 
255 
257 
259  void reset(AccessType access);
260 
262  void unlock();
263 
265  void lockShared();
266 
268  void lock();
269 
271  void release()
272  {
273  reset(from);
274  }
275 
276 protected:
277  explicit DtCriticalSection(DtParallelTickManager*, AccessType to);
279 
280  friend class DtParallelTickManager;
281 
284 
287 };
288 
289 class DT_DLL_vrfcore DtParallelTickManager::ThreadLocalInfo : boost::noncopyable
290 {
291 public:
292  explicit ThreadLocalInfo(DtParallelTickManager* m);
293 
294  DtParallelTickManager::AccessType state() const;
295 
296 private:
297  friend class DtCriticalSection;
298 
299  void push(DtCriticalSection& cs);
300  void pop(DtCriticalSection& cs);
301 
302  typedef std::vector<DtCriticalSection*> Stack;
304 };

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)