[binutils-gdb] Windows gdb: Change serial_event management

Pedro Alves via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=87109f7e017e7e8bb327c53e8f0515ef881332fd

commit 87109f7e017e7e8bb327c53e8f0515ef881332fd
Author: Pedro Alves <[email protected]>
Date:   Mon May 22 11:29:44 2023 +0100

    Windows gdb: Change serial_event management
    
    windows_nat_target::windows_continue, when it finds a resumed thread
    that has a pending event, does:
    
              /* There's no need to really continue, because there's already
                 another event pending.  However, we do need to inform the
                 event loop of this.  */
              serial_event_set (m_wait_event);
              return TRUE;
    
    If we have more than one pending event ready to be consumed, and,
    windows_nat_target::wait returns without calling
    windows_nat_target::windows_continue, which it will with the non-stop
    support in a later patch, then we will miss waking up the event loop.
    
    This patch makes windows-nat.c manage the serial_event similarly to
    how linux-nat.c does it.  Clear it on entry to
    windows_nat_target::wait, and set it if there may be more events to
    process.  With this, there's no need to set it from
    windows_nat_target::wait_for_debug_event_main_thread, so the patch
    also makes us not do it.
    
    Approved-By: Tom Tromey <[email protected]>
    Change-Id: I44e1682721aa4866f1dbb052b3cfb4870fb13579
    commit-id:669a42f6

Diff:
---
 gdb/windows-nat.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index e0589c4de97..b2142469474 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -251,7 +251,6 @@ windows_nat_target::wait_for_debug_event_main_thread (DEBUG_EVENT *event)
 	{
 	  *event = m_last_debug_event;
 	  m_debug_event_pending = false;
-	  serial_event_clear (m_wait_event);
 	}
       else
 	wait_for_debug_event (event, INFINITE);
@@ -1190,6 +1189,11 @@ windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 {
   int pid = -1;
 
+  /* serial_event is a manual-reset event.  Clear it first.  We'll set
+     it again if we may need to wake up the event loop to get here
+     again.  */
+  serial_event_clear (m_wait_event);
+
   /* We loop when we get a non-standard exception rather than return
      with a SPURIOUS because resume can try and step or modify things,
      which needs a current_thread->h.  But some of these exceptions mark
@@ -1238,6 +1242,10 @@ windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 		thr->suspend ();
 	    }
 
+	  /* If something came out, assume there may be more.  This is
+	     needed because there may be pending events ready to
+	     consume.  */
+	  serial_event_set (m_wait_event);
 	  return result;
 	}
       else
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.