Skip to content

Commit 6ddb1e6

Browse files
committed
Fix Tera Multi-Farmer reset recovery.
1 parent 164fe16 commit 6ddb1e6

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraMultiFarmer.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ bool TeraMultiFarmer::start_sequence_host(
367367
}
368368
}catch (OperationFailedException&){
369369
stats.m_errors++;
370-
m_reset_required[console.index()] = true;
370+
m_reset_required[console.index()].store(true, std::memory_order_relaxed);
371371
throw;
372372
}
373373

@@ -401,10 +401,10 @@ bool TeraMultiFarmer::start_sequence_host(
401401

402402
if (result == TeraLobbyWaiter::LobbyResult::BANNED_PLAYER){
403403
stats.m_banned++;
404-
m_reset_required[0] = true;
405-
m_reset_required[1] = true;
406-
m_reset_required[2] = true;
407-
m_reset_required[3] = true;
404+
m_reset_required[0].store(true, std::memory_order_relaxed);
405+
m_reset_required[1].store(true, std::memory_order_relaxed);
406+
m_reset_required[2].store(true, std::memory_order_relaxed);
407+
m_reset_required[3].store(true, std::memory_order_relaxed);
408408
}
409409
if (result != TeraLobbyWaiter::LobbyResult::RAID_STARTED){
410410
return false;
@@ -481,7 +481,14 @@ bool TeraMultiFarmer::run_raid(
481481
}catch (OperationCancelledException&){
482482
}catch (OperationFailedException&){
483483
stats.m_errors++;
484-
m_reset_required[console.index()] = true;
484+
#if 0
485+
m_reset_required[console.index()].store(true, std::memory_order_relaxed);
486+
#else
487+
m_reset_required[0].store(true, std::memory_order_relaxed);
488+
m_reset_required[1].store(true, std::memory_order_relaxed);
489+
m_reset_required[2].store(true, std::memory_order_relaxed);
490+
m_reset_required[3].store(true, std::memory_order_relaxed);
491+
#endif
485492
raid_waiter.cancel();
486493
// cout << "OperationFailedException: " << console.index() << endl;
487494
throw;
@@ -508,7 +515,7 @@ bool TeraMultiFarmer::run_raid(
508515
// Host throws. Reset the host and keep going.
509516
stats.m_errors++;
510517
env.update_stats();
511-
m_reset_required[console.index()] = true;
518+
m_reset_required[console.index()].store(true, std::memory_order_relaxed);
512519
throw;
513520
}
514521
});
@@ -531,10 +538,10 @@ void TeraMultiFarmer::program(MultiSwitchProgramEnvironment& env, CancellableSco
531538
std::string report_name = "PokemonSV-AutoHost-JoinReport-" + now_to_filestring() + ".txt";
532539
MultiLanguageJoinTracker join_tracker((uint8_t)env.consoles.size());
533540

534-
m_reset_required[0] = false;
535-
m_reset_required[1] = false;
536-
m_reset_required[2] = false;
537-
m_reset_required[3] = false;
541+
m_reset_required[0].store(false, std::memory_order_relaxed);
542+
m_reset_required[1].store(false, std::memory_order_relaxed);
543+
m_reset_required[2].store(false, std::memory_order_relaxed);
544+
m_reset_required[3].store(false, std::memory_order_relaxed);
538545

539546
if (RECOVERY_MODE == RecoveryMode::SAVE_AND_RESET){
540547
env.run_in_parallel(scope, [&](ConsoleHandle& console, ProControllerContext& context){
@@ -570,15 +577,15 @@ void TeraMultiFarmer::program(MultiSwitchProgramEnvironment& env, CancellableSco
570577
// Reset all errored Switches.
571578
env.run_in_parallel(scope, [&](ConsoleHandle& console, ProControllerContext& context){
572579
size_t index = console.index();
573-
if (!m_reset_required[index]){
580+
if (!m_reset_required[index].load(std::memory_order_relaxed)){
574581
return;
575582
}
576583
if (index == host_index){
577584
reset_host(env.program_info(), console, context);
578585
}else{
579586
reset_joiner(env.program_info(), console, context);
580587
}
581-
m_reset_required[index] = false;
588+
m_reset_required[index].store(false, std::memory_order_relaxed);
582589
});
583590

584591
// Check kill-switch now before we go online.
@@ -614,7 +621,7 @@ void TeraMultiFarmer::program(MultiSwitchProgramEnvironment& env, CancellableSco
614621
// Iterate the errored Switches. If a non-host has errored,
615622
// rethrow the exception to stop the program.
616623
for (size_t c = 0; c < 4; c++){
617-
if (m_reset_required[c] && c != host_index){
624+
if (m_reset_required[c].load(std::memory_order_relaxed) && c != host_index){
618625
throw;
619626
}
620627
}

SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraMultiFarmer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class TeraMultiFarmer : public MultiSwitchProgramInstance, private ConfigOption:
149149

150150
WallClock m_last_time_fix;
151151
// std::atomic<bool> m_raid_error;
152-
bool m_reset_required[4];
152+
std::atomic<bool> m_reset_required[4];
153153
};
154154

155155

0 commit comments

Comments
 (0)