X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ftestpoint%2Ftestpoint.h;h=b613b1749dab4d4258bffc0857ad745d4883fe74;hp=ba3af8a5370a7c6155e46e480b105fc16e2f2a15;hb=7966af5763c4aaca39df9bbfa9277ff15715c720;hpb=6242251b39f531a2485b758edcb455e220267fdd diff --git a/src/common/testpoint/testpoint.h b/src/common/testpoint/testpoint.h index ba3af8a53..b613b1749 100644 --- a/src/common/testpoint/testpoint.h +++ b/src/common/testpoint/testpoint.h @@ -1,18 +1,8 @@ /* - * Copyright (C) 2012 - Christian Babeux + * Copyright (C) 2012 Christian Babeux * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2 only, as - * published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef NTESTPOINT @@ -24,6 +14,10 @@ #include /* for caa_likely/unlikely */ +#ifdef __cplusplus +extern "C" { +#endif + extern int lttng_testpoint_activated; void *lttng_testpoint_lookup(const char *name); @@ -31,42 +25,46 @@ void *lttng_testpoint_lookup(const char *name); /* * Testpoint is only active if the global lttng_testpoint_activated flag is * set. + * Return a non-zero error code to indicate failure. */ -#define testpoint(name) \ - do { \ - if (caa_unlikely(lttng_testpoint_activated)) { \ - __testpoint_##name##_wrapper(); \ - } \ - } while (0) +#define testpoint(name) \ + ((caa_unlikely(lttng_testpoint_activated)) \ + ? __testpoint_##name##_wrapper() : 0) /* * One wrapper per testpoint is generated. This is to keep track of the symbol * lookup status and the corresponding function pointer, if any. */ #define _TESTPOINT_DECL(_name) \ - static inline void __testpoint_##_name##_wrapper(void) \ + static inline int __testpoint_##_name##_wrapper(void) \ { \ - static void (*tp)(void); \ + int ret = 0; \ + static int (*tp)(void); \ static int found; \ const char *tp_name = "__testpoint_" #_name; \ \ if (tp) { \ - tp(); \ + ret = tp(); \ } else { \ if (!found) { \ - tp = lttng_testpoint_lookup(tp_name); \ + tp = (int (*)(void)) lttng_testpoint_lookup(tp_name); \ if (tp) { \ found = 1; \ - tp(); \ + ret = tp(); \ } else { \ found = -1; \ } \ } \ } \ + return ret; \ } /* Testpoint declaration */ #define TESTPOINT_DECL(name) \ _TESTPOINT_DECL(name) +#ifdef __cplusplus +} +#endif + #endif /* NTESTPOINT */