@@ -556,36 +556,46 @@ bool ThreadList::WillResume() {
556556 }
557557 }
558558
559+ ThreadSP thread_to_run;
560+ if (run_me_only_list.GetSize (false ) > 0 ) {
561+ if (stop_others_thread_sp) {
562+ thread_to_run = stop_others_thread_sp;
563+ } else if (run_me_only_list.GetSize (false ) == 1 ) {
564+ thread_to_run = run_me_only_list.GetThreadAtIndex (0 );
565+ } else {
566+ int random_thread =
567+ (int )((run_me_only_list.GetSize (false ) * (double )rand ()) /
568+ (RAND_MAX + 1.0 ));
569+ thread_to_run = run_me_only_list.GetThreadAtIndex (random_thread);
570+ }
571+ }
572+
559573 // Give all the threads that are likely to run a last chance to set up their
560574 // state before we negotiate who is actually going to get a chance to run...
561575 // Don't set to resume suspended threads, and if any thread wanted to stop
562576 // others, only call setup on the threads that request StopOthers...
563- bool wants_solo_run = run_me_only_list.GetSize (false ) > 0 ;
564- for (pos = m_threads.begin (); pos != end; ++pos) {
565- ThreadSP thread_sp (*pos);
577+ if (thread_to_run != nullptr ) {
566578 // See if any thread wants to run stopping others. If it does, then we
567579 // won't setup the other threads for resume, since they aren't going to get
568580 // a chance to run. This is necessary because the SetupForResume might add
569581 // "StopOthers" plans which would then get to be part of the who-gets-to-run
570582 // negotiation, but they're coming in after the fact, and the threads that
571583 // are already set up should take priority.
572- if (thread_sp->GetResumeState () != eStateSuspended &&
573- (!wants_solo_run || thread_sp->GetCurrentPlan ()->StopOthers ())) {
574- if (thread_sp->IsOperatingSystemPluginThread () &&
575- !thread_sp->GetBackingThread ())
576- continue ;
577- if (thread_sp->SetupForResume ()) {
578- // You can't say "stop others" and also want yourself to be suspended.
579- assert (thread_sp->GetCurrentPlan ()->RunState () != eStateSuspended);
580- run_me_only_list.AddThread (thread_sp);
581-
582- if (!(stop_others_thread_sp && stop_others_thread_sp->ShouldRunBeforePublicStop ())) {
583- if (thread_sp == GetSelectedThread ())
584- stop_others_thread_sp = thread_sp;
585-
584+ thread_to_run->SetupForResume ();
585+ } else {
586+ for (pos = m_threads.begin (); pos != end; ++pos) {
587+ ThreadSP thread_sp (*pos);
588+ if (thread_sp->GetResumeState () != eStateSuspended) {
589+ if (thread_sp->IsOperatingSystemPluginThread () &&
590+ !thread_sp->GetBackingThread ())
591+ continue ;
592+ if (thread_sp->SetupForResume ()) {
593+ // You can't say "stop others" and also want yourself to be suspended.
594+ assert (thread_sp->GetCurrentPlan ()->RunState () != eStateSuspended);
595+ run_me_only_list.AddThread (thread_sp);
596+ thread_to_run = thread_sp;
586597 if (thread_sp->ShouldRunBeforePublicStop ()) {
587598 // This takes precedence, so if we find one of these, service it:
588- stop_others_thread_sp = thread_sp;
589599 break ;
590600 }
591601 }
@@ -622,19 +632,6 @@ bool ThreadList::WillResume() {
622632 need_to_resume = false ;
623633 }
624634 } else {
625- ThreadSP thread_to_run;
626-
627- if (stop_others_thread_sp) {
628- thread_to_run = stop_others_thread_sp;
629- } else if (run_me_only_list.GetSize (false ) == 1 ) {
630- thread_to_run = run_me_only_list.GetThreadAtIndex (0 );
631- } else {
632- int random_thread =
633- (int )((run_me_only_list.GetSize (false ) * (double )rand ()) /
634- (RAND_MAX + 1.0 ));
635- thread_to_run = run_me_only_list.GetThreadAtIndex (random_thread);
636- }
637-
638635 for (pos = m_threads.begin (); pos != end; ++pos) {
639636 ThreadSP thread_sp (*pos);
640637 if (thread_sp == thread_to_run) {
0 commit comments