bin: compile lttng-sessiond as C++
[lttng-tools.git] / src / common / testpoint / testpoint.h
CommitLineData
6242251b 1/*
ab5be9fa 2 * Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
6242251b 3 *
ab5be9fa 4 * SPDX-License-Identifier: GPL-2.0-only
6242251b 5 *
6242251b
CB
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
7966af57
SM
17#ifdef __cplusplus
18extern "C" {
19#endif
20
6242251b
CB
21extern int lttng_testpoint_activated;
22
23void *lttng_testpoint_lookup(const char *name);
24
25/*
26 * Testpoint is only active if the global lttng_testpoint_activated flag is
27 * set.
6993eeb3 28 * Return a non-zero error code to indicate failure.
6242251b 29 */
6993eeb3
CB
30#define testpoint(name) \
31 ((caa_unlikely(lttng_testpoint_activated)) \
32 ? __testpoint_##name##_wrapper() : 0)
6242251b
CB
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) \
6993eeb3 39 static inline int __testpoint_##_name##_wrapper(void) \
6242251b 40 { \
6993eeb3
CB
41 int ret = 0; \
42 static int (*tp)(void); \
6242251b
CB
43 static int found; \
44 const char *tp_name = "__testpoint_" #_name; \
45 \
46 if (tp) { \
6993eeb3 47 ret = tp(); \
6242251b
CB
48 } else { \
49 if (!found) { \
7966af57 50 tp = (int (*)(void)) lttng_testpoint_lookup(tp_name); \
6242251b
CB
51 if (tp) { \
52 found = 1; \
6993eeb3 53 ret = tp(); \
6242251b
CB
54 } else { \
55 found = -1; \
56 } \
57 } \
58 } \
6993eeb3 59 return ret; \
6242251b
CB
60 }
61
62/* Testpoint declaration */
63#define TESTPOINT_DECL(name) \
64 _TESTPOINT_DECL(name)
65
7966af57
SM
66#ifdef __cplusplus
67}
68#endif
69
6242251b 70#endif /* NTESTPOINT */
This page took 0.05931 seconds and 4 git commands to generate.