From 38a4721d059bd9e0b1480bc6f6a61f4c8b58e701 Mon Sep 17 00:00:00 2001 From: Vitali Lovich Date: Fri, 11 Mar 2022 07:26:49 -0800 Subject: [PATCH] Enable a way to globally enable/disable COZ tracepoints It can be useful to leave coz tracepoints committed in the code but only conditionally enable coz. --- include/coz.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/coz.h b/include/coz.h index dc0bcc8..98be982 100644 --- a/include/coz.h +++ b/include/coz.h @@ -8,6 +8,18 @@ #if !defined(COZ_H) #define COZ_H +/// Embedders can define COZ_ENABLED explicitly to 1 or 0 to globally to +/// enable/disable coz tracepoints at build time without needing to modify code. +/// If set to 0 before including this header for the first time, all macros +/// become noops. This is useful to commit coz tracepoints into a codebase but +/// not require linking against the coz runtime and not having any code bloat +/// nor runtime overhead from using the macros. +#ifndef COZ_ENABLED +#define COZ_ENABLED 1 +#endif + +#if COZ_ENABLED + #ifndef __USE_GNU # define __USE_GNU #endif @@ -184,4 +196,17 @@ static void _call_coz_wake_other() { } #endif +#else + +#define _COZ_NOOP() do {} while(0) +#define COZ_PROGRESS_NAMED(name) _COZ_NOOP() +#define COZ_PROGRESS() _COZ_NOOP() +#define COZ_BEGIN(name) _COZ_NOOP() +#define COZ_END(name) _COZ_NOOP() +#define COZ_PRE_BLOCK() _COZ_NOOP() +#define COZ_POST_BLOCK(skip_delay) _COZ_NOOP() +#define COZ_WAKE_OTHER() _COZ_NOOP() + +#endif + #endif