+ async_event_handler *h;
+
+ h = xmalloc (sizeof (*h));
+ h->ready = 0;
+ h->next_handler = NULL;
+ h->proc = proc;
+ h->client_data = client_data;
+ if (async_event_handler_list.first_handler == NULL)
+ async_event_handler_list.first_handler = h;
+ else
+ async_event_handler_list.last_handler->next_handler = h;
+ async_event_handler_list.last_handler = h;
+ return h;
+}
+
+/* Mark the handler (ASYNC_HANDLER_PTR) as ready. This information
+ will be used by gdb_do_one_event. The caller will be whoever
+ created the event source, and wants to signal that the event is
+ ready to be handled. */
+void
+mark_async_event_handler (async_event_handler *async_handler_ptr)
+{
+ async_handler_ptr->ready = 1;
+}
+
+struct async_event_handler_data
+{
+ async_event_handler_func* proc;
+ gdb_client_data client_data;
+};
+
+static void
+invoke_async_event_handler (event_data data)
+{
+ struct async_event_handler_data *hdata = data.ptr;
+ async_event_handler_func* proc = hdata->proc;
+ gdb_client_data client_data = hdata->client_data;
+
+ xfree (hdata);
+ (*proc) (client_data);
+}
+
+/* Check if any asynchronous event handlers are ready, and queue
+ events in the ready queue for any that are. */
+static void
+check_async_event_handlers (void)
+{
+ async_event_handler *async_handler_ptr;
+ struct async_event_handler_data *hdata;
+ struct gdb_event *event_ptr;
+ event_data data;
+
+ for (async_handler_ptr = async_event_handler_list.first_handler;
+ async_handler_ptr != NULL;
+ async_handler_ptr = async_handler_ptr->next_handler)
+ {
+ if (async_handler_ptr->ready)
+ {
+ async_handler_ptr->ready = 0;
+
+ hdata = xmalloc (sizeof (*hdata));
+
+ hdata->proc = async_handler_ptr->proc;
+ hdata->client_data = async_handler_ptr->client_data;
+
+ data.ptr = hdata;
+
+ event_ptr = create_event (invoke_async_event_handler, data);
+ QUEUE_enque (gdb_event_p, event_queue, event_ptr);
+ }
+ }
+}
+
+/* Delete an asynchronous handler (ASYNC_HANDLER_PTR).
+ Free the space allocated for it. */
+void
+delete_async_event_handler (async_event_handler **async_handler_ptr)
+{
+ async_event_handler *prev_ptr;
+
+ if (async_event_handler_list.first_handler == *async_handler_ptr)
+ {
+ async_event_handler_list.first_handler
+ = (*async_handler_ptr)->next_handler;
+ if (async_event_handler_list.first_handler == NULL)
+ async_event_handler_list.last_handler = NULL;
+ }
+ else
+ {
+ prev_ptr = async_event_handler_list.first_handler;
+ while (prev_ptr && prev_ptr->next_handler != *async_handler_ptr)
+ prev_ptr = prev_ptr->next_handler;
+ gdb_assert (prev_ptr);
+ prev_ptr->next_handler = (*async_handler_ptr)->next_handler;
+ if (async_event_handler_list.last_handler == (*async_handler_ptr))
+ async_event_handler_list.last_handler = prev_ptr;
+ }
+ xfree (*async_handler_ptr);
+ *async_handler_ptr = NULL;