From f9a38d2309043de9e0c763ae72aa81b25c1dfca7 Mon Sep 17 00:00:00 2001 From: m4nu3lf Date: Fri, 13 Oct 2017 18:13:52 +0100 Subject: CommandQueueMT doesn't lock during command execution --- core/command_queue_mt.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'core/command_queue_mt.cpp') diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index 8e2aa24c22..2028a18a06 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -76,6 +76,30 @@ CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() { return &sync_sems[idx]; } +bool CommandQueueMT::dealloc_one() { +tryagain: + if (dealloc_ptr == write_ptr) { + // The queue is empty + return false; + } + + uint32_t size = *(uint32_t *)&command_mem[dealloc_ptr]; + + if (size == 0) { + // End of command buffer wrap down + dealloc_ptr = 0; + goto tryagain; + } + + if (size & 1) { + // Still used, nothing can be deallocated + return false; + } + + dealloc_ptr += (size >> 1) + sizeof(uint32_t); + return true; +} + CommandQueueMT::CommandQueueMT(bool p_sync) { read_ptr = 0; -- cgit v1.2.3