b613b1749dab4d4258bffc0857ad745d4883fe74
[lttng-tools.git] / src / common / testpoint / testpoint.h
1 /*
2 * Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifdef NTESTPOINT
9
10 #define testpoint(name)
11 #define TESTPOINT_DECL(name)
12
13 #else /* NTESTPOINT */
14
15 #include <urcu.h> /* for caa_likely/unlikely */
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 extern int lttng_testpoint_activated;
22
23 void *lttng_testpoint_lookup(const char *name);
24
25 /*
26 * Testpoint is only active if the global lttng_testpoint_activated flag is
27 * set.
28 * Return a non-zero error code to indicate failure.
29 */
30 #define testpoint(name) \
31 ((caa_unlikely(lttng_testpoint_activated)) \
32 ? __testpoint_##name##_wrapper() : 0)
33
34 /*
35 * One wrapper per testpoint is generated. This is to keep track of the symbol
36 * lookup status and the corresponding function pointer, if any.
37 */
38 #define _TESTPOINT_DECL(_name) \
39 static inline int __testpoint_##_name##_wrapper(void) \
40 { \
41 int ret = 0; \
42 static int (*tp)(void); \
43 static int found; \
44 const char *tp_name = "__testpoint_" #_name; \
45 \
46 if (tp) { \
47 ret = tp(); \
48 } else { \
49 if (!found) { \
50 tp = (int (*)(void)) lttng_testpoint_lookup(tp_name); \
51 if (tp) { \
52 found = 1; \
53 ret = tp(); \
54 } else { \
55 found = -1; \
56 } \
57 } \
58 } \
59 return ret; \
60 }
61
62 /* Testpoint declaration */
63 #define TESTPOINT_DECL(name) \
64 _TESTPOINT_DECL(name)
65
66 #ifdef __cplusplus
67 }
68 #endif
69
70 #endif /* NTESTPOINT */
This page took 0.030337 seconds and 3 git commands to generate.