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