mirror of https://github.com/axmolengine/axmol.git
Merge pull request #15705 from minggo/jsb-debug-issue
lock mutext to get element from g_queue
This commit is contained in:
commit
c8c57696be
|
@ -1757,20 +1757,26 @@ void ScriptingCore::garbageCollect()
|
||||||
|
|
||||||
void SimpleRunLoop::update(float dt)
|
void SimpleRunLoop::update(float dt)
|
||||||
{
|
{
|
||||||
g_qMutex.lock();
|
std::string message;
|
||||||
size_t size = g_queue.size();
|
size_t messageCount = 0;
|
||||||
g_qMutex.unlock();
|
while (true)
|
||||||
|
|
||||||
while (size > 0)
|
|
||||||
{
|
{
|
||||||
g_qMutex.lock();
|
g_qMutex.lock();
|
||||||
|
messageCount = g_queue.size();
|
||||||
|
if (messageCount > 0)
|
||||||
|
{
|
||||||
auto first = g_queue.begin();
|
auto first = g_queue.begin();
|
||||||
std::string str = *first;
|
message = *first;
|
||||||
g_queue.erase(first);
|
g_queue.erase(first);
|
||||||
size = g_queue.size();
|
--messageCount;
|
||||||
|
}
|
||||||
g_qMutex.unlock();
|
g_qMutex.unlock();
|
||||||
|
|
||||||
ScriptingCore::getInstance()->debugProcessInput(str);
|
if (messageCount == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!message.empty())
|
||||||
|
ScriptingCore::getInstance()->debugProcessInput(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1788,20 +1794,26 @@ void ScriptingCore::debugProcessInput(const std::string& str)
|
||||||
|
|
||||||
static bool NS_ProcessNextEvent()
|
static bool NS_ProcessNextEvent()
|
||||||
{
|
{
|
||||||
g_qMutex.lock();
|
std::string message;
|
||||||
size_t size = g_queue.size();
|
size_t messageCount = 0;
|
||||||
g_qMutex.unlock();
|
while (true)
|
||||||
|
|
||||||
while (size > 0)
|
|
||||||
{
|
{
|
||||||
g_qMutex.lock();
|
g_qMutex.lock();
|
||||||
|
messageCount = g_queue.size();
|
||||||
|
if (messageCount > 0)
|
||||||
|
{
|
||||||
auto first = g_queue.begin();
|
auto first = g_queue.begin();
|
||||||
std::string str = *first;
|
message = *first;
|
||||||
g_queue.erase(first);
|
g_queue.erase(first);
|
||||||
size = g_queue.size();
|
--messageCount;
|
||||||
|
}
|
||||||
g_qMutex.unlock();
|
g_qMutex.unlock();
|
||||||
|
|
||||||
ScriptingCore::getInstance()->debugProcessInput(str);
|
if (messageCount == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!message.empty())
|
||||||
|
ScriptingCore::getInstance()->debugProcessInput(message);
|
||||||
}
|
}
|
||||||
// std::this_thread::yield();
|
// std::this_thread::yield();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
|
Loading…
Reference in New Issue