Merge pull request #4562 from lioncash/loop

cpu_manager: Make use of ranged for where applicable
This commit is contained in:
bunnei 2020-08-24 17:58:41 -04:00 committed by GitHub
commit 6fd3a1bf85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 16 deletions

View File

@ -41,9 +41,9 @@ void CpuManager::Shutdown() {
running_mode = false; running_mode = false;
Pause(false); Pause(false);
if (is_multicore) { if (is_multicore) {
for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { for (auto& data : core_data) {
core_data[core].host_thread->join(); data.host_thread->join();
core_data[core].host_thread.reset(); data.host_thread.reset();
} }
} else { } else {
core_data[0].host_thread->join(); core_data[0].host_thread->join();
@ -166,25 +166,23 @@ void CpuManager::MultiCorePause(bool paused) {
bool all_not_barrier = false; bool all_not_barrier = false;
while (!all_not_barrier) { while (!all_not_barrier) {
all_not_barrier = true; all_not_barrier = true;
for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { for (const auto& data : core_data) {
all_not_barrier &= all_not_barrier &= !data.is_running.load() && data.initialized.load();
!core_data[core].is_running.load() && core_data[core].initialized.load();
} }
} }
for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { for (auto& data : core_data) {
core_data[core].enter_barrier->Set(); data.enter_barrier->Set();
} }
if (paused_state.load()) { if (paused_state.load()) {
bool all_barrier = false; bool all_barrier = false;
while (!all_barrier) { while (!all_barrier) {
all_barrier = true; all_barrier = true;
for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { for (const auto& data : core_data) {
all_barrier &= all_barrier &= data.is_paused.load() && data.initialized.load();
core_data[core].is_paused.load() && core_data[core].initialized.load();
} }
} }
for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { for (auto& data : core_data) {
core_data[core].exit_barrier->Set(); data.exit_barrier->Set();
} }
} }
} else { } else {
@ -192,9 +190,8 @@ void CpuManager::MultiCorePause(bool paused) {
bool all_barrier = false; bool all_barrier = false;
while (!all_barrier) { while (!all_barrier) {
all_barrier = true; all_barrier = true;
for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { for (const auto& data : core_data) {
all_barrier &= all_barrier &= data.is_paused.load() && data.initialized.load();
core_data[core].is_paused.load() && core_data[core].initialized.load();
} }
} }
/// Don't release the barrier /// Don't release the barrier