[DEV] add some inspection code in Gale thread
This commit is contained in:
parent
ba27f7f9b8
commit
2b6be85251
@ -13,23 +13,30 @@
|
|||||||
gale::Thread::Thread() :
|
gale::Thread::Thread() :
|
||||||
m_state(state_stop),
|
m_state(state_stop),
|
||||||
m_thread(nullptr) {
|
m_thread(nullptr) {
|
||||||
|
GALE_INFO("Create new Thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
gale::Thread::~Thread() {
|
gale::Thread::~Thread() {
|
||||||
|
GALE_INFO("Remove Thread [START]");
|
||||||
stop();
|
stop();
|
||||||
|
GALE_INFO("Remove Thread [STOP]");
|
||||||
}
|
}
|
||||||
|
|
||||||
void gale::Thread::start() {
|
void gale::Thread::start() {
|
||||||
if (m_state == state_stop) {
|
if (m_state == state_stop) {
|
||||||
|
GALE_DEBUG("Allocate std11::thread [START]");
|
||||||
m_state = state_starting;
|
m_state = state_starting;
|
||||||
m_thread = new std11::thread(&gale::Thread::threadCall, this);
|
m_thread = new std11::thread(&gale::Thread::threadCall, this);
|
||||||
|
GALE_DEBUG("Allocate std11::thread [Set priority]");
|
||||||
// set priority
|
// set priority
|
||||||
|
|
||||||
|
GALE_DEBUG("Allocate std11::thread [Register context]");
|
||||||
// set association with the gale context ...
|
// set association with the gale context ...
|
||||||
gale::contextRegisterThread(m_thread);
|
gale::contextRegisterThread(m_thread);
|
||||||
|
|
||||||
|
GALE_DEBUG("Allocate std11::thread [set State]");
|
||||||
m_state = state_running;
|
m_state = state_running;
|
||||||
|
GALE_DEBUG("Allocate std11::thread [STOP]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,23 +50,31 @@ void gale::Thread::stop() {
|
|||||||
GALE_INFO("wait Thread stopping");
|
GALE_INFO("wait Thread stopping");
|
||||||
usleep(500000);
|
usleep(500000);
|
||||||
}
|
}
|
||||||
|
GALE_DEBUG("stop std11::thread [START]");
|
||||||
m_thread->join();
|
m_thread->join();
|
||||||
gale::contextUnRegisterThread(m_thread);
|
gale::contextUnRegisterThread(m_thread);
|
||||||
|
GALE_DEBUG("stop std11::thread [delete]");
|
||||||
delete m_thread;
|
delete m_thread;
|
||||||
m_thread = nullptr;
|
m_thread = nullptr;
|
||||||
|
GALE_DEBUG("stop std11::thread [set state]");
|
||||||
m_state = state_stop;
|
m_state = state_stop;
|
||||||
|
GALE_DEBUG("stop std11::thread [STOP]");
|
||||||
}
|
}
|
||||||
|
|
||||||
void gale::Thread::threadCall() {
|
void gale::Thread::threadCall() {
|
||||||
|
GALE_DEBUG("THREAD MAIN [START]");
|
||||||
while (m_state != state_stopping) {
|
while (m_state != state_stopping) {
|
||||||
if (m_state == state_starting) {
|
if (m_state == state_starting) {
|
||||||
|
GALE_DEBUG("run std11::thread [NOTHING to do]");
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (onThreadCall() == true) {
|
if (onThreadCall() == true) {
|
||||||
|
GALE_DEBUG("run std11::thread [AUTO STOP]");
|
||||||
m_state = state_stopping;
|
m_state = state_stopping;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
GALE_DEBUG("THREAD MAIN [STOP]");
|
||||||
m_state = state_stopping;
|
m_state = state_stopping;
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,10 @@ namespace gale {
|
|||||||
virtual ~Thread();
|
virtual ~Thread();
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
protected:
|
|
||||||
virtual bool onThreadCall() { return true; };
|
|
||||||
private:
|
private:
|
||||||
void threadCall();
|
void threadCall();
|
||||||
|
protected:
|
||||||
|
virtual bool onThreadCall() { return true; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user