check transfer  0.1
Check data transfer for SDAccell OpenCL application
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
TF_TestThread Class Referenceabstract

Base class for application with thread. More...

#include <tf_testthread.h>

Inheritance diagram for TF_TestThread:
TF_Test TF_CheckTransferIn TF_CheckTransferOut

Public Member Functions

virtual void CleanupInThread ()=0
 Free any resource. More...
 
void * Execute ()
 
virtual void GetResult ()
 Show result of test. More...
 
virtual void GetResultInThread ()=0
 Show result. More...
 
virtual int isComplete ()
 Return 1 when test is complete. More...
 
virtual int Prepare (int cnt)
 Prepare test. More...
 
virtual void PrepareInThread ()=0
 Prepare test. More...
 
virtual void Run ()=0
 Main body of user test. More...
 
virtual void Start ()
 Start of test. More...
 
virtual void StepTable ()=0
 Show status information into test table. More...
 
virtual void Stop ()
 Stop of test. More...
 
 TF_TestThread (TableEngine *pTable, int argc, char **argv)
 
virtual ~TF_TestThread ()
 
- Public Member Functions inherited from TF_Test
virtual void StepMainThread ()
 Don't use. Reserve for future. More...
 
 TF_Test (TableEngine *pTable)
 

Static Public Member Functions

static void * ThreadFunc (void *lpvThreadParm)
 

Public Attributes

pthread_attr_t m_attrThread
 
int m_CycleCnt
 
pthread_t m_hThread
 
int m_isComplete
 
int m_isException
 
int m_isPrepareComplete
 
int m_isTerminate
 
pthread_mutex_t m_ResultCompleteMutex
 
pthread_mutex_t m_ResultStartMutex
 
pthread_mutex_t m_StartMutex
 
pthread_mutex_t m_ThreadExitMutex
 
- Public Attributes inherited from TF_Test
TableEnginem_pTemplateEngine
 

Detailed Description

Base class for application with thread.

Class creates additional thread.

Definition at line 23 of file tf_testthread.h.

Constructor & Destructor Documentation

◆ TF_TestThread()

TF_TestThread::TF_TestThread ( TableEngine pTable,
int  argc,
char **  argv 
)

Definition at line 21 of file tf_testthread.cpp.

References m_CycleCnt, m_isComplete, m_isException, m_isPrepareComplete, m_isTerminate, m_ResultCompleteMutex, m_ResultStartMutex, m_StartMutex, and m_ThreadExitMutex.

21  : TF_Test( pTable )
22 {
23  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld\n", __FUNCTION__, pthread_self());
24 
26  m_isComplete=0;
27  m_isTerminate=0;
28  m_CycleCnt=0;
29  m_isException=0;
30 
31  pthread_mutex_init(&m_ResultStartMutex, 0);
32  pthread_mutex_init(&m_ResultCompleteMutex, 0);
33  pthread_mutex_init(&m_StartMutex, 0);
34  pthread_mutex_init(&m_ThreadExitMutex, 0);
35 
36  // Lock mutex for Start and GetResult
37  pthread_mutex_lock(&m_ResultStartMutex);
38  pthread_mutex_lock(&m_ResultCompleteMutex);
39  pthread_mutex_lock(&m_StartMutex);
40  //pthread_mutex_lock(&m_ThreadExitMutex);
41 
42 }
pthread_mutex_t m_ResultStartMutex
Definition: tf_testthread.h:61
pthread_mutex_t m_StartMutex
Definition: tf_testthread.h:63
int m_isPrepareComplete
Definition: tf_testthread.h:55
TF_Test(TableEngine *pTable)
Definition: tf_test.h:23
pthread_mutex_t m_ResultCompleteMutex
Definition: tf_testthread.h:62
pthread_mutex_t m_ThreadExitMutex
Definition: tf_testthread.h:64

◆ ~TF_TestThread()

TF_TestThread::~TF_TestThread ( )
virtual

Definition at line 47 of file tf_testthread.cpp.

References m_ThreadExitMutex.

48 {
49  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld\n", __FUNCTION__, pthread_self());
50  pthread_mutex_lock(&m_ThreadExitMutex);
51  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld (COMPLETE)\n", __FUNCTION__, pthread_self());
52 }
pthread_mutex_t m_ThreadExitMutex
Definition: tf_testthread.h:64

Member Function Documentation

◆ CleanupInThread()

virtual void TF_TestThread::CleanupInThread ( )
pure virtual

Free any resource.

Implemented in TF_CheckTransferIn, and TF_CheckTransferOut.

Referenced by Execute().

◆ Execute()

void * TF_TestThread::Execute ( )

Definition at line 102 of file tf_testthread.cpp.

References CleanupInThread(), GetResultInThread(), _except_info_t::info, m_isComplete, m_isException, m_isPrepareComplete, m_ResultCompleteMutex, m_ResultStartMutex, m_StartMutex, m_ThreadExitMutex, PrepareInThread(), and Run().

