ScummVM API documentation
dgThreads.h
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #if !defined(AFX_DG_THREADS_42YH_HY78GT_YHJ63Y__INCLUDED_)
23 #define AFX_DG_THREADS_42YH_HY78GT_YHJ63Y__INCLUDED_
24 
25 #define DG_MAXQUEUE 16
26 
27 
29 public:
30  dgWorkerThread() {
31  m_threadIndex = -1;
32  }
33  virtual void ThreadExecute() = 0;
34  virtual ~dgWorkerThread() {}
35 
36  dgInt32 m_threadIndex;
37 };
38 
39 
40 class dgThreads {
41 public:
42  dgThreads();
43  ~dgThreads();
44 
45  void CreateThreaded(dgInt32 threadCount);
46  void DestroydgThreads();
47 
48  void ClearTimers();
49  void SetPerfomanceCounter(OnGetPerformanceCountCallback callback);
50  dgUnsigned32 GetPerfomanceTicks(dgUnsigned32 threadIndex) const;
51 
52  dgInt32 GetThreadCount() const ;
53  dgInt32 SubmitJob(dgWorkerThread *const job);
54  void SynchronizationBarrier();
55  void CalculateChunkSizes(dgInt32 elements, dgInt32 *const chunkSizes) const;
56 
57  void dgGetLock() const;
58  void dgReleaseLock() const;
59 
60  void dgGetIndirectLock(dgInt32 *lockVar);
61  void dgReleaseIndirectLock(dgInt32 *lockVar);
62 
63 private:
64  struct dgLocadData {
65  dgInt32 m_ticks;
66  dgInt32 m_threadIndex;
67  dgThreads *m_manager;
68  };
69 
70  void DoWork(dgInt32 threadIndex);
71  dgInt32 GetWork(dgWorkerThread **cWork);
72 
73 
74  static void *ThreadExecute(void *Param);
75 
76  dgInt32 m_numOfThreads;
77  dgInt32 m_numberOfCPUCores;
78  dgInt32 m_topIndex;
79  dgInt32 m_bottomIndex;
80  dgInt32 m_workInProgress;
81  mutable dgInt32 m_globalSpinLock;
82 
83  bool m_exit;
84  //dgInt32 m_emptySlot;
85  //dgInt32 m_workToDo;
86  //dgInt32 m_criticalSection;
87  dgInt32 m_workToDoSpinLock;
88  dgWorkerThread *m_queue[DG_MAXQUEUE];
89  //pthread_t m_threadhandles[DG_MAXIMUN_THREADS];
90 
91  OnGetPerformanceCountCallback m_getPerformanceCount;
92  dgLocadData m_localData[DG_MAXIMUN_THREADS];
93 };
94 
95 
96 
97 #endif
Definition: dgThreads.h:28
Definition: dgThreads.h:40