From fa4b09f63da63cade61c03d72e6844874f996f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Thu, 18 May 2017 13:01:12 +0200 Subject: [PATCH] Make MessageQueue::flush() reentrant --- core/message_queue.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/message_queue.cpp b/core/message_queue.cpp index 821414be07e..ce7708efe6f 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -316,12 +316,19 @@ void MessageQueue::flush() { while (read_pos < buffer_end) { - _THREAD_SAFE_UNLOCK_ - //lock on each interation, so a call can re-add itself to the message queue Message *message = (Message *)&buffer[read_pos]; + uint32_t advance = sizeof(Message); + if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) + advance += sizeof(Variant) * message->args; + + //pre-advance so this function is reentrant + read_pos += advance; + + _THREAD_SAFE_UNLOCK_ + Object *target = ObjectDB::get_instance(message->instance_ID); if (target != NULL) { @@ -357,13 +364,9 @@ void MessageQueue::flush() { } } - uint32_t advance = sizeof(Message); - if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) - advance += sizeof(Variant) * message->args; message->~Message(); _THREAD_SAFE_LOCK_ - read_pos += advance; } buffer_end = 0; // reset buffer