Commit | Line | Data |
---|---|---|
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 | ||
17 | extern int lttng_testpoint_activated; | |
18 | ||
19 | void *lttng_testpoint_lookup(const char *name); | |
20 | ||
21 | /* | |
22 | * Testpoint is only active if the global lttng_testpoint_activated flag is | |
23 | * set. | |
6993eeb3 | 24 | * Return a non-zero error code to indicate failure. |
6242251b | 25 | */ |
6993eeb3 CB |
26 | #define testpoint(name) \ |
27 | ((caa_unlikely(lttng_testpoint_activated)) \ | |
28 | ? __testpoint_##name##_wrapper() : 0) | |
6242251b CB |
29 | |
30 | /* | |
31 | * One wrapper per testpoint is generated. This is to keep track of the symbol | |
32 | * lookup status and the corresponding function pointer, if any. | |
33 | */ | |
34 | #define _TESTPOINT_DECL(_name) \ | |
6993eeb3 | 35 | static inline int __testpoint_##_name##_wrapper(void) \ |
6242251b | 36 | { \ |
6993eeb3 CB |
37 | int ret = 0; \ |
38 | static int (*tp)(void); \ | |
6242251b CB |
39 | static int found; \ |
40 | const char *tp_name = "__testpoint_" #_name; \ | |
41 | \ | |
42 | if (tp) { \ | |
6993eeb3 | 43 | ret = tp(); \ |
6242251b CB |
44 | } else { \ |
45 | if (!found) { \ | |
7966af57 | 46 | tp = (int (*)(void)) lttng_testpoint_lookup(tp_name); \ |
6242251b CB |
47 | if (tp) { \ |
48 | found = 1; \ | |
6993eeb3 | 49 | ret = tp(); \ |
6242251b CB |
50 | } else { \ |
51 | found = -1; \ | |
52 | } \ | |
53 | } \ | |
54 | } \ | |
6993eeb3 | 55 | return ret; \ |
6242251b CB |
56 | } |
57 | ||
58 | /* Testpoint declaration */ | |
59 | #define TESTPOINT_DECL(name) \ | |
60 | _TESTPOINT_DECL(name) | |
61 | ||
62 | #endif /* NTESTPOINT */ |