Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
lib
util
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
12
ThreadedObject::ThreadedObject
() :
13
m_isPausing(false), m_isRunning(false), m_thread(NULL)
14
{
15
m_sem
= SDL_CreateSemaphore(0);
16
}
17
18
ThreadedObject::~ThreadedObject
()
19
{
20
SDL_DestroySemaphore(
m_sem
);
21
}
22
23
void
ThreadedObject::pause
(){
24
m_isPausing
=
true
;
25
}
26
27
void
ThreadedObject::resume
(){
28
m_isPausing
=
false
;
29
SDL_SemPost(
m_sem
);
30
}
31
32
bool
ThreadedObject::isPausing
(){
33
return
m_isPausing
;
34
}
35
36
bool
ThreadedObject::isRunning
(){
37
return
m_isRunning
;
38
}
39
40
bool
ThreadedObject::oneStep
(){
41
if
(
m_isPausing
){
42
SDL_SemWait(
m_sem
);
43
}
44
return
true
;
45
}
46
47
void
ThreadedObject::start
()
48
{
49
if
(
m_thread
)
return
;
50
m_isRunning
=
true
;
51
m_thread
= SDL_CreateThread(
threadMain
, (
void
*)
this
);
52
}
53
54
void
ThreadedObject::stop
()
55
{
56
if
(
m_isPausing
)
resume
();
57
m_isRunning
=
false
;
58
wait
();
59
}
60
61
void
ThreadedObject::wait
()
62
{
63
SDL_WaitThread(
m_thread
, NULL);
64
m_thread
= NULL;
65
}
66
67
void
ThreadedObject::notifyFinish
()
68
{
69
m_isRunning
=
false
;
70
}
ThreadedObject::m_isPausing
bool m_isPausing
Definition:
ThreadedObject.h:21
ThreadedObject
Definition:
ThreadedObject.h:6
ThreadedObject::notifyFinish
void notifyFinish()
Definition:
ThreadedObject.cpp:67
ThreadedObject::pause
void pause()
Definition:
ThreadedObject.cpp:23
ThreadedObject::resume
void resume()
Definition:
ThreadedObject.cpp:27
ThreadedObject::oneStep
virtual bool oneStep()
Definition:
ThreadedObject.cpp:40
ThreadedObject::m_isRunning
bool m_isRunning
Definition:
ThreadedObject.h:21
ThreadedObject::m_sem
SDL_sem * m_sem
Definition:
ThreadedObject.h:23
ThreadedObject::isPausing
bool isPausing()
Definition:
ThreadedObject.cpp:32
ThreadedObject.h
ThreadedObject::isRunning
bool isRunning()
Definition:
ThreadedObject.cpp:36
threadMain
static int threadMain(void *arg)
Definition:
ThreadedObject.cpp:3
ThreadedObject::stop
void stop()
Definition:
ThreadedObject.cpp:54
ThreadedObject::ThreadedObject
ThreadedObject()
Definition:
ThreadedObject.cpp:12
ThreadedObject::m_thread
SDL_Thread * m_thread
Definition:
ThreadedObject.h:22
ThreadedObject::start
void start()
Definition:
ThreadedObject.cpp:47
ThreadedObject::wait
void wait()
Definition:
ThreadedObject.cpp:61
ThreadedObject::~ThreadedObject
~ThreadedObject()
Definition:
ThreadedObject.cpp:18
hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51