public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdbsupport: Remove some unnecessary ifdef HAVE_POLL judgments
@ 2022-05-13  7:49 Youling Tang
  2022-05-13  9:28 ` Pedro Alves
  0 siblings, 1 reply; 9+ messages in thread
From: Youling Tang @ 2022-05-13  7:49 UTC (permalink / raw)
  To: gdb-patches

By searching event-loop.cc we found that there are only the following 2
places to assign values to use_poll,
$ grep -nr use_poll gdbsupport/event-loop.cc
  88:static unsigned char use_poll = USE_POLL;
  263:	use_poll = 0;

This USE_POLL is defined as follows,
 #ifdef HAVE_POLL
 #define USE_POLL 1
 #else
 #define USE_POLL 0
 #endif

So use_poll may be 1 only if HAVE_POLL is defined. Removed "ifdef
HAVE_POLL" judgment in use_poll control block.

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
---
 gdbsupport/event-loop.cc | 61 +++++-----------------------------------
 1 file changed, 7 insertions(+), 54 deletions(-)

diff --git a/gdbsupport/event-loop.cc b/gdbsupport/event-loop.cc
index 385b45b2de1..0bdaa4e7d35 100644
--- a/gdbsupport/event-loop.cc
+++ b/gdbsupport/event-loop.cc
@@ -248,13 +248,10 @@ void
 add_file_handler (int fd, handler_func *proc, gdb_client_data client_data,
 		  std::string &&name, bool is_ui)
 {
-#ifdef HAVE_POLL
-  struct pollfd fds;
-#endif
-
   if (use_poll)
     {
-#ifdef HAVE_POLL
+      struct pollfd fds;
+
       /* Check to see if poll () is usable.  If not, we'll switch to
 	 use select.  This can happen on systems like
 	 m68k-motorola-sys, `poll' cannot be used to wait for `stdin'.
@@ -264,21 +261,10 @@ add_file_handler (int fd, handler_func *proc, gdb_client_data client_data,
       fds.events = POLLIN;
       if (poll (&fds, 1, 0) == 1 && (fds.revents & POLLNVAL))
 	use_poll = 0;
-#else
-      internal_error (__FILE__, __LINE__,
-		      _("use_poll without HAVE_POLL"));
-#endif /* HAVE_POLL */
     }
   if (use_poll)
-    {
-#ifdef HAVE_POLL
-      create_file_handler (fd, POLLIN, proc, client_data, std::move (name),
+    create_file_handler (fd, POLLIN, proc, client_data, std::move (name),
 			   is_ui);
-#else
-      internal_error (__FILE__, __LINE__,
-		      _("use_poll without HAVE_POLL"));
-#endif
-    }
   else
     create_file_handler (fd, GDB_READABLE | GDB_EXCEPTION,
 			 proc, client_data, std::move (name), is_ui);
@@ -323,7 +309,6 @@ create_file_handler (int fd, int mask, handler_func * proc,
 
       if (use_poll)
 	{
-#ifdef HAVE_POLL
 	  gdb_notifier.num_fds++;
 	  if (gdb_notifier.poll_fds)
 	    gdb_notifier.poll_fds =
@@ -336,10 +321,6 @@ create_file_handler (int fd, int mask, handler_func * proc,
 	  (gdb_notifier.poll_fds + gdb_notifier.num_fds - 1)->fd = fd;
 	  (gdb_notifier.poll_fds + gdb_notifier.num_fds - 1)->events = mask;
 	  (gdb_notifier.poll_fds + gdb_notifier.num_fds - 1)->revents = 0;
-#else
-	  internal_error (__FILE__, __LINE__,
-			  _("use_poll without HAVE_POLL"));
-#endif /* HAVE_POLL */
 	}
       else
 	{
@@ -402,10 +383,6 @@ delete_file_handler (int fd)
 {
   file_handler *file_ptr, *prev_ptr = NULL;
   int i;
-#ifdef HAVE_POLL
-  int j;
-  struct pollfd *new_poll_fds;
-#endif
 
   /* Find the entry for the given file.  */
 
@@ -421,7 +398,9 @@ delete_file_handler (int fd)
 
   if (use_poll)
     {
-#ifdef HAVE_POLL
+      int j;
+      struct pollfd *new_poll_fds;
+
       /* Create a new poll_fds array by copying every fd's information
 	 but the one we want to get rid of.  */
 
@@ -442,10 +421,6 @@ delete_file_handler (int fd)
       xfree (gdb_notifier.poll_fds);
       gdb_notifier.poll_fds = new_poll_fds;
       gdb_notifier.num_fds--;
-#else
-      internal_error (__FILE__, __LINE__,
-		      _("use_poll without HAVE_POLL"));
-#endif /* HAVE_POLL */
     }
   else
     {
@@ -510,9 +485,6 @@ static void
 handle_file_event (file_handler *file_ptr, int ready_mask)
 {
   int mask;
-#ifdef HAVE_POLL
-  int error_mask;
-#endif
 
     {
 	{
@@ -528,7 +500,7 @@ handle_file_event (file_handler *file_ptr, int ready_mask)
 
 	  if (use_poll)
 	    {
-#ifdef HAVE_POLL
+	      int error_mask;
 	      /* POLLHUP means EOF, but can be combined with POLLIN to
 		 signal more data to read.  */
 	      error_mask = POLLHUP | POLLERR | POLLNVAL;
@@ -547,10 +519,6 @@ handle_file_event (file_handler *file_ptr, int ready_mask)
 		}
 	      else
 		file_ptr->error = 0;
-#else
-	      internal_error (__FILE__, __LINE__,
-			      _("use_poll without HAVE_POLL"));
-#endif /* HAVE_POLL */
 	    }
 	  else
 	    {
@@ -601,7 +569,6 @@ gdb_wait_for_event (int block)
 
   if (use_poll)
     {
-#ifdef HAVE_POLL
       int timeout;
 
       if (block)
@@ -616,10 +583,6 @@ gdb_wait_for_event (int block)
 	 signal.  */
       if (num_found == -1 && errno != EINTR)
 	perror_with_name (("poll"));
-#else
-      internal_error (__FILE__, __LINE__,
-		      _("use_poll without HAVE_POLL"));
-#endif /* HAVE_POLL */
     }
   else
     {
@@ -672,7 +635,6 @@ gdb_wait_for_event (int block)
      may change between invocations, but this is good enough.  */
   if (use_poll)
     {
-#ifdef HAVE_POLL
       int i;
       int mask;
 
@@ -699,10 +661,6 @@ gdb_wait_for_event (int block)
       mask = (gdb_notifier.poll_fds + i)->revents;
       handle_file_event (file_ptr, mask);
       return 1;
-#else
-      internal_error (__FILE__, __LINE__,
-		      _("use_poll without HAVE_POLL"));
-#endif /* HAVE_POLL */
     }
   else
     {
@@ -858,12 +816,7 @@ update_wait_timeout (void)
       /* Update the timeout for select/ poll.  */
       if (use_poll)
 	{
-#ifdef HAVE_POLL
 	  gdb_notifier.poll_timeout = timeout.tv_sec * 1000;
-#else
-	  internal_error (__FILE__, __LINE__,
-			  _("use_poll without HAVE_POLL"));
-#endif /* HAVE_POLL */
 	}
       else
 	{
-- 
2.20.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-05-16 19:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13  7:49 [PATCH] gdbsupport: Remove some unnecessary ifdef HAVE_POLL judgments Youling Tang
2022-05-13  9:28 ` Pedro Alves
2022-05-13 10:09   ` Youling Tang
2022-05-13 10:21     ` Pedro Alves
2022-05-14  1:14       ` Youling Tang
2022-05-16  9:31         ` [PATCH] gdbsupport/even-loop.cc: simplify !HAVE_POLL paths Pedro Alves
2022-05-16 12:13           ` Youling Tang
2022-05-16 15:24           ` Tom Tromey
2022-05-16 19:01             ` [ob/pushed] Reindent gdbsupport/event-loop.cc:handle_file_event (Re: [PATCH] gdbsupport/even-loop.cc: simplify !HAVE_POLL paths) Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).