]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbsupport/event-loop: do not truncate poll timeouts to lower second
authorPatrick Monnerat <patrick@monnerat.net>
Mon, 12 May 2025 15:36:17 +0000 (17:36 +0200)
committerPatrick Monnerat <patrick@monnerat.net>
Mon, 12 May 2025 15:47:35 +0000 (17:47 +0200)
In update_wait_timeout function, microseconds were not taken into account
in poll timeout computation, resulting in 100% cpu time consumption in
the event loop while waiting for a sub-second timeout.

The bug has been introduced in commit c2c6d25.

This patch adds the microseconds converted to milliseconds in poll
timeout computation. Conversion by excess (ceil) is performed to
avoid the same problem with sub-millisecond timeouts too.

gdbsupport/event-loop.cc

index c080490f399565e31c3fdcfd58342938bb45a045..e7b21e786dba013c7bed16c81cba9091840d75df 100644 (file)
@@ -827,7 +827,8 @@ update_wait_timeout (void)
       /* Update the timeout for select/ poll.  */
 #ifdef HAVE_POLL
       if (use_poll)
-       gdb_notifier.poll_timeout = timeout.tv_sec * 1000;
+       gdb_notifier.poll_timeout = (timeout.tv_sec * 1000 +
+                                    (timeout.tv_usec + 1000 - 1) / 1000);
       else
 #endif /* HAVE_POLL */
        {