Skip to content

Commit f374ead

Browse files
authored
Fix load order guarantees (#6883)
1 parent 3e77e13 commit f374ead

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

code/object/objcollide.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,10 @@ void post_process_threaded_collisions() {
795795
for(auto& [i, processed] : workerThreads) {
796796
auto& thread = collision_thread_data_buffer[i];
797797

798-
if (thread.result_length.load(std::memory_order_acquire) > processed) {
798+
size_t queue_length = thread.queue_length.load(std::memory_order_acquire);
799+
size_t result_length = thread.result_length.load(std::memory_order_acquire);
800+
801+
if (result_length > processed) {
799802
{
800803
std::scoped_lock lock(thread.result_mutex);
801804
thread.queue_results.swap(thread.queue_send);
@@ -816,7 +819,7 @@ void post_process_threaded_collisions() {
816819
processed += thread.queue_send->size();
817820
thread.queue_send->clear();
818821
}
819-
else if (thread.queue_length.load(std::memory_order_acquire) == 0) {
822+
else if (queue_length == 0) {
820823
thread.queue_results->clear();
821824
workerThreads.erase(i);
822825
break;

0 commit comments

Comments
 (0)