We are going to unlink the timeout from the splay tree anyway, so do it
unconditionally before the callback, instead of waiting until after the
callback to check whether or not to remove it based on its expiration
time.
timersub(&timeout->tv, &now, diff);
if(diff->tv_sec < 0) {
- timeout->cb(timeout->data);
-
- if(timercmp(&timeout->tv, &now, <)) {
- timeout_del(timeout);
- }
+ timeout_cb_t cb = timeout->cb;
+ timeout_del(timeout);
+ cb(timeout->data);
} else {
tv = diff;
break;