delayed_call.h 709 B

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