From 34d83987c18df3e06db1528423841376072bb627 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 14 Feb 2024 11:19:41 -0500 Subject: kernel: Add __TRY_CALL() macro This commit adds a macro to make testing if weak functions are implemented, then running them, less messy. This allows you to do so in one line. Signed-off-by: Ian Moffett --- sys/include/sys/cdefs.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sys/include') diff --git a/sys/include/sys/cdefs.h b/sys/include/sys/cdefs.h index 59c81d4..da78510 100644 --- a/sys/include/sys/cdefs.h +++ b/sys/include/sys/cdefs.h @@ -154,6 +154,13 @@ #define __MODULE_NAME(name) \ __used static const char *__THIS_MODULE = name +/* + * Attempts to call a __weak function. Does nothing + * if routine not implemented. + */ +#define __TRY_CALL(routine, ...) \ + if (routine != NULL) routine(__VA_ARGS__) + #else /* -- cgit v1.2.3