[DEBUG] Android multithread pb correction
This commit is contained in:
parent
31dff9e69d
commit
46bd1eac16
@ -10,10 +10,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <gale/context/Context.h>
|
#include <gale/context/Context.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(__TARGET_OS__Android)
|
#if defined(__TARGET_OS__Android)
|
||||||
static void* threadCallback(void* _userData) {
|
void* gale::Thread::threadCallback(void* _userData) {
|
||||||
gale::Thread* threadHandle = static_cast<gale::Thread*>(_userData);
|
gale::Thread* threadHandle = static_cast<gale::Thread*>(_userData);
|
||||||
if (threadHandle != nullptr) {
|
if (threadHandle != nullptr) {
|
||||||
threadHandle->threadCall();
|
threadHandle->threadCall();
|
||||||
@ -44,9 +42,9 @@ void gale::Thread::start() {
|
|||||||
m_state = state_starting;
|
m_state = state_starting;
|
||||||
m_context = &gale::getContext();
|
m_context = &gale::getContext();
|
||||||
#if defined(__TARGET_OS__Android)
|
#if defined(__TARGET_OS__Android)
|
||||||
pthread_create(&m_thread, nullptr, &threadCallback, this);
|
pthread_create(&m_thread, nullptr, &gale::Thread::threadCallback, this);
|
||||||
#else
|
#else
|
||||||
m_thread = new std11::thread(&gale::Thread::threadCall, this);//, &gale::getContext());
|
m_thread = std11::make_shared<std11::thread>(&gale::Thread::threadCall, this);
|
||||||
if (m_thread == nullptr) {
|
if (m_thread == nullptr) {
|
||||||
GALE_ERROR("Can not create thread ...");
|
GALE_ERROR("Can not create thread ...");
|
||||||
return;
|
return;
|
||||||
@ -78,7 +76,8 @@ void gale::Thread::stop() {
|
|||||||
}
|
}
|
||||||
GALE_DEBUG("stop std11::thread [START]");
|
GALE_DEBUG("stop std11::thread [START]");
|
||||||
#if defined(__TARGET_OS__Android)
|
#if defined(__TARGET_OS__Android)
|
||||||
//m_thread.join();
|
void* ret = nullptr;
|
||||||
|
int val = pthread_join(m_thread, &ret);
|
||||||
#else
|
#else
|
||||||
m_thread->join();
|
m_thread->join();
|
||||||
#endif
|
#endif
|
||||||
@ -87,8 +86,7 @@ void gale::Thread::stop() {
|
|||||||
#if defined(__TARGET_OS__Android)
|
#if defined(__TARGET_OS__Android)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
delete m_thread;
|
m_thread.reset();
|
||||||
m_thread = nullptr;
|
|
||||||
#endif
|
#endif
|
||||||
GALE_DEBUG("stop std11::thread [set state]");
|
GALE_DEBUG("stop std11::thread [set state]");
|
||||||
m_state = state_stop;
|
m_state = state_stop;
|
||||||
|
@ -36,7 +36,7 @@ namespace gale {
|
|||||||
#if defined(__TARGET_OS__Android)
|
#if defined(__TARGET_OS__Android)
|
||||||
pthread_t m_thread;
|
pthread_t m_thread;
|
||||||
#else
|
#else
|
||||||
std11::thread* m_thread;
|
std11::shared_ptr<std11::thread> m_thread;
|
||||||
#endif
|
#endif
|
||||||
gale::Context* m_context;
|
gale::Context* m_context;
|
||||||
public:
|
public:
|
||||||
@ -50,7 +50,10 @@ namespace gale {
|
|||||||
virtual ~Thread();
|
virtual ~Thread();
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
public:
|
private:
|
||||||
|
#if defined(__TARGET_OS__Android)
|
||||||
|
static void* threadCallback(void* _userData);
|
||||||
|
#endif
|
||||||
void threadCall();
|
void threadCall();
|
||||||
protected:
|
protected:
|
||||||
virtual bool onThreadCall() { return true; };
|
virtual bool onThreadCall() { return true; };
|
||||||
|
@ -435,32 +435,32 @@ class AndroidContext : public gale::Context {
|
|||||||
enum gale::key::status _status,
|
enum gale::key::status _status,
|
||||||
int32_t _pointerID,
|
int32_t _pointerID,
|
||||||
const vec2& _pos) {
|
const vec2& _pos) {
|
||||||
GALE_DEBUG("OS_SetInput [BEGIN]");
|
GALE_VERBOSE("OS_SetInput [BEGIN]");
|
||||||
gale::Context::OS_SetInput(_type, _status, _pointerID, vec2(_pos.x(),m_currentHeight-_pos.y()));
|
gale::Context::OS_SetInput(_type, _status, _pointerID, vec2(_pos.x(),m_currentHeight-_pos.y()));
|
||||||
GALE_DEBUG("OS_SetInput [END]");
|
GALE_VERBOSE("OS_SetInput [END]");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANDROID_SetKeyboard(char32_t _myChar, bool _isDown, bool _isARepeateKey=false) {
|
void ANDROID_SetKeyboard(char32_t _myChar, bool _isDown, bool _isARepeateKey=false) {
|
||||||
GALE_DEBUG("ANDROID_SetKeyboard [BEGIN]");
|
GALE_VERBOSE("ANDROID_SetKeyboard [BEGIN]");
|
||||||
OS_setKeyboard(m_guiKeyBoardSpecialKeyMode,
|
OS_setKeyboard(m_guiKeyBoardSpecialKeyMode,
|
||||||
gale::key::keyboard_char,
|
gale::key::keyboard_char,
|
||||||
(_isDown==true?gale::key::status_down:gale::key::status_up),
|
(_isDown==true?gale::key::status_down:gale::key::status_up),
|
||||||
_isARepeateKey,
|
_isARepeateKey,
|
||||||
_myChar);
|
_myChar);
|
||||||
GALE_DEBUG("ANDROID_SetKeyboard [END]");
|
GALE_VERBOSE("ANDROID_SetKeyboard [END]");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ANDROID_systemKeyboradEvent(enum gale::key::keyboard _key, bool _isDown) {
|
bool ANDROID_systemKeyboradEvent(enum gale::key::keyboard _key, bool _isDown) {
|
||||||
GALE_DEBUG("ANDROID_systemKeyboradEvent [BEGIN]");
|
GALE_VERBOSE("ANDROID_systemKeyboradEvent [BEGIN]");
|
||||||
OS_setKeyboard(m_guiKeyBoardSpecialKeyMode,
|
OS_setKeyboard(m_guiKeyBoardSpecialKeyMode,
|
||||||
_key,
|
_key,
|
||||||
(_isDown==true?gale::key::status_down:gale::key::status_up));
|
(_isDown==true?gale::key::status_down:gale::key::status_up));
|
||||||
GALE_DEBUG("ANDROID_systemKeyboradEvent [END]");
|
GALE_VERBOSE("ANDROID_systemKeyboradEvent [END]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANDROID_SetKeyboardMove(int _move, bool _isDown, bool _isARepeateKey=false) {
|
void ANDROID_SetKeyboardMove(int _move, bool _isDown, bool _isARepeateKey=false) {
|
||||||
GALE_DEBUG("ANDROID_SetKeyboardMove [BEGIN]");
|
GALE_VERBOSE("ANDROID_SetKeyboardMove [BEGIN]");
|
||||||
// direct wrapping :
|
// direct wrapping :
|
||||||
enum gale::key::keyboard move = (enum gale::key::keyboard)_move;
|
enum gale::key::keyboard move = (enum gale::key::keyboard)_move;
|
||||||
m_guiKeyBoardSpecialKeyMode.update(move, _isDown);
|
m_guiKeyBoardSpecialKeyMode.update(move, _isDown);
|
||||||
@ -468,14 +468,14 @@ class AndroidContext : public gale::Context {
|
|||||||
move,
|
move,
|
||||||
(_isDown==true?gale::key::status_down:gale::key::status_up),
|
(_isDown==true?gale::key::status_down:gale::key::status_up),
|
||||||
_isARepeateKey);
|
_isARepeateKey);
|
||||||
GALE_DEBUG("ANDROID_SetKeyboardMove [END]");
|
GALE_VERBOSE("ANDROID_SetKeyboardMove [END]");
|
||||||
}
|
}
|
||||||
|
|
||||||
void OS_Resize(const vec2& _size) {
|
void OS_Resize(const vec2& _size) {
|
||||||
GALE_DEBUG("OS_Resize [BEGIN]");
|
GALE_VERBOSE("OS_Resize [BEGIN]");
|
||||||
m_currentHeight = _size.y();
|
m_currentHeight = _size.y();
|
||||||
gale::Context::OS_Resize(_size);
|
gale::Context::OS_Resize(_size);
|
||||||
GALE_DEBUG("OS_Resize [END]");
|
GALE_VERBOSE("OS_Resize [END]");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -888,7 +888,7 @@ extern "C" {
|
|||||||
jobject _thiz,
|
jobject _thiz,
|
||||||
jint _id) {
|
jint _id) {
|
||||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||||
GALE_DEBUG("Java_org_gale_Gale_EWrenderInit [BEGIN]");
|
GALE_VERBOSE("Java_org_gale_Gale_EWrenderInit [BEGIN]");
|
||||||
if( _id >= (int32_t)s_listInstance.size()
|
if( _id >= (int32_t)s_listInstance.size()
|
||||||
|| _id<0
|
|| _id<0
|
||||||
|| nullptr == s_listInstance[_id] ) {
|
|| nullptr == s_listInstance[_id] ) {
|
||||||
@ -896,7 +896,7 @@ extern "C" {
|
|||||||
// TODO : generate error in java to stop the current instance
|
// TODO : generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GALE_DEBUG("Java_org_gale_Gale_EWrenderInit [END]");
|
GALE_VERBOSE("Java_org_gale_Gale_EWrenderInit [END]");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_gale_Gale_EWrenderResize(JNIEnv* _env,
|
void Java_org_gale_Gale_EWrenderResize(JNIEnv* _env,
|
||||||
@ -905,7 +905,7 @@ extern "C" {
|
|||||||
jint _w,
|
jint _w,
|
||||||
jint _h) {
|
jint _h) {
|
||||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||||
GALE_DEBUG("Java_org_gale_Gale_EWrenderResize [BEGIN]");
|
GALE_VERBOSE("Java_org_gale_Gale_EWrenderResize [BEGIN]");
|
||||||
if( _id >= (int32_t)s_listInstance.size()
|
if( _id >= (int32_t)s_listInstance.size()
|
||||||
|| _id<0
|
|| _id<0
|
||||||
|| nullptr == s_listInstance[_id] ) {
|
|| nullptr == s_listInstance[_id] ) {
|
||||||
@ -914,7 +914,7 @@ extern "C" {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s_listInstance[_id]->OS_Resize(vec2(_w, _h));
|
s_listInstance[_id]->OS_Resize(vec2(_w, _h));
|
||||||
GALE_DEBUG("Java_org_gale_Gale_EWrenderResize [END]");
|
GALE_VERBOSE("Java_org_gale_Gale_EWrenderResize [END]");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Return true or false to not redraw when the under draw has not be done (processing gain of time)
|
// TODO : Return true or false to not redraw when the under draw has not be done (processing gain of time)
|
||||||
@ -922,7 +922,7 @@ extern "C" {
|
|||||||
jobject _thiz,
|
jobject _thiz,
|
||||||
jint _id) {
|
jint _id) {
|
||||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||||
GALE_DEBUG("Java_org_gale_Gale_EWrenderDraw [BEGIN]");
|
GALE_VERBOSE("Java_org_gale_Gale_EWrenderDraw [BEGIN]");
|
||||||
if( _id >= (int32_t)s_listInstance.size()
|
if( _id >= (int32_t)s_listInstance.size()
|
||||||
|| _id<0
|
|| _id<0
|
||||||
|| nullptr == s_listInstance[_id] ) {
|
|| nullptr == s_listInstance[_id] ) {
|
||||||
@ -931,7 +931,7 @@ extern "C" {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s_listInstance[_id]->OS_Draw(true);
|
s_listInstance[_id]->OS_Draw(true);
|
||||||
GALE_DEBUG("Java_org_gale_Gale_EWrenderDraw [END]");
|
GALE_VERBOSE("Java_org_gale_Gale_EWrenderDraw [END]");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ gale::Context& gale::getContext() {
|
|||||||
|
|
||||||
void gale::setContext(gale::Context* _context) {
|
void gale::setContext(gale::Context* _context) {
|
||||||
std::map<std11::thread::id, gale::Context*>& list = getContextList();
|
std::map<std11::thread::id, gale::Context*>& list = getContextList();
|
||||||
GALE_ERROR("Set context : " << std11::this_thread::get_id() << " context pointer : " << uint64_t(_context));
|
//GALE_ERROR("Set context : " << std11::this_thread::get_id() << " context pointer : " << uint64_t(_context));
|
||||||
g_lockContextMap.lock();
|
g_lockContextMap.lock();
|
||||||
std::map<std11::thread::id, gale::Context*>::iterator it = list.find(std11::this_thread::get_id());
|
std::map<std11::thread::id, gale::Context*>::iterator it = list.find(std11::this_thread::get_id());
|
||||||
if (it == list.end()) {
|
if (it == list.end()) {
|
||||||
@ -82,7 +82,7 @@ void gale::contextRegisterThread(std11::thread* _thread) {
|
|||||||
}
|
}
|
||||||
gale::Context* context = &gale::getContext();
|
gale::Context* context = &gale::getContext();
|
||||||
std::map<std11::thread::id, gale::Context*>& list = getContextList();
|
std::map<std11::thread::id, gale::Context*>& list = getContextList();
|
||||||
GALE_ERROR("REGISTER Thread : " << _thread->get_id() << " context pointer : " << uint64_t(context));
|
//GALE_ERROR("REGISTER Thread : " << _thread->get_id() << " context pointer : " << uint64_t(context));
|
||||||
g_lockContextMap.lock();
|
g_lockContextMap.lock();
|
||||||
std::map<std11::thread::id, gale::Context*>::iterator it = list.find(_thread->get_id());
|
std::map<std11::thread::id, gale::Context*>::iterator it = list.find(_thread->get_id());
|
||||||
if (it == list.end()) {
|
if (it == list.end()) {
|
||||||
@ -506,7 +506,6 @@ void gale::Context::clipBoardSet(enum gale::context::clipBoard::clipboardListe _
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
||||||
GALE_INFO("plop 10");
|
|
||||||
gale::openGL::threadHasContext();
|
gale::openGL::threadHasContext();
|
||||||
int64_t currentTime = gale::getTime();
|
int64_t currentTime = gale::getTime();
|
||||||
// this is to prevent the multiple display at the a high frequency ...
|
// this is to prevent the multiple display at the a high frequency ...
|
||||||
@ -518,13 +517,11 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
m_previousDisplayTime = currentTime;
|
m_previousDisplayTime = currentTime;
|
||||||
GALE_INFO("plop 20");
|
|
||||||
|
|
||||||
// process the events
|
// process the events
|
||||||
if (m_displayFps == true) {
|
if (m_displayFps == true) {
|
||||||
m_FpsSystemEvent.tic();
|
m_FpsSystemEvent.tic();
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 30");
|
|
||||||
bool needRedraw = false;
|
bool needRedraw = false;
|
||||||
//! Event management section ...
|
//! Event management section ...
|
||||||
{
|
{
|
||||||
@ -547,7 +544,6 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
|||||||
// release the curent interface :
|
// release the curent interface :
|
||||||
unLockContext();
|
unLockContext();
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 40");
|
|
||||||
bool hasDisplayDone = false;
|
bool hasDisplayDone = false;
|
||||||
//! drawing section:
|
//! drawing section:
|
||||||
{
|
{
|
||||||
@ -556,7 +552,6 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
|||||||
if (m_displayFps == true) {
|
if (m_displayFps == true) {
|
||||||
m_FpsSystemContext.tic();
|
m_FpsSystemContext.tic();
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 41");
|
|
||||||
if( needRedraw == true
|
if( needRedraw == true
|
||||||
|| _displayEveryTime == true) {
|
|| _displayEveryTime == true) {
|
||||||
lockContext();
|
lockContext();
|
||||||
@ -566,12 +561,10 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
|||||||
m_FpsSystemContext.incrementCounter();
|
m_FpsSystemContext.incrementCounter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 42");
|
|
||||||
if (m_displayFps == true) {
|
if (m_displayFps == true) {
|
||||||
m_FpsSystemContext.toc();
|
m_FpsSystemContext.toc();
|
||||||
m_FpsSystem.tic();
|
m_FpsSystem.tic();
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 43");
|
|
||||||
if (m_application != nullptr) {
|
if (m_application != nullptr) {
|
||||||
if( true == needRedraw
|
if( true == needRedraw
|
||||||
|| true == _displayEveryTime) {
|
|| true == _displayEveryTime) {
|
||||||
@ -583,35 +576,28 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
|||||||
hasDisplayDone = true;
|
hasDisplayDone = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 44");
|
|
||||||
if (m_displayFps == true) {
|
if (m_displayFps == true) {
|
||||||
m_FpsSystem.toc();
|
m_FpsSystem.toc();
|
||||||
m_FpsFlush.tic();
|
m_FpsFlush.tic();
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 45");
|
|
||||||
if (hasDisplayDone == true) {
|
if (hasDisplayDone == true) {
|
||||||
if (m_displayFps == true) {
|
if (m_displayFps == true) {
|
||||||
m_FpsFlush.incrementCounter();
|
m_FpsFlush.incrementCounter();
|
||||||
}
|
}
|
||||||
gale::openGL::flush();
|
gale::openGL::flush();
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 46");
|
|
||||||
if (m_displayFps == true) {
|
if (m_displayFps == true) {
|
||||||
m_FpsFlush.toc();
|
m_FpsFlush.toc();
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 47");
|
|
||||||
// release open GL Context
|
// release open GL Context
|
||||||
gale::openGL::unLock();
|
gale::openGL::unLock();
|
||||||
GALE_INFO("plop 48");
|
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 50");
|
|
||||||
if (m_displayFps == true) {
|
if (m_displayFps == true) {
|
||||||
m_FpsSystemEvent.draw();
|
m_FpsSystemEvent.draw();
|
||||||
m_FpsSystemContext.draw();
|
m_FpsSystemContext.draw();
|
||||||
m_FpsSystem.draw();
|
m_FpsSystem.draw();
|
||||||
m_FpsFlush.draw();
|
m_FpsFlush.draw();
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 60");
|
|
||||||
{
|
{
|
||||||
// set the curent interface :
|
// set the curent interface :
|
||||||
lockContext();
|
lockContext();
|
||||||
@ -626,9 +612,7 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
|||||||
// release the curent interface :
|
// release the curent interface :
|
||||||
unLockContext();
|
unLockContext();
|
||||||
}
|
}
|
||||||
GALE_INFO("plop 70");
|
|
||||||
gale::openGL::threadHasNoMoreContext();
|
gale::openGL::threadHasNoMoreContext();
|
||||||
GALE_INFO("plop 80");
|
|
||||||
return hasDisplayDone;
|
return hasDisplayDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user