ThreadedObject.cpp
Go to the documentation of this file.
1 #include "ThreadedObject.h"
2 
3 static int threadMain(void *arg)
4 {
5  ThreadedObject *throbj = (ThreadedObject *)arg;
6  while(throbj->isRunning()){
7  if (!throbj->oneStep()) break;
8  }
9  throbj->notifyFinish();
10 }
11 
13  m_isPausing(false), m_isRunning(false), m_thread(NULL)
14 {
15  m_sem = SDL_CreateSemaphore(0);
16 }
17 
19 {
20  SDL_DestroySemaphore(m_sem);
21 }
22 
24  m_isPausing = true;
25 }
26 
28  m_isPausing = false;
29  SDL_SemPost(m_sem);
30 }
31 
33  return m_isPausing;
34 }
35 
37  return m_isRunning;
38 }
39 
41  if (m_isPausing){
42  SDL_SemWait(m_sem);
43  }
44  return true;
45 }
46 
48 {
49  if (m_thread) return;
50  m_isRunning = true;
51  m_thread = SDL_CreateThread(threadMain, (void *)this);
52 }
53 
55 {
56  if (m_isPausing) resume();
57  m_isRunning = false;
58  wait();
59 }
60 
62 {
63  SDL_WaitThread(m_thread, NULL);
64  m_thread = NULL;
65 }
66 
68 {
69  m_isRunning = false;
70 }
virtual bool oneStep()
SDL_sem * m_sem
static int threadMain(void *arg)
SDL_Thread * m_thread


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51