|
55 | 55 | #endif |
56 | 56 |
|
57 | 57 | // The following macros would need to be implemented somehow |
58 | | -// for purely weakly ordered architectures. There's a test case |
| 58 | +// for weakly ordered architectures. There's a test case |
59 | 59 | // ("[RID_Owner] Thread safety") with potential to catch issues |
60 | 60 | // on such architectures if these primitives fail to be implemented. |
61 | 61 | // For now, they will be just markers about needs that may arise. |
| 62 | +#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) // MSVC, x86. |
62 | 63 | #define WEAK_MEMORY_ORDER 0 |
| 64 | +#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__)) // GCC/Clang, x86. |
| 65 | +#define WEAK_MEMORY_ORDER 0 |
| 66 | +#else |
| 67 | +#define WEAK_MEMORY_ORDER 1 |
| 68 | +#endif |
63 | 69 | #if WEAK_MEMORY_ORDER |
64 | 70 | // Ideally, we'd have implementations that collaborate with the |
65 | 71 | // sync mechanism used (e.g., the mutex) so instead of some full |
@@ -119,6 +125,7 @@ class RID_Alloc : public RID_AllocBase { |
119 | 125 | _FORCE_INLINE_ RID _allocate_rid() { |
120 | 126 | if constexpr (THREAD_SAFE) { |
121 | 127 | mutex.lock(); |
| 128 | + SYNC_ACQUIRE; |
122 | 129 | } |
123 | 130 |
|
124 | 131 | if (alloc_count == max_alloc) { |
@@ -175,6 +182,7 @@ class RID_Alloc : public RID_AllocBase { |
175 | 182 | alloc_count++; |
176 | 183 |
|
177 | 184 | if constexpr (THREAD_SAFE) { |
| 185 | + SYNC_RELEASE; |
178 | 186 | mutex.unlock(); |
179 | 187 | } |
180 | 188 |
|
@@ -367,6 +375,7 @@ class RID_Alloc : public RID_AllocBase { |
367 | 375 | _FORCE_INLINE_ void free(const RID &p_rid) { |
368 | 376 | if constexpr (THREAD_SAFE) { |
369 | 377 | mutex.lock(); |
| 378 | + SYNC_ACQUIRE; |
370 | 379 | } |
371 | 380 |
|
372 | 381 | uint64_t id = p_rid.get_id(); |
@@ -401,6 +410,7 @@ class RID_Alloc : public RID_AllocBase { |
401 | 410 | free_list_chunks[alloc_count / elements_in_chunk][alloc_count % elements_in_chunk] = idx; |
402 | 411 |
|
403 | 412 | if constexpr (THREAD_SAFE) { |
| 413 | + SYNC_RELEASE; |
404 | 414 | mutex.unlock(); |
405 | 415 | } |
406 | 416 | } |
@@ -429,6 +439,7 @@ class RID_Alloc : public RID_AllocBase { |
429 | 439 | void fill_owned_buffer(RID *p_rid_buffer) const { |
430 | 440 | if constexpr (THREAD_SAFE) { |
431 | 441 | mutex.lock(); |
| 442 | + SYNC_ACQUIRE; |
432 | 443 | } |
433 | 444 | uint32_t idx = 0; |
434 | 445 | for (size_t i = 0; i < max_alloc; i++) { |
|
0 commit comments