xmsinterp  1.0
ThreadLoop.cpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
6 //------------------------------------------------------------------------------
7 
8 //----- Included files ---------------------------------------------------------
9 
10 // 1. Precompiled header
11 
12 // 2. My own header
14 
15 // 3. Standard library headers
16 
17 // 4. External library headers
18 
19 // 5. Shared code headers
20 
21 // 6. Non-shared code headers
22 
23 //----- Forward declarations ---------------------------------------------------
24 
25 //----- External globals -------------------------------------------------------
26 
27 //----- Namespace declaration --------------------------------------------------
28 namespace xms
29 {
30 //----- Constants / Enumerations -----------------------------------------------
31 
32 //----- Classes / Structs ------------------------------------------------------
35 {
36 public:
37  impl()
38  : m_start(-1)
39  , m_nIter(-1)
40  , m_curIdx(-1)
41  , m_cntPtr(nullptr)
42  {
43  }
44 
45  int m_start;
46  int m_nIter;
47  int m_curIdx;
48  int* m_cntPtr;
49 };
50 
51 //----- Internal functions -----------------------------------------------------
52 
53 //----- Class / Function definitions -------------------------------------------
54 
59 //------------------------------------------------------------------------------
61 //------------------------------------------------------------------------------
62 ThreadLoop::ThreadLoop()
63 : m_p(new ThreadLoop::impl)
64 {
65 } // ThreadLoop::ThreadLoop
66 //------------------------------------------------------------------------------
68 //------------------------------------------------------------------------------
69 ThreadLoop::~ThreadLoop()
70 {
71 } // ThreadLoop::~ThreadLoop
72 //------------------------------------------------------------------------------
78 //------------------------------------------------------------------------------
79 void ThreadLoop::SetStartNumIterCnt(int a_startIdx, int a_numIter, int* a_cntPtr)
80 {
81  m_p->m_start = a_startIdx;
82  m_p->m_nIter = a_numIter;
83  m_p->m_cntPtr = a_cntPtr;
84 } // ThreadLoop::SetStartEnd
85 //------------------------------------------------------------------------------
88 //------------------------------------------------------------------------------
90 {
91  return m_p->m_curIdx;
92 } // ThreadLoop::CurrIdx
93 //------------------------------------------------------------------------------
95 //------------------------------------------------------------------------------
97 {
98  m_p->m_curIdx = m_p->m_start;
99  for (int i = 0; i < m_p->m_nIter; ++i, ++m_p->m_curIdx, ++(*m_p->m_cntPtr))
100  {
101  Worker();
102  }
103 } // ThreadLoop::operator()
104 
105 } // namespace xms
void DoWork()
Executes the work of the thread.
Definition: ThreadLoop.cpp:96
int m_curIdx
current index the thread is executing
Definition: ThreadLoop.cpp:47
int * m_cntPtr
pointer to a counter for this thread, updated on each iteration
Definition: ThreadLoop.cpp:48
int CurrIdx()
Returns the current index of the thread.
Definition: ThreadLoop.cpp:89
Thread worker class.
Definition: ThreadLoop.h:23
BSHP< impl > m_p
implementation class
Definition: ThreadLoop.h:42
Implementation of ThreadLoop.
Definition: ThreadLoop.cpp:34
int m_start
starting index for the thread
Definition: ThreadLoop.cpp:45
void SetStartNumIterCnt(int a_startIdx, int a_numIter, int *a_cntPtr)
Sets up the thread worker.
Definition: ThreadLoop.cpp:79
int m_nIter
number of interations for the thread to perform
Definition: ThreadLoop.cpp:46
virtual void Worker()=0
Overridden by derived class.