delayed_call.h 670 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef _DELAYED_CALL_H
  2. #define _DELAYED_CALL_H
  3. /*
  4. * Poor man's closures; I wish we could've done them sanely polymorphic,
  5. * but...
  6. */
  7. struct delayed_call {
  8. void (*fn)(void *);
  9. void *arg;
  10. };
  11. #define DEFINE_DELAYED_CALL(name) struct delayed_call name = {NULL, NULL}
  12. /* I really wish we had closures with sane typechecking... */
  13. static inline void set_delayed_call(struct delayed_call *call,
  14. void (*fn)(void *), void *arg)
  15. {
  16. call->fn = fn;
  17. call->arg = arg;
  18. }
  19. static inline void do_delayed_call(struct delayed_call *call)
  20. {
  21. if (call->fn)
  22. call->fn(call->arg);
  23. }
  24. static inline void clear_delayed_call(struct delayed_call *call)
  25. {
  26. call->fn = NULL;
  27. }
  28. #endif