1 /* Event loop machinery for GDB, the GNU debugger.
2 Copyright (C) 1999-2020 Free Software Foundation, Inc.
3 Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbsupport/common-defs.h"
21 #include "gdbsupport/event-loop.h"
26 #if defined (HAVE_POLL_H)
28 #elif defined (HAVE_SYS_POLL_H)
33 #include <sys/types.h>
34 #include "gdbsupport/gdb_sys_time.h"
35 #include "gdbsupport/gdb_select.h"
37 /* Tell create_file_handler what events we are interested in.
38 This is used by the select version of the event loop. */
40 #define GDB_READABLE (1<<1)
41 #define GDB_WRITABLE (1<<2)
42 #define GDB_EXCEPTION (1<<3)
44 /* Information about each file descriptor we register with the event
47 typedef struct file_handler
49 int fd
; /* File descriptor. */
50 int mask
; /* Events we want to monitor: POLLIN, etc. */
51 int ready_mask
; /* Events that have been seen since
53 handler_func
*proc
; /* Procedure to call when fd is ready. */
54 gdb_client_data client_data
; /* Argument to pass to proc. */
55 int error
; /* Was an error detected on this fd? */
56 struct file_handler
*next_file
; /* Next registered file descriptor. */
60 /* Do we use poll or select ? */
65 #endif /* HAVE_POLL */
67 static unsigned char use_poll
= USE_POLL
;
74 /* Gdb_notifier is just a list of file descriptors gdb is interested in.
75 These are the input file descriptor, and the target file
76 descriptor. We have two flavors of the notifier, one for platforms
77 that have the POLL function, the other for those that don't, and
78 only support SELECT. Each of the elements in the gdb_notifier list is
79 basically a description of what kind of events gdb is interested
84 /* Ptr to head of file handler list. */
85 file_handler
*first_file_handler
;
87 /* Next file handler to handle, for the select variant. To level
88 the fairness across event sources, we serve file handlers in a
89 round-robin-like fashion. The number and order of the polled
90 file handlers may change between invocations, but this is good
92 file_handler
*next_file_handler
;
95 /* Ptr to array of pollfd structures. */
96 struct pollfd
*poll_fds
;
98 /* Next file descriptor to handle, for the poll variant. To level
99 the fairness across event sources, we poll the file descriptors
100 in a round-robin-like fashion. The number and order of the
101 polled file descriptors may change between invocations, but
102 this is good enough. */
103 int next_poll_fds_index
;
105 /* Timeout in milliseconds for calls to poll(). */
109 /* Masks to be used in the next call to select.
110 Bits are set in response to calls to create_file_handler. */
111 fd_set check_masks
[3];
113 /* What file descriptors were found ready by select. */
114 fd_set ready_masks
[3];
116 /* Number of file descriptors to monitor (for poll). */
117 /* Number of valid bits (highest fd value + 1) (for select). */
120 /* Time structure for calls to select(). */
121 struct timeval select_timeout
;
123 /* Flag to tell whether the timeout should be used. */
128 /* Structure associated with a timer. PROC will be executed at the
129 first occasion after WHEN. */
132 std::chrono::steady_clock::time_point when
;
134 struct gdb_timer
*next
;
135 timer_handler_func
*proc
; /* Function to call to do the work. */
136 gdb_client_data client_data
; /* Argument to async_handler_func. */
139 /* List of currently active timers. It is sorted in order of
140 increasing timers. */
143 /* Pointer to first in timer list. */
144 struct gdb_timer
*first_timer
;
146 /* Id of the last timer created. */
151 static void create_file_handler (int fd
, int mask
, handler_func
*proc
,
152 gdb_client_data client_data
);
153 static int gdb_wait_for_event (int);
154 static int update_wait_timeout (void);
155 static int poll_timers (void);
157 /* Process one high level event. If nothing is ready at this time,
158 wait for something to happen (via gdb_wait_for_event), then process
159 it. Returns >0 if something was done otherwise returns <0 (this
160 can happen if there are no event sources to wait for). */
163 gdb_do_one_event (void)
165 static int event_source_head
= 0;
166 const int number_of_sources
= 3;
169 /* First let's see if there are any asynchronous signal handlers
170 that are ready. These would be the result of invoking any of the
172 if (invoke_async_signal_handlers ())
175 /* To level the fairness across event sources, we poll them in a
176 round-robin fashion. */
177 for (current
= 0; current
< number_of_sources
; current
++)
181 switch (event_source_head
)
184 /* Are any timers that are ready? */
185 res
= poll_timers ();
188 /* Are there events already waiting to be collected on the
189 monitored file descriptors? */
190 res
= gdb_wait_for_event (0);
193 /* Are there any asynchronous event handlers ready? */
194 res
= check_async_event_handlers ();
197 internal_error (__FILE__
, __LINE__
,
198 "unexpected event_source_head %d",
203 if (event_source_head
== number_of_sources
)
204 event_source_head
= 0;
210 /* Block waiting for a new event. If gdb_wait_for_event returns -1,
211 we should get out because this means that there are no event
212 sources left. This will make the event loop stop, and the
215 if (gdb_wait_for_event (1) < 0)
218 /* If gdb_wait_for_event has returned 1, it means that one event has
219 been handled. We break out of the loop. */
225 /* Wrapper function for create_file_handler, so that the caller
226 doesn't have to know implementation details about the use of poll
229 add_file_handler (int fd
, handler_func
* proc
, gdb_client_data client_data
)
238 /* Check to see if poll () is usable. If not, we'll switch to
239 use select. This can happen on systems like
240 m68k-motorola-sys, `poll' cannot be used to wait for `stdin'.
241 On m68k-motorola-sysv, tty's are not stream-based and not
245 if (poll (&fds
, 1, 0) == 1 && (fds
.revents
& POLLNVAL
))
248 internal_error (__FILE__
, __LINE__
,
249 _("use_poll without HAVE_POLL"));
250 #endif /* HAVE_POLL */
255 create_file_handler (fd
, POLLIN
, proc
, client_data
);
257 internal_error (__FILE__
, __LINE__
,
258 _("use_poll without HAVE_POLL"));
262 create_file_handler (fd
, GDB_READABLE
| GDB_EXCEPTION
,
266 /* Add a file handler/descriptor to the list of descriptors we are
269 FD is the file descriptor for the file/stream to be listened to.
271 For the poll case, MASK is a combination (OR) of POLLIN,
272 POLLRDNORM, POLLRDBAND, POLLPRI, POLLOUT, POLLWRNORM, POLLWRBAND:
273 these are the events we are interested in. If any of them occurs,
274 proc should be called.
276 For the select case, MASK is a combination of READABLE, WRITABLE,
277 EXCEPTION. PROC is the procedure that will be called when an event
278 occurs for FD. CLIENT_DATA is the argument to pass to PROC. */
281 create_file_handler (int fd
, int mask
, handler_func
* proc
,
282 gdb_client_data client_data
)
284 file_handler
*file_ptr
;
286 /* Do we already have a file handler for this file? (We may be
287 changing its associated procedure). */
288 for (file_ptr
= gdb_notifier
.first_file_handler
; file_ptr
!= NULL
;
289 file_ptr
= file_ptr
->next_file
)
291 if (file_ptr
->fd
== fd
)
295 /* It is a new file descriptor. Add it to the list. Otherwise, just
296 change the data associated with it. */
297 if (file_ptr
== NULL
)
299 file_ptr
= XNEW (file_handler
);
301 file_ptr
->ready_mask
= 0;
302 file_ptr
->next_file
= gdb_notifier
.first_file_handler
;
303 gdb_notifier
.first_file_handler
= file_ptr
;
308 gdb_notifier
.num_fds
++;
309 if (gdb_notifier
.poll_fds
)
310 gdb_notifier
.poll_fds
=
311 (struct pollfd
*) xrealloc (gdb_notifier
.poll_fds
,
312 (gdb_notifier
.num_fds
313 * sizeof (struct pollfd
)));
315 gdb_notifier
.poll_fds
=
316 XNEW (struct pollfd
);
317 (gdb_notifier
.poll_fds
+ gdb_notifier
.num_fds
- 1)->fd
= fd
;
318 (gdb_notifier
.poll_fds
+ gdb_notifier
.num_fds
- 1)->events
= mask
;
319 (gdb_notifier
.poll_fds
+ gdb_notifier
.num_fds
- 1)->revents
= 0;
321 internal_error (__FILE__
, __LINE__
,
322 _("use_poll without HAVE_POLL"));
323 #endif /* HAVE_POLL */
327 if (mask
& GDB_READABLE
)
328 FD_SET (fd
, &gdb_notifier
.check_masks
[0]);
330 FD_CLR (fd
, &gdb_notifier
.check_masks
[0]);
332 if (mask
& GDB_WRITABLE
)
333 FD_SET (fd
, &gdb_notifier
.check_masks
[1]);
335 FD_CLR (fd
, &gdb_notifier
.check_masks
[1]);
337 if (mask
& GDB_EXCEPTION
)
338 FD_SET (fd
, &gdb_notifier
.check_masks
[2]);
340 FD_CLR (fd
, &gdb_notifier
.check_masks
[2]);
342 if (gdb_notifier
.num_fds
<= fd
)
343 gdb_notifier
.num_fds
= fd
+ 1;
347 file_ptr
->proc
= proc
;
348 file_ptr
->client_data
= client_data
;
349 file_ptr
->mask
= mask
;
352 /* Return the next file handler to handle, and advance to the next
353 file handler, wrapping around if the end of the list is
356 static file_handler
*
357 get_next_file_handler_to_handle_and_advance (void)
359 file_handler
*curr_next
;
361 /* The first time around, this is still NULL. */
362 if (gdb_notifier
.next_file_handler
== NULL
)
363 gdb_notifier
.next_file_handler
= gdb_notifier
.first_file_handler
;
365 curr_next
= gdb_notifier
.next_file_handler
;
366 gdb_assert (curr_next
!= NULL
);
369 gdb_notifier
.next_file_handler
= curr_next
->next_file
;
370 /* Wrap around, if necessary. */
371 if (gdb_notifier
.next_file_handler
== NULL
)
372 gdb_notifier
.next_file_handler
= gdb_notifier
.first_file_handler
;
377 /* Remove the file descriptor FD from the list of monitored fd's:
378 i.e. we don't care anymore about events on the FD. */
380 delete_file_handler (int fd
)
382 file_handler
*file_ptr
, *prev_ptr
= NULL
;
386 struct pollfd
*new_poll_fds
;
389 /* Find the entry for the given file. */
391 for (file_ptr
= gdb_notifier
.first_file_handler
; file_ptr
!= NULL
;
392 file_ptr
= file_ptr
->next_file
)
394 if (file_ptr
->fd
== fd
)
398 if (file_ptr
== NULL
)
404 /* Create a new poll_fds array by copying every fd's information
405 but the one we want to get rid of. */
407 new_poll_fds
= (struct pollfd
*)
408 xmalloc ((gdb_notifier
.num_fds
- 1) * sizeof (struct pollfd
));
410 for (i
= 0, j
= 0; i
< gdb_notifier
.num_fds
; i
++)
412 if ((gdb_notifier
.poll_fds
+ i
)->fd
!= fd
)
414 (new_poll_fds
+ j
)->fd
= (gdb_notifier
.poll_fds
+ i
)->fd
;
415 (new_poll_fds
+ j
)->events
= (gdb_notifier
.poll_fds
+ i
)->events
;
416 (new_poll_fds
+ j
)->revents
417 = (gdb_notifier
.poll_fds
+ i
)->revents
;
421 xfree (gdb_notifier
.poll_fds
);
422 gdb_notifier
.poll_fds
= new_poll_fds
;
423 gdb_notifier
.num_fds
--;
425 internal_error (__FILE__
, __LINE__
,
426 _("use_poll without HAVE_POLL"));
427 #endif /* HAVE_POLL */
431 if (file_ptr
->mask
& GDB_READABLE
)
432 FD_CLR (fd
, &gdb_notifier
.check_masks
[0]);
433 if (file_ptr
->mask
& GDB_WRITABLE
)
434 FD_CLR (fd
, &gdb_notifier
.check_masks
[1]);
435 if (file_ptr
->mask
& GDB_EXCEPTION
)
436 FD_CLR (fd
, &gdb_notifier
.check_masks
[2]);
438 /* Find current max fd. */
440 if ((fd
+ 1) == gdb_notifier
.num_fds
)
442 gdb_notifier
.num_fds
--;
443 for (i
= gdb_notifier
.num_fds
; i
; i
--)
445 if (FD_ISSET (i
- 1, &gdb_notifier
.check_masks
[0])
446 || FD_ISSET (i
- 1, &gdb_notifier
.check_masks
[1])
447 || FD_ISSET (i
- 1, &gdb_notifier
.check_masks
[2]))
450 gdb_notifier
.num_fds
= i
;
454 /* Deactivate the file descriptor, by clearing its mask,
455 so that it will not fire again. */
459 /* If this file handler was going to be the next one to be handled,
460 advance to the next's next, if any. */
461 if (gdb_notifier
.next_file_handler
== file_ptr
)
463 if (file_ptr
->next_file
== NULL
464 && file_ptr
== gdb_notifier
.first_file_handler
)
465 gdb_notifier
.next_file_handler
= NULL
;
467 get_next_file_handler_to_handle_and_advance ();
470 /* Get rid of the file handler in the file handler list. */
471 if (file_ptr
== gdb_notifier
.first_file_handler
)
472 gdb_notifier
.first_file_handler
= file_ptr
->next_file
;
475 for (prev_ptr
= gdb_notifier
.first_file_handler
;
476 prev_ptr
->next_file
!= file_ptr
;
477 prev_ptr
= prev_ptr
->next_file
)
479 prev_ptr
->next_file
= file_ptr
->next_file
;
484 /* Handle the given event by calling the procedure associated to the
485 corresponding file handler. */
488 handle_file_event (file_handler
*file_ptr
, int ready_mask
)
497 /* With poll, the ready_mask could have any of three events
498 set to 1: POLLHUP, POLLERR, POLLNVAL. These events
499 cannot be used in the requested event mask (events), but
500 they can be returned in the return mask (revents). We
501 need to check for those event too, and add them to the
502 mask which will be passed to the handler. */
504 /* See if the desired events (mask) match the received
505 events (ready_mask). */
510 /* POLLHUP means EOF, but can be combined with POLLIN to
511 signal more data to read. */
512 error_mask
= POLLHUP
| POLLERR
| POLLNVAL
;
513 mask
= ready_mask
& (file_ptr
->mask
| error_mask
);
515 if ((mask
& (POLLERR
| POLLNVAL
)) != 0)
517 /* Work in progress. We may need to tell somebody
518 what kind of error we had. */
520 warning (_("Error detected on fd %d"), file_ptr
->fd
);
522 warning (_("Invalid or non-`poll'able fd %d"),
529 internal_error (__FILE__
, __LINE__
,
530 _("use_poll without HAVE_POLL"));
531 #endif /* HAVE_POLL */
535 if (ready_mask
& GDB_EXCEPTION
)
537 warning (_("Exception condition detected on fd %d"),
543 mask
= ready_mask
& file_ptr
->mask
;
546 /* If there was a match, then call the handler. */
548 (*file_ptr
->proc
) (file_ptr
->error
, file_ptr
->client_data
);
553 /* Wait for new events on the monitored file descriptors. Run the
554 event handler if the first descriptor that is detected by the poll.
555 If BLOCK and if there are no events, this function will block in
556 the call to poll. Return 1 if an event was handled. Return -1 if
557 there are no file descriptors to monitor. Return 1 if an event was
558 handled, otherwise returns 0. */
561 gdb_wait_for_event (int block
)
563 file_handler
*file_ptr
;
566 /* Make sure all output is done before getting another event. */
569 if (gdb_notifier
.num_fds
== 0)
573 update_wait_timeout ();
581 timeout
= gdb_notifier
.timeout_valid
? gdb_notifier
.poll_timeout
: -1;
585 num_found
= poll (gdb_notifier
.poll_fds
,
586 (unsigned long) gdb_notifier
.num_fds
, timeout
);
588 /* Don't print anything if we get out of poll because of a
590 if (num_found
== -1 && errno
!= EINTR
)
591 perror_with_name (("poll"));
593 internal_error (__FILE__
, __LINE__
,
594 _("use_poll without HAVE_POLL"));
595 #endif /* HAVE_POLL */
599 struct timeval select_timeout
;
600 struct timeval
*timeout_p
;
603 timeout_p
= gdb_notifier
.timeout_valid
604 ? &gdb_notifier
.select_timeout
: NULL
;
607 memset (&select_timeout
, 0, sizeof (select_timeout
));
608 timeout_p
= &select_timeout
;
611 gdb_notifier
.ready_masks
[0] = gdb_notifier
.check_masks
[0];
612 gdb_notifier
.ready_masks
[1] = gdb_notifier
.check_masks
[1];
613 gdb_notifier
.ready_masks
[2] = gdb_notifier
.check_masks
[2];
614 num_found
= gdb_select (gdb_notifier
.num_fds
,
615 &gdb_notifier
.ready_masks
[0],
616 &gdb_notifier
.ready_masks
[1],
617 &gdb_notifier
.ready_masks
[2],
620 /* Clear the masks after an error from select. */
623 FD_ZERO (&gdb_notifier
.ready_masks
[0]);
624 FD_ZERO (&gdb_notifier
.ready_masks
[1]);
625 FD_ZERO (&gdb_notifier
.ready_masks
[2]);
627 /* Dont print anything if we got a signal, let gdb handle
630 perror_with_name (("select"));
634 /* Avoid looking at poll_fds[i]->revents if no event fired. */
638 /* Run event handlers. We always run just one handler and go back
639 to polling, in case a handler changes the notifier list. Since
640 events for sources we haven't consumed yet wake poll/select
641 immediately, no event is lost. */
643 /* To level the fairness across event descriptors, we handle them in
644 a round-robin-like fashion. The number and order of descriptors
645 may change between invocations, but this is good enough. */
654 if (gdb_notifier
.next_poll_fds_index
>= gdb_notifier
.num_fds
)
655 gdb_notifier
.next_poll_fds_index
= 0;
656 i
= gdb_notifier
.next_poll_fds_index
++;
658 gdb_assert (i
< gdb_notifier
.num_fds
);
659 if ((gdb_notifier
.poll_fds
+ i
)->revents
)
663 for (file_ptr
= gdb_notifier
.first_file_handler
;
665 file_ptr
= file_ptr
->next_file
)
667 if (file_ptr
->fd
== (gdb_notifier
.poll_fds
+ i
)->fd
)
670 gdb_assert (file_ptr
!= NULL
);
672 mask
= (gdb_notifier
.poll_fds
+ i
)->revents
;
673 handle_file_event (file_ptr
, mask
);
676 internal_error (__FILE__
, __LINE__
,
677 _("use_poll without HAVE_POLL"));
678 #endif /* HAVE_POLL */
682 /* See comment about even source fairness above. */
687 file_ptr
= get_next_file_handler_to_handle_and_advance ();
689 if (FD_ISSET (file_ptr
->fd
, &gdb_notifier
.ready_masks
[0]))
690 mask
|= GDB_READABLE
;
691 if (FD_ISSET (file_ptr
->fd
, &gdb_notifier
.ready_masks
[1]))
692 mask
|= GDB_WRITABLE
;
693 if (FD_ISSET (file_ptr
->fd
, &gdb_notifier
.ready_masks
[2]))
694 mask
|= GDB_EXCEPTION
;
698 handle_file_event (file_ptr
, mask
);
704 /* Create a timer that will expire in MS milliseconds from now. When
705 the timer is ready, PROC will be executed. At creation, the timer
706 is added to the timers queue. This queue is kept sorted in order
707 of increasing timers. Return a handle to the timer struct. */
710 create_timer (int ms
, timer_handler_func
*proc
,
711 gdb_client_data client_data
)
713 using namespace std::chrono
;
714 struct gdb_timer
*timer_ptr
, *timer_index
, *prev_timer
;
716 steady_clock::time_point time_now
= steady_clock::now ();
718 timer_ptr
= new gdb_timer ();
719 timer_ptr
->when
= time_now
+ milliseconds (ms
);
720 timer_ptr
->proc
= proc
;
721 timer_ptr
->client_data
= client_data
;
722 timer_list
.num_timers
++;
723 timer_ptr
->timer_id
= timer_list
.num_timers
;
725 /* Now add the timer to the timer queue, making sure it is sorted in
726 increasing order of expiration. */
728 for (timer_index
= timer_list
.first_timer
;
730 timer_index
= timer_index
->next
)
732 if (timer_index
->when
> timer_ptr
->when
)
736 if (timer_index
== timer_list
.first_timer
)
738 timer_ptr
->next
= timer_list
.first_timer
;
739 timer_list
.first_timer
= timer_ptr
;
744 for (prev_timer
= timer_list
.first_timer
;
745 prev_timer
->next
!= timer_index
;
746 prev_timer
= prev_timer
->next
)
749 prev_timer
->next
= timer_ptr
;
750 timer_ptr
->next
= timer_index
;
753 gdb_notifier
.timeout_valid
= 0;
754 return timer_ptr
->timer_id
;
757 /* There is a chance that the creator of the timer wants to get rid of
758 it before it expires. */
760 delete_timer (int id
)
762 struct gdb_timer
*timer_ptr
, *prev_timer
= NULL
;
764 /* Find the entry for the given timer. */
766 for (timer_ptr
= timer_list
.first_timer
; timer_ptr
!= NULL
;
767 timer_ptr
= timer_ptr
->next
)
769 if (timer_ptr
->timer_id
== id
)
773 if (timer_ptr
== NULL
)
775 /* Get rid of the timer in the timer list. */
776 if (timer_ptr
== timer_list
.first_timer
)
777 timer_list
.first_timer
= timer_ptr
->next
;
780 for (prev_timer
= timer_list
.first_timer
;
781 prev_timer
->next
!= timer_ptr
;
782 prev_timer
= prev_timer
->next
)
784 prev_timer
->next
= timer_ptr
->next
;
788 gdb_notifier
.timeout_valid
= 0;
791 /* Convert a std::chrono duration to a struct timeval. */
793 template<typename Duration
>
794 static struct timeval
795 duration_cast_timeval (const Duration
&d
)
797 using namespace std::chrono
;
798 seconds sec
= duration_cast
<seconds
> (d
);
799 microseconds msec
= duration_cast
<microseconds
> (d
- sec
);
802 tv
.tv_sec
= sec
.count ();
803 tv
.tv_usec
= msec
.count ();
807 /* Update the timeout for the select() or poll(). Returns true if the
808 timer has already expired, false otherwise. */
811 update_wait_timeout (void)
813 if (timer_list
.first_timer
!= NULL
)
815 using namespace std::chrono
;
816 steady_clock::time_point time_now
= steady_clock::now ();
817 struct timeval timeout
;
819 if (timer_list
.first_timer
->when
< time_now
)
821 /* It expired already. */
827 steady_clock::duration d
= timer_list
.first_timer
->when
- time_now
;
828 timeout
= duration_cast_timeval (d
);
831 /* Update the timeout for select/ poll. */
835 gdb_notifier
.poll_timeout
= timeout
.tv_sec
* 1000;
837 internal_error (__FILE__
, __LINE__
,
838 _("use_poll without HAVE_POLL"));
839 #endif /* HAVE_POLL */
843 gdb_notifier
.select_timeout
.tv_sec
= timeout
.tv_sec
;
844 gdb_notifier
.select_timeout
.tv_usec
= timeout
.tv_usec
;
846 gdb_notifier
.timeout_valid
= 1;
848 if (timer_list
.first_timer
->when
< time_now
)
852 gdb_notifier
.timeout_valid
= 0;
857 /* Check whether a timer in the timers queue is ready. If a timer is
858 ready, call its handler and return. Update the timeout for the
859 select() or poll() as well. Return 1 if an event was handled,
860 otherwise returns 0.*/
865 if (update_wait_timeout ())
867 struct gdb_timer
*timer_ptr
= timer_list
.first_timer
;
868 timer_handler_func
*proc
= timer_ptr
->proc
;
869 gdb_client_data client_data
= timer_ptr
->client_data
;
871 /* Get rid of the timer from the beginning of the list. */
872 timer_list
.first_timer
= timer_ptr
->next
;
874 /* Delete the timer before calling the callback, not after, in
875 case the callback itself decides to try deleting the timer
879 /* Call the procedure associated with that timer. */
880 (proc
) (client_data
);