[DEV] set a real periodic call independent of display (fix wayland stop redraw)

This commit is contained in:
Edouard DUPIN 2017-02-03 21:16:01 +01:00
parent 11e7e0f540
commit ae21bbff96
4 changed files with 60 additions and 31 deletions

View File

@ -93,6 +93,10 @@ void gale::Thread::stop() {
void gale::Thread::threadCall() { void gale::Thread::threadCall() {
GALE_DEBUG("THREAD MAIN [START]"); GALE_DEBUG("THREAD MAIN [START]");
if (m_name != "") {
ethread::setName(m_name);
m_lastUpdatateName = echrono::Steady::now();
}
gale::setContext(m_context); gale::setContext(m_context);
while (m_state != state::stopping) { while (m_state != state::stopping) {
if (m_state == state::starting) { if (m_state == state::starting) {
@ -100,6 +104,12 @@ void gale::Thread::threadCall() {
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
continue; continue;
} }
if (m_name != "") {
if ((echrono::Steady::now()-m_lastUpdatateName) > echrono::seconds(10)) {
m_lastUpdatateName = echrono::Steady::now();
ethread::setName(m_name);
}
}
if (onThreadCall() == true) { if (onThreadCall() == true) {
GALE_DEBUG("run std::thread [AUTO STOP]"); GALE_DEBUG("run std::thread [AUTO STOP]");
m_state = state::stopping; m_state = state::stopping;
@ -107,6 +117,7 @@ void gale::Thread::threadCall() {
} }
} }
GALE_DEBUG("THREAD MAIN [STOP]"); GALE_DEBUG("THREAD MAIN [STOP]");
gale::setContext(nullptr);
m_state = state::stopping; m_state = state::stopping;
} }
@ -117,3 +128,7 @@ bool gale::Thread::onThreadCall() {
enum gale::Thread::state gale::Thread::getState() { enum gale::Thread::state gale::Thread::getState() {
return m_state; return m_state;
} }
void gale::Thread::setName(std::string _name) {
m_name = _name;
}

View File

@ -62,6 +62,15 @@ namespace gale {
* @brief Stop the Thread (destroy thread here) * @brief Stop the Thread (destroy thread here)
*/ */
virtual void stop(); virtual void stop();
private:
std::string m_name; //!< thread Name
echrono::Steady m_lastUpdatateName;
public:
/**
* @brief change name of the thread
* @param[in] _name Name of the thread
*/
void setName(std::string m_name);
private: private:
#if defined(__TARGET_OS__Android) #if defined(__TARGET_OS__Android)
static void* threadCallback(void* _userData); static void* threadCallback(void* _userData);

View File

@ -130,22 +130,6 @@ void gale::contextUnRegisterThread(std::thread* _thread) {
g_lockContextMap.unlock(); g_lockContextMap.unlock();
} }
class PeriodicThread : public gale::Thread {
public:
PeriodicThread() {
}
bool onThreadCall() override {
ethread::setName("galeThread 2");
std::this_thread::sleep_for(std::chrono::milliseconds(200));
GALE_INFO("periodicThread");
return false;
}
};
void gale::Context::setInitImage(const std::string& _fileName) { void gale::Context::setInitImage(const std::string& _fileName) {
//m_initDisplayImageName = _fileName; //m_initDisplayImageName = _fileName;
} }
@ -210,6 +194,38 @@ void gale::Context::setArchiveDir(int _mode, const char* _str, const char* _appl
} }
} }
namespace gale {
class PeriodicThread : public gale::Thread {
private:
gale::Context* m_context;
public:
PeriodicThread(gale::Context* _context):
m_context(_context) {
setName("GaleThread 2");
}
bool onThreadCall() override {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
#if 0
m_context->lockContext();
#else
mutexInterface().lock();
#endif
m_context->processEvents();
// call all the application for periodic request (the application manage multiple instance )...
if (m_context->m_application != nullptr) {
m_context->m_application->onPeriod(echrono::Steady::now());
}
#if 0
m_context->unLockContext();
#else
mutexInterface().unlock();
#endif
return false;
}
};
}
gale::Context::Context(gale::Application* _application, int32_t _argc, const char* _argv[]) : gale::Context::Context(gale::Application* _application, int32_t _argc, const char* _argv[]) :
@ -241,7 +257,7 @@ gale::Context::Context(gale::Application* _application, int32_t _argc, const cha
// set the curent interface: // set the curent interface:
lockContext(); lockContext();
// create thread to manage real periodic event // create thread to manage real periodic event
m_periodicThread = ememory::makeShared<PeriodicThread>(); m_periodicThread = ememory::makeShared<PeriodicThread>(this);
m_periodicThread->start(); m_periodicThread->start();
std::this_thread::sleep_for(std::chrono::milliseconds(2000)); std::this_thread::sleep_for(std::chrono::milliseconds(2000));
@ -637,11 +653,7 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
*/ */
processEvents();
// call all the application for periodic request (the application manage multiple instance ...
if (m_application != nullptr) {
m_application->onPeriod(currentTime);
}
if (m_application != nullptr) { if (m_application != nullptr) {
// Redraw all needed elements // Redraw all needed elements
m_application->onRegenerateDisplay(*this); m_application->onRegenerateDisplay(*this);

View File

@ -14,7 +14,6 @@
#include <gale/Application.hpp> #include <gale/Application.hpp>
#include <gale/context/clipBoard.hpp> #include <gale/context/clipBoard.hpp>
#include <gale/context/commandLine.hpp> #include <gale/context/commandLine.hpp>
// TODO : #include <gale/context/InputManager.hpp>
#include <gale/context/Fps.hpp> #include <gale/context/Fps.hpp>
#include <gale/Thread.hpp> #include <gale/Thread.hpp>
#include <ememory/memory.hpp> #include <ememory/memory.hpp>
@ -27,7 +26,9 @@
namespace gale { namespace gale {
class Thread; class Thread;
class PeriodicThread;
class Context { class Context {
friend class gale::PeriodicThread;
protected: protected:
std::recursive_mutex m_mutex; std::recursive_mutex m_mutex;
ememory::SharedPtr<gale::Thread> m_periodicThread; ememory::SharedPtr<gale::Thread> m_periodicThread;
@ -69,7 +70,6 @@ namespace gale {
etk::FSNode m_simulationFile; etk::FSNode m_simulationFile;
private: private:
echrono::Steady m_previousDisplayTime; // this is to limit framerate ... in case... echrono::Steady m_previousDisplayTime; // this is to limit framerate ... in case...
// TODO : gale::context::InputManager m_input;
etk::Fifo<std::function<void(gale::Context& _context)> > m_msgSystem; etk::Fifo<std::function<void(gale::Context& _context)> > m_msgSystem;
bool m_displayFps; bool m_displayFps;
gale::context::Fps m_FpsSystemEvent; gale::context::Fps m_FpsSystemEvent;
@ -262,13 +262,6 @@ namespace gale {
* @param[in] _status "true" to enable decoration / false otherwise * @param[in] _status "true" to enable decoration / false otherwise
*/ */
virtual void setWindowsDecoration(bool _status) {}; virtual void setWindowsDecoration(bool _status) {};
/**
* @brief get the curent time in micro-second
* @note : must be implemented in all system OS implementation
* @return The curent time of the process
*/
// TODO : REMOVE this ... deprecated since c++11
static int64_t getTime();
private: private:
// TODO : set user argument here .... // TODO : set user argument here ....