-/* Are any of the handlers ready? Check this variable using
- check_async_ready. This is used by process_event, to determine
- whether or not to invoke the invoke_async_signal_handler
- function. */
-static int async_handler_ready = 0;
-
-static void create_file_handler (int fd, int mask, handler_func * proc, gdb_client_data client_data);
-static void invoke_async_signal_handler (void);
-static void handle_file_event (int event_file_desc);
-static int gdb_wait_for_event (void);
-static int check_async_ready (void);
-static void async_queue_event (gdb_event * event_ptr, queue_position position);
-static gdb_event *create_file_event (int fd);
-static int process_event (void);
-static void handle_timer_event (int dummy);
-static void poll_timers (void);
-\f
-
-/* Insert an event object into the gdb event queue at
- the specified position.
- POSITION can be head or tail, with values TAIL, HEAD.
- EVENT_PTR points to the event to be inserted into the queue.
- The caller must allocate memory for the event. It is freed
- after the event has ben handled.
- Events in the queue will be processed head to tail, therefore,
- events inserted at the head of the queue will be processed
- as last in first out. Event appended at the tail of the queue
- will be processed first in first out. */
-static void
-async_queue_event (gdb_event * event_ptr, queue_position position)
-{
- if (position == TAIL)
- {
- /* 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;
- }
-}
-
-/* Create a file event, to be enqueued in the event queue for
- processing. The procedure associated to this event is always
- handle_file_event, which will in turn invoke the one that was
- associated to FD when it was registered with the event loop. */
-static gdb_event *
-create_file_event (int fd)
-{
- gdb_event *file_event_ptr;
-
- file_event_ptr = (gdb_event *) xmalloc (sizeof (gdb_event));
- file_event_ptr->proc = handle_file_event;
- file_event_ptr->fd = fd;
- return (file_event_ptr);
-}
-
-/* Process one event.
- The event can be the next one to be serviced in the event queue,
- or an asynchronous event handler can be invoked in response to
- the reception of a signal.
- If an event was processed (either way), 1 is returned otherwise
- 0 is returned.
- Scan the queue from head to tail, processing therefore the high
- priority events first, by invoking the associated event handler
- procedure. */
-static int
-process_event (void)
-{
- gdb_event *event_ptr, *prev_ptr;
- event_handler_func *proc;
- int fd;
-
- /* First let's see if there are any asynchronous event handlers that
- are ready. These would be the result of invoking any of the
- signal handlers. */
-
- if (check_async_ready ())
- {
- invoke_async_signal_handler ();
- return 1;
- }
-
- /* 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. */
-
- proc = event_ptr->proc;
- fd = event_ptr->fd;
-
- /* Let's get rid of the event from the event queue. We need to
- do this now because while processing the event, the proc
- function could end up calling 'error' and therefore jump out
- to the caller of this function, gdb_do_one_event. In that
- 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. */
- (*proc) (fd);
- return 1;
- }