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