Referenced by ThreadFunc().

103 {
104  try
105  {
106  pthread_mutex_lock(&m_ThreadExitMutex);
107 
108  PrepareInThread();
109 
110 
112 
113  // Sleep here while TF_TestThread::Start() will be called in another thread
114  pthread_mutex_lock(&m_StartMutex);
115 
116  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld (START)\n", __FUNCTION__, pthread_self());
117 
118  // Working forever while m_isTerminate == 0
119  Run();
120 
121  m_isComplete = 1;
122 
123  // Wait while TF_TestThread::GetResult() will be called
124  pthread_mutex_lock( &m_ResultStartMutex );
125 
127 
128  // Unlock mutex for complete GetResult() execution
129  pthread_mutex_unlock(&m_ResultCompleteMutex);
130 
131  CleanupInThread();
132 
133  // Unlock mutex for complete TF_TestThread::~TF_TestThread() execution
134  pthread_mutex_unlock(&m_ThreadExitMutex);
135 
136  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld (COMPLETE)\n", __FUNCTION__, pthread_self());
137 
138  }
139  catch( except_info_t err )
140  {
141  printf( "\n\n\n\n\n\n\n \n Error in thread:\n%s\n \n", err.info.c_str());
142  m_isComplete = 1;
143  m_isException = 1;
144  pthread_mutex_unlock(&m_ThreadExitMutex);
145  }
146 
147  catch( ... )
148  {
149  printf( "\n\n\n \n Unknow error in thread\n \n" );
150  m_isComplete = 1;
151  m_isException = 1;
152  pthread_mutex_unlock(&m_ThreadExitMutex);
153 
154  }
155 
156  return 0;
157 }
pthread_mutex_t m_ResultStartMutex
Definition: tf_testthread.h:61
virtual void GetResultInThread()=0
Show result.
virtual void PrepareInThread()=0
Prepare test.
pthread_mutex_t m_StartMutex
Definition: tf_testthread.h:63
int m_isPrepareComplete
Definition: tf_testthread.h:55
std::string info
Definition: exceptinfo.h:8
pthread_mutex_t m_ResultCompleteMutex
Definition: tf_testthread.h:62
pthread_mutex_t m_ThreadExitMutex
Definition: tf_testthread.h:64
virtual void CleanupInThread()=0
Free any resource.
virtual void Run()=0
Main body of user test.

◆ GetResult()

void TF_TestThread::GetResult ( )
virtual

Show result of test.

Reimplemented from TF_Test.

Definition at line 188 of file tf_testthread.cpp.

References m_ResultCompleteMutex, and m_ResultStartMutex.

189 {
190  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld (START)\n", __FUNCTION__, pthread_self());
191 
192  // Unlock mutex for finish Execute()
193  pthread_mutex_unlock(&m_ResultStartMutex);
194 
195  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld (Unlock m_ResultStartMutex)\n", __FUNCTION__, pthread_self());
196 
197  // Waiting here while GetResultInThread() will be called and complete from Execute();
198  pthread_mutex_lock(&m_ResultCompleteMutex);
199 
200  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld (COMPLETE)\n", __FUNCTION__, pthread_self());
201 }
pthread_mutex_t m_ResultStartMutex
Definition: tf_testthread.h:61
pthread_mutex_t m_ResultCompleteMutex
Definition: tf_testthread.h:62

◆ GetResultInThread()

virtual void TF_TestThread::GetResultInThread ( )
pure virtual

Show result.

Implemented in TF_CheckTransferIn, and TF_CheckTransferOut.

Referenced by Execute().

◆ isComplete()

int TF_TestThread::isComplete ( )
virtual

Return 1 when test is complete.

Reimplemented from TF_Test.

Definition at line 178 of file tf_testthread.cpp.

References m_isComplete.

179 {
180  //if(m_isComplete > 0)
181  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld\n", __FUNCTION__, pthread_self());
182 
183  return m_isComplete;
184 }

◆ Prepare()

int TF_TestThread::Prepare ( int  cnt)
virtual

Prepare test.

Parameters
cntnumber of call function
Returns
1 - prepare complete, 0 - prepare don't complete

Function is called during test preparation. Preparation of the test can be very long. When preparation is complete function must be return 1.

Preparation of the all tests is complete when all tests return 1

Implements TF_Test.

Definition at line 56 of file tf_testthread.cpp.

References except_info(), m_attrThread, m_hThread, m_isException, m_isPrepareComplete, and ThreadFunc().

57 {
58  if( 0==cnt )
59  {
60  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld\n", __FUNCTION__, pthread_self());
61  int res = pthread_attr_init(&m_attrThread);
62  if(res != 0) {
63  fprintf(stderr, "%s\n", "Stream not started");
64  throw( "Stream not started" );
65  }
66 
67  res = pthread_attr_setdetachstate(&m_attrThread, PTHREAD_CREATE_JOINABLE);
68  if(res != 0) {
69  fprintf(stderr, "%s\n", "Stream not started");
70  throw( "Stream not started" );
71  }
72 
73  res = pthread_create(&m_hThread, &m_attrThread, ThreadFunc, this);
74  if(res != 0) {
75  fprintf(stderr, "%s\n", "Stream not started");
76  throw( "Stream not started" );
77  }
78  }
79 
80  int ret=m_isPrepareComplete;
81 
82  if( m_isException )
83  {
84  throw except_info( "%s - exception during execute", __FUNCTION__ );
85  }
86  return ret;
87 }
static void * ThreadFunc(void *lpvThreadParm)
int m_isPrepareComplete
Definition: tf_testthread.h:55
except_info_t except_info(const char *fmt,...)
Definition: exceptinfo.cpp:25
pthread_t m_hThread
Definition: tf_testthread.h:66
pthread_attr_t m_attrThread
Definition: tf_testthread.h:67

◆ PrepareInThread()

virtual void TF_TestThread::PrepareInThread ( )
pure virtual

Prepare test.

Implemented in TF_CheckTransferIn, and TF_CheckTransferOut.

Referenced by Execute().

◆ Run()

virtual void TF_TestThread::Run ( )
pure virtual

Main body of user test.

Implemented in TF_CheckTransferIn, and TF_CheckTransferOut.

Referenced by Execute().

◆ Start()

void TF_TestThread::Start ( )
virtual

Start of test.

Implements TF_Test.

Definition at line 161 of file tf_testthread.cpp.

References m_StartMutex.

162 {
163  // Unlock mutex for unblock TF_TestThread::Execute() function
164  pthread_mutex_unlock(&m_StartMutex);
165  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld\n", __FUNCTION__, pthread_self());
166 }
pthread_mutex_t m_StartMutex
Definition: tf_testthread.h:63

◆ StepTable()

virtual void TF_TestThread::StepTable ( )
pure virtual

Show status information into test table.

Reimplemented from TF_Test.

Implemented in TF_CheckTransferIn, and TF_CheckTransferOut.

◆ Stop()

void TF_TestThread::Stop ( )
virtual

Stop of test.

Reimplemented from TF_Test.

Definition at line 170 of file tf_testthread.cpp.

References m_isTerminate.

171 {
172  m_isTerminate = 1;
173  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld\n", __FUNCTION__, pthread_self());
174 }

◆ ThreadFunc()

void * TF_TestThread::ThreadFunc ( void *  lpvThreadParm)
static

Definition at line 91 of file tf_testthread.cpp.

References Execute().

Referenced by Prepare().

92 {
93  TF_TestThread *test=(TF_TestThread*)lpvThreadParm;
94  if(!test)
95  return 0;
96  //fprintf(stderr, "TF_TestThread::%s(): ID - %ld\n", __FUNCTION__, pthread_self());
97  return test->Execute();
98 }
Base class for application with thread.
Definition: tf_testthread.h:23

Member Data Documentation

◆ m_attrThread

pthread_attr_t TF_TestThread::m_attrThread

Definition at line 67 of file tf_testthread.h.

Referenced by Prepare().

◆ m_CycleCnt

int TF_TestThread::m_CycleCnt

Definition at line 58 of file tf_testthread.h.

Referenced by TF_TestThread().

◆ m_hThread

pthread_t TF_TestThread::m_hThread

Definition at line 66 of file tf_testthread.h.

Referenced by Prepare().

◆ m_isComplete

int TF_TestThread::m_isComplete

Definition at line 56 of file tf_testthread.h.

Referenced by Execute(), isComplete(), and TF_TestThread().

◆ m_isException

int TF_TestThread::m_isException

Definition at line 59 of file tf_testthread.h.

Referenced by Execute(), Prepare(), and TF_TestThread().

◆ m_isPrepareComplete

int TF_TestThread::m_isPrepareComplete

Definition at line 55 of file tf_testthread.h.

Referenced by Execute(), Prepare(), and TF_TestThread().

◆ m_isTerminate

int TF_TestThread::m_isTerminate

◆ m_ResultCompleteMutex

pthread_mutex_t TF_TestThread::m_ResultCompleteMutex

Definition at line 62 of file tf_testthread.h.

Referenced by Execute(), GetResult(), and TF_TestThread().

◆ m_ResultStartMutex

pthread_mutex_t TF_TestThread::m_ResultStartMutex

Definition at line 61 of file tf_testthread.h.

Referenced by Execute(), GetResult(), and TF_TestThread().

◆ m_StartMutex

pthread_mutex_t TF_TestThread::m_StartMutex

Definition at line 63 of file tf_testthread.h.

Referenced by Execute(), Start(), and TF_TestThread().

◆ m_ThreadExitMutex

pthread_mutex_t TF_TestThread::m_ThreadExitMutex

Definition at line 64 of file tf_testthread.h.

Referenced by Execute(), TF_TestThread(), and ~TF_TestThread().


The documentation for this class was generated from the following files: