@@ -1585,22 +1585,30 @@ extern bool try_lock_spu_threads_in_a_state_compatible_with_savestates(bool reve
15851585
15861586 idm::select<named_thread<spu_thread>>([&](u32 id, spu_thread& spu)
15871587 {
1588- spu_list.emplace_back (ensure (idm::get_unlocked<named_thread<spu_thread>>(id)));
1588+ if (give_up)
1589+ {
1590+ return ;
1591+ }
15891592
1590- if (spu.current_func && spu.unsavable )
1593+ if (spu.current_func && spu.unsavable && !force_collect )
15911594 {
15921595 const u64 start = spu.start_time ;
15931596
1594- // Automatically give up if it is asleep 15 seconds or more
1595- if (start && current > start && current - start >= 15 '000'000 )
1597+ // Automatically give up if it is asleep 5 seconds or more
1598+ if (start && current > start && current - start >= 5 '000'000 )
15961599 {
15971600 give_up = true ;
1601+ return ;
15981602 }
15991603 }
1604+
1605+ spu_list.emplace_back (ensure (idm::get_unlocked<named_thread<spu_thread>>(id)));
16001606 });
16011607
1602- if (!force_collect && give_up)
1608+ if (give_up)
16031609 {
1610+ spu_list.clear ();
1611+ old_counter = umax;
16041612 return decltype (&spu_list){};
16051613 }
16061614
@@ -1625,6 +1633,7 @@ extern bool try_lock_spu_threads_in_a_state_compatible_with_savestates(bool reve
16251633 }
16261634 else if (get_system_time () - start >= 150'000 )
16271635 {
1636+ std::this_thread::sleep_for (1ms);
16281637 passed_count++;
16291638 start = 0 ;
16301639 continue ;
@@ -1636,37 +1645,29 @@ extern bool try_lock_spu_threads_in_a_state_compatible_with_savestates(bool reve
16361645 if (!spu_list)
16371646 {
16381647 // Give up for now
1639- std::this_thread::sleep_for (10ms );
1648+ std::this_thread::sleep_for (50ms );
16401649 passed_count++;
16411650 start = 0 ;
16421651 continue ;
16431652 }
16441653
16451654 // Avoid using suspend_all when more than 2 threads known to be unsavable
1646- u32 unsavable_threads = 0 ;
1655+ u32 savable_threads = 0 ;
16471656
16481657 for (auto & spu : *spu_list)
16491658 {
1650- if (spu->unsavable )
1659+ if (! spu->unsavable )
16511660 {
1652- unsavable_threads++;
1653-
1654- if (unsavable_threads >= 3 )
1655- {
1656- break ;
1657- }
1661+ savable_threads++;
16581662 }
16591663 }
16601664
1661- if (unsavable_threads >= 3 )
1665+ if (!savable_threads )
16621666 {
16631667 std::this_thread::yield ();
16641668 continue ;
16651669 }
16661670
1667- // Flag for optimization
1668- bool paused_anyone = false ;
1669-
16701671 if (cpu_thread::suspend_all (nullptr , {}, [&]()
16711672 {
16721673 if (!get_spus (false , true ))
@@ -1695,19 +1696,13 @@ extern bool try_lock_spu_threads_in_a_state_compatible_with_savestates(bool reve
16951696 break ;
16961697 }
16971698 }
1698- else
1699- {
1700- paused_anyone = true ;
1701- ensure (!spu->state .test_and_set (cpu_flag::dbg_global_pause));
1702- }
17031699 }
17041700
1705- if (failed && paused_anyone )
1701+ for ( auto & spu : *spu_list )
17061702 {
1707- // For faster signalling, first remove state flags then batch notifications
1708- for (auto & spu : *spu_list)
1703+ if (!failed && !is_emu_paused)
17091704 {
1710- spu->state -= cpu_flag::dbg_global_pause;
1705+ ensure (! spu->state . test_and_set ( cpu_flag::dbg_global_pause)) ;
17111706 }
17121707 }
17131708
@@ -1719,13 +1714,6 @@ extern bool try_lock_spu_threads_in_a_state_compatible_with_savestates(bool reve
17191714 return false ;
17201715 }
17211716
1722- if (!paused_anyone)
1723- {
1724- // Need not do anything
1725- std::this_thread::yield ();
1726- continue ;
1727- }
1728-
17291717 for (auto & spu : *spu_list)
17301718 {
17311719 if (spu->state & cpu_flag::wait)
@@ -1755,7 +1743,7 @@ extern bool try_lock_spu_threads_in_a_state_compatible_with_savestates(bool reve
17551743 {
17561744 spu->state .notify_one ();
17571745 }
1758- };
1746+ }
17591747
17601748 return false ;
17611749}
0 commit comments