This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Simplify the event loop


Trying to get my head round the asynchronous event loop made me feel that the
usual loop in event-loop.c is overly complicated.  Maybe I'm missing something
but the patch below seems to work.  There seems to be vestigial code from
legacy concepts that are no longer present.  In any case the value of
event_queue.last_event isn't used anywhere in the code and the comment seems to
reflect this:

    /* Event queue:  
       - the first event in the queue is the head of the queue. 
       It will be the next to be serviced.
       - the last event in the queue 

       Events can be inserted at the front of the queue or at the end of

i.e nothing about the last event.

Also there is provision for FIFO and LIFO queues but only FIFO queues are
used (at least in FSF GDB).  I've left this in for the moment though, so
one issue can be dealt with at a time.

-- 
Nick                                           http://www.inet.net.nz/~nickrob


2006-09-09  Nick Roberts  <nickrob@snap.net.nz>

	* event-loop.c (event_queue): Delete structure.
	(event_head): New variable.
	(async_queue_event, process_event): Simplify.


*** event-loop.c	11 Feb 2006 11:01:43 +1300	1.29
--- event-loop.c	10 Sep 2006 12:48:14 +1200	
***************
*** 96,107 ****
  async_signal_handler;
  
  
! /* Event queue:  
!    - the first event in the queue is the head of the queue. 
!    It will be the next to be serviced.
!    - the last event in the queue 
! 
!    Events can be inserted at the front of the queue or at the end of
     the queue.  Events will be extracted from the queue for processing
     starting from the head.  Therefore, events inserted at the head of
     the queue will be processed in a last in first out fashion, while
--- 96,102 ----
  async_signal_handler;
  
  
! /* Events can be inserted at the front of the queue or at the end of
     the queue.  Events will be extracted from the queue for processing
     starting from the head.  Therefore, events inserted at the head of
     the queue will be processed in a last in first out fashion, while
***************
*** 109,120 ****
     in first out manner.  All the fields are NULL if the queue is
     empty. */
  
! static struct
!   {
!     gdb_event *first_event;	/* First pending event */
!     gdb_event *last_event;	/* Last pending event */
!   }
! event_queue;
  
  /* Gdb_notifier is just a list of file descriptors gdb is interested in.
     These are the input file descriptor, and the target file
--- 104,110 ----
     in first out manner.  All the fields are NULL if the queue is
     empty. */
  
! gdb_event *event_head = NULL;
  
  /* Gdb_notifier is just a list of file descriptors gdb is interested in.
     These are the input file descriptor, and the target file
***************
*** 244,264 ****
      {
        /* The event will become the new last_event. */
  
        event_ptr->next_event = NULL;
!       if (event_queue.first_event == NULL)
! 	event_queue.first_event = event_ptr;
        else
! 	event_queue.last_event->next_event = event_ptr;
!       event_queue.last_event = event_ptr;
      }
    else if (position == HEAD)
      {
        /* The event becomes the new first_event. */
  
!       event_ptr->next_event = event_queue.first_event;
!       if (event_queue.first_event == NULL)
! 	event_queue.last_event = event_ptr;
!       event_queue.first_event = event_ptr;
      }
  }
  
--- 234,258 ----
      {
        /* The event will become the new last_event. */
  
+       gdb_event *prev_ptr;
+ 
        event_ptr->next_event = NULL;
!       if (event_head == NULL)
! 	event_head = event_ptr;
        else
! 	{
! 	  for (prev_ptr = event_head; prev_ptr;
! 	       prev_ptr = prev_ptr->next_event)
! 	  ;
! 	  prev_ptr = event_ptr;
! 	}
      }
    else if (position == HEAD)
      {
        /* The event becomes the new first_event. */
  
!       event_ptr->next_event = event_head;
!       event_head = event_ptr;
      }
  }
  
***************
*** 289,295 ****
  static int
  process_event (void)
  {
!   gdb_event *event_ptr, *prev_ptr;
    event_handler_func *proc;
    int fd;
  
--- 283,289 ----
  static int
  process_event (void)
  {
!   gdb_event *event_ptr;
    event_handler_func *proc;
    int fd;
  
***************
*** 306,313 ****
    /* Look in the event queue to find an event that is ready
       to be processed. */
  
!   for (event_ptr = event_queue.first_event; event_ptr != NULL;
!        event_ptr = event_ptr->next_event)
      {
        /* Call the handler for the event. */
  
--- 300,306 ----
    /* Look in the event queue to find an event that is ready
       to be processed. */
  
!   for (event_ptr = event_head; event_ptr; event_ptr = event_ptr->next_event)
      {
        /* Call the handler for the event. */
  
***************
*** 321,342 ****
           case, we would have on the event queue an event wich has been
           processed, but not deleted. */
  
!       if (event_queue.first_event == event_ptr)
! 	{
! 	  event_queue.first_event = event_ptr->next_event;
! 	  if (event_ptr->next_event == NULL)
! 	    event_queue.last_event = NULL;
! 	}
!       else
! 	{
! 	  prev_ptr = event_queue.first_event;
! 	  while (prev_ptr->next_event != event_ptr)
! 	    prev_ptr = prev_ptr->next_event;
! 
! 	  prev_ptr->next_event = event_ptr->next_event;
! 	  if (event_ptr->next_event == NULL)
! 	    event_queue.last_event = prev_ptr;
! 	}
        xfree (event_ptr);
  
        /* Now call the procedure associated with the event. */
--- 314,321 ----
           case, we would have on the event queue an event wich has been
           processed, but not deleted. */
  
!       event_head = event_head->next_event;
! 
        xfree (event_ptr);
  
        /* Now call the procedure associated with the event. */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]