summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2017-05-18 13:01:12 +0200
committerPedro J. Estébanez <pedrojrulez@gmail.com>2017-05-18 13:02:49 +0200
commit983fd3a7bbb6ac0e02ffcca78d60053ec8847aee (patch)
treec939fe8ae642d52a26779f92fead90ccf5eca292
parent9fa4f1c54c6d528192e7ed04354d5ce2c733d99a (diff)
Make MessageQueue::flush() reentrant
-rw-r--r--core/message_queue.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/core/message_queue.cpp b/core/message_queue.cpp
index fa1c8112cc..d7d31b6c1e 100644
--- a/core/message_queue.cpp
+++ b/core/message_queue.cpp
@@ -318,12 +318,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) {
@@ -359,13 +366,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