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 queue_toplevel_callback(toplevel_callback_fn_t fn
, void *ctx
)
33 cb
= snew(struct callback
);
37 /* If the front end has requested notification of pending
38 * callbacks, and we didn't already have one queued, let it know
39 * we do have one now. */
40 if (notify_frontend
&& !cbhead
)
41 notify_frontend(frontend
);
51 void run_toplevel_callbacks(void)
54 struct callback
*cb
= cbhead
;
56 * Careful ordering here. We call the function _before_
57 * advancing cbhead (though, of course, we must free cb
58 * _after_ advancing it). This means that if the very last
59 * callback schedules another callback, cbhead does not become
60 * NULL at any point, and so the frontend notification
61 * function won't be needlessly pestered.
71 int toplevel_callback_pending(void)
73 return cbhead
!= NULL
;