@@ -310,24 +310,16 @@ class RID_Alloc : public RID_AllocBase {
310310 }
311311
312312 _FORCE_INLINE_ bool owns (const RID &p_rid) const {
313- if (p_rid == RID ()) {
314- return false ;
315- }
316-
317313 if constexpr (THREAD_SAFE ) {
318- SYNC_ACQUIRE ;
314+ mutex. lock () ;
319315 }
320316
321317 uint64_t id = p_rid.get_id ();
322318 uint32_t idx = uint32_t (id & 0xFFFFFFFF );
323- uint32_t ma;
324- if constexpr (THREAD_SAFE ) {
325- ma = ((std::atomic<uint32_t > *)&max_alloc)->load (std::memory_order_relaxed);
326- } else {
327- ma = max_alloc;
328- }
329-
330- if (unlikely (idx >= ma)) {
319+ if (unlikely (idx >= max_alloc)) {
320+ if constexpr (THREAD_SAFE ) {
321+ mutex.unlock ();
322+ }
331323 return false ;
332324 }
333325
@@ -336,29 +328,10 @@ class RID_Alloc : public RID_AllocBase {
336328
337329 uint32_t validator = uint32_t (id >> 32 );
338330
339- if constexpr (THREAD_SAFE ) {
340- #ifdef TSAN_ENABLED
341- __tsan_acquire (&chunks[idx_chunk]); // We know not a race in practice.
342- __tsan_acquire (&chunks[idx_chunk][idx_element]); // We know not a race in practice.
343- #endif
344- }
345-
346- Chunk &c = chunks[idx_chunk][idx_element];
331+ bool owned = (chunks[idx_chunk][idx_element].validator & 0x7FFFFFFF ) == validator;
347332
348333 if constexpr (THREAD_SAFE ) {
349- #ifdef TSAN_ENABLED
350- __tsan_release (&chunks[idx_chunk]);
351- __tsan_release (&chunks[idx_chunk][idx_element]);
352- __tsan_acquire (&c.validator ); // We know not a race in practice.
353- #endif
354- }
355-
356- bool owned = (c.validator & 0x7FFFFFFF ) == validator;
357-
358- if constexpr (THREAD_SAFE ) {
359- #ifdef TSAN_ENABLED
360- __tsan_release (&c.validator );
361- #endif
334+ mutex.unlock ();
362335 }
363336
364337 return owned;
0 commit comments