]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tevent: add TEVENT_DEBUG() avoid argument overhead when log is not active...
authorStefan Metzmacher <metze@samba.org>
Fri, 11 Nov 2022 14:05:53 +0000 (15:05 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 19 Jul 2023 08:02:33 +0000 (08:02 +0000)
It can be very costly to calculate the arguments passed to
tevent_debug(), just to drop the message within tevent_debug()
or the callback function.

So we add a way to avoid the overhead, it will be used in the
next commits.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/tevent/tevent_internal.h

index 4fdaa6586e614f6ec11e7fa2398ae441dc4d4e61..7bb9bd67de9253fd5f27b4120fbb9e2192dcf81a 100644 (file)
@@ -296,6 +296,13 @@ struct tevent_debug_ops {
 
 void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
                  const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
+#define TEVENT_DEBUG(__ev, __level, __fmt, ...) do { \
+       if (unlikely((__ev) != NULL && \
+                    (__level) <= (__ev)->debug_ops.max_level)) \
+       { \
+               tevent_debug((__ev), (__level), (__fmt), __VA_ARGS__); \
+       } \
+} while(0)
 
 void tevent_abort(struct tevent_context *ev, const char *reason);