From 48e8da4aac6c2f6c56f38e2778329178b27666e7 Mon Sep 17 00:00:00 2001 From: Lyuma Date: Thu, 24 Sep 2020 09:03:19 -0700 Subject: core/command_queue_mt: Customizable size and tests Adds unit tests for command_queue_mt.h/cpp In this revision, some unit tests will fail due to issue #42107. --- core/command_queue_mt.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'core/command_queue_mt.cpp') diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index ace210ca2c..95fcd2c70e 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -31,6 +31,7 @@ #include "command_queue_mt.h" #include "core/os/os.h" +#include "core/project_settings.h" void CommandQueueMT::lock() { mutex.lock(); @@ -94,6 +95,10 @@ tryagain: } CommandQueueMT::CommandQueueMT(bool p_sync) { + command_mem_size = GLOBAL_DEF_RST("memory/limits/command_queue/multithreading_queue_size_kb", DEFAULT_COMMAND_MEM_SIZE_KB); + ProjectSettings::get_singleton()->set_custom_property_info("memory/limits/command_queue/multithreading_queue_size_kb", PropertyInfo(Variant::INT, "memory/limits/command_queue/multithreading_queue_size_kb", PROPERTY_HINT_RANGE, "1,4096,1,or_greater")); + command_mem_size *= 1024; + command_mem = (uint8_t *)memalloc(command_mem_size); if (p_sync) { sync = memnew(Semaphore); } -- cgit v1.2.3 From 9f654b441fffa613568e30a4c53a57390be69e12 Mon Sep 17 00:00:00 2001 From: Lyuma Date: Thu, 24 Sep 2020 09:55:38 -0700 Subject: core/command_queue_mt: Fix crash/hang when buffer fills up This patch fixes two related issues. One is the race condition in issue #42107.. The other is a crash which happens when the reader is lapped near the end of the buffer. --- core/command_queue_mt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/command_queue_mt.cpp') diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index 95fcd2c70e..a55eed5d3c 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -72,7 +72,7 @@ CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() { bool CommandQueueMT::dealloc_one() { tryagain: - if (dealloc_ptr == write_ptr) { + if (dealloc_ptr == (write_ptr_and_epoch >> 1)) { // The queue is empty return false; } -- cgit v1.2.3