Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _DELAYED_CALL_H
0003 #define _DELAYED_CALL_H
0004 
0005 /*
0006  * Poor man's closures; I wish we could've done them sanely polymorphic,
0007  * but...
0008  */
0009 
0010 struct delayed_call {
0011     void (*fn)(void *);
0012     void *arg;
0013 };
0014 
0015 #define DEFINE_DELAYED_CALL(name) struct delayed_call name = {NULL, NULL}
0016 
0017 /* I really wish we had closures with sane typechecking... */
0018 static inline void set_delayed_call(struct delayed_call *call,
0019         void (*fn)(void *), void *arg)
0020 {
0021     call->fn = fn;
0022     call->arg = arg;
0023 }
0024 
0025 static inline void do_delayed_call(struct delayed_call *call)
0026 {
0027     if (call->fn)
0028         call->fn(call->arg);
0029 }
0030 
0031 static inline void clear_delayed_call(struct delayed_call *call)
0032 {
0033     call->fn = NULL;
0034 }
0035 #endif