2 * Facility for queueing callback functions to be run from the
3 * top-level event loop after the current top-level activity finishes.
11 struct callback *next;
13 toplevel_callback_fn_t fn;
17 struct callback *cbhead = NULL, *cbtail = NULL;
19 toplevel_callback_notify_fn_t notify_frontend = NULL;
20 void *frontend = NULL;
22 void request_callback_notifications(toplevel_callback_notify_fn_t fn,
29 void stoat_callback(void *ctx)
32 if (++stoat % 1000 == 0)
33 debug(("stoat %d\n", stoat));
34 queue_toplevel_callback(stoat_callback, NULL);
36 void queue_stoat(void)
41 queue_toplevel_callback(stoat_callback, NULL);
45 void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx)
51 cb = snew(struct callback);
55 /* If the front end has requested notification of pending
56 * callbacks, and we didn't already have one queued, let it know
57 * we do have one now. */
58 if (notify_frontend && !cbhead)
59 notify_frontend(frontend);
69 void run_toplevel_callbacks(void)
73 struct callback *cb = cbhead;
75 * Careful ordering here. We call the function _before_
76 * advancing cbhead (though, of course, we must free cb
77 * _after_ advancing it). This means that if the very last
78 * callback schedules another callback, cbhead does not become
79 * NULL at any point, and so the frontend notification
80 * function won't be needlessly pestered.
90 int toplevel_callback_pending(void)
93 return cbhead != NULL;