1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-24 15:26:15 +00:00

Use atomic flag to prevent flush_if_pending from reading unlocked command_mem.

This commit is contained in:
Pāvels Nadtočajevs
2025-02-25 23:26:43 +02:00
parent e7ac8e45a3
commit bdb5d522d1

View File

@@ -114,6 +114,7 @@ class CommandQueueMT {
uint32_t sync_awaiters = 0; uint32_t sync_awaiters = 0;
WorkerThreadPool::TaskID pump_task_id = WorkerThreadPool::INVALID_TASK_ID; WorkerThreadPool::TaskID pump_task_id = WorkerThreadPool::INVALID_TASK_ID;
uint64_t flush_read_ptr = 0; uint64_t flush_read_ptr = 0;
std::atomic<bool> pending;
template <typename T, typename... Args> template <typename T, typename... Args>
_FORCE_INLINE_ void create_command(Args &&...p_args) { _FORCE_INLINE_ void create_command(Args &&...p_args) {
@@ -126,6 +127,7 @@ class CommandQueueMT {
*(uint64_t *)&command_mem[size] = alloc_size; *(uint64_t *)&command_mem[size] = alloc_size;
void *cmd = &command_mem[size + sizeof(uint64_t)]; void *cmd = &command_mem[size + sizeof(uint64_t)];
new (cmd) T(std::forward<Args>(p_args)...); new (cmd) T(std::forward<Args>(p_args)...);
pending.store(true);
} }
template <typename T, bool NeedsSync, typename... Args> template <typename T, bool NeedsSync, typename... Args>
@@ -186,6 +188,7 @@ class CommandQueueMT {
} }
command_mem.clear(); command_mem.clear();
pending.store(false);
flush_read_ptr = 0; flush_read_ptr = 0;
_prevent_sync_wraparound(); _prevent_sync_wraparound();
@@ -226,7 +229,7 @@ public:
} }
_FORCE_INLINE_ void flush_if_pending() { _FORCE_INLINE_ void flush_if_pending() {
if (unlikely(command_mem.size() > 0)) { if (unlikely(pending.load())) {
_flush(); _flush();
} }
} }