From 7ca6cbd8d69b3f1461db3bba5dd6fbffbff3e852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 5 Aug 2019 14:18:13 +0200 Subject: [PATCH] RID_Alloc: Fix locking in getornull and free early returns Those missing unlocks were preventing the editor from starting. --- core/rid_owner.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/core/rid_owner.h b/core/rid_owner.h index 3c2e61f6770..26807e9a5e5 100644 --- a/core/rid_owner.h +++ b/core/rid_owner.h @@ -109,6 +109,9 @@ public: uint64_t id = p_rid.get_id(); uint32_t idx = uint32_t(id & 0xFFFFFFFF); if (unlikely(idx >= max_alloc)) { + if (THREAD_SAFE) { + spin_lock.unlock(); + } return NULL; } @@ -116,7 +119,10 @@ public: uint32_t idx_element = idx % elements_in_chunk; uint32_t validator = uint32_t(id >> 32); - if (validator_chunks[idx_chunk][idx_element] != validator) { + if (unlikely(validator_chunks[idx_chunk][idx_element] != validator)) { + if (THREAD_SAFE) { + spin_lock.unlock(); + } return NULL; } @@ -166,13 +172,23 @@ public: uint64_t id = p_rid.get_id(); uint32_t idx = uint32_t(id & 0xFFFFFFFF); - ERR_FAIL_COND(idx >= max_alloc); + if (unlikely(idx >= max_alloc)) { + if (THREAD_SAFE) { + spin_lock.unlock(); + } + ERR_FAIL(); + } uint32_t idx_chunk = idx / elements_in_chunk; uint32_t idx_element = idx % elements_in_chunk; uint32_t validator = uint32_t(id >> 32); - ERR_FAIL_COND(validator_chunks[idx_chunk][idx_element] != validator); + if (unlikely(validator_chunks[idx_chunk][idx_element] != validator)) { + if (THREAD_SAFE) { + spin_lock.unlock(); + } + ERR_FAIL(); + } chunks[idx_chunk][idx_element].~T(); validator_chunks[idx_chunk][idx_element] = 0xFFFFFFFF; // go invalid