Hide internal tracepoint and providers data symbols
[lttng-ust.git] / src / lib / lttng-ust-pthread-wrapper / lttng-ust-pthread.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-or-later
3 *
4 * Copyright (C) 2013 Mentor Graphics
5 */
6
7 /*
8 * Do _not_ define _LGPL_SOURCE because we don't want to create a
9 * circular dependency loop between this malloc wrapper, liburcu and
10 * libc.
11 */
12
13 /* Has to be included first to override dlfcn.h */
14 #include <common/compat/dlfcn.h>
15
16 #include "common/macros.h"
17 #include <pthread.h>
18
19 #define LTTNG_UST_TRACEPOINT_HIDDEN_DEFINITION
20 #define LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION
21
22 #define LTTNG_UST_TRACEPOINT_DEFINE
23 #define LTTNG_UST_TRACEPOINT_CREATE_PROBES
24 #define LTTNG_UST_TP_IP_PARAM ip
25 #include "ust_pthread.h"
26
27 static __thread int thread_in_trace;
28
29 int pthread_mutex_lock(pthread_mutex_t *mutex)
30 {
31 static int (*mutex_lock)(pthread_mutex_t *);
32 int retval;
33
34 if (!mutex_lock) {
35 mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
36 if (!mutex_lock) {
37 if (thread_in_trace) {
38 abort();
39 }
40 fprintf(stderr, "unable to initialize pthread wrapper library.\n");
41 return EINVAL;
42 }
43 }
44 if (thread_in_trace) {
45 return mutex_lock(mutex);
46 }
47
48 thread_in_trace = 1;
49 lttng_ust_tracepoint(lttng_ust_pthread, pthread_mutex_lock_req, mutex,
50 LTTNG_UST_CALLER_IP());
51 retval = mutex_lock(mutex);
52 lttng_ust_tracepoint(lttng_ust_pthread, pthread_mutex_lock_acq, mutex,
53 retval, LTTNG_UST_CALLER_IP());
54 thread_in_trace = 0;
55 return retval;
56 }
57
58 int pthread_mutex_trylock(pthread_mutex_t *mutex)
59 {
60 static int (*mutex_trylock)(pthread_mutex_t *);
61 int retval;
62
63 if (!mutex_trylock) {
64 mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
65 if (!mutex_trylock) {
66 if (thread_in_trace) {
67 abort();
68 }
69 fprintf(stderr, "unable to initialize pthread wrapper library.\n");
70 return EINVAL;
71 }
72 }
73 if (thread_in_trace) {
74 return mutex_trylock(mutex);
75 }
76
77 thread_in_trace = 1;
78 retval = mutex_trylock(mutex);
79 lttng_ust_tracepoint(lttng_ust_pthread, pthread_mutex_trylock, mutex,
80 retval, LTTNG_UST_CALLER_IP());
81 thread_in_trace = 0;
82 return retval;
83 }
84
85 int pthread_mutex_unlock(pthread_mutex_t *mutex)
86 {
87 static int (*mutex_unlock)(pthread_mutex_t *);
88 int retval;
89
90 if (!mutex_unlock) {
91 mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
92 if (!mutex_unlock) {
93 if (thread_in_trace) {
94 abort();
95 }
96 fprintf(stderr, "unable to initialize pthread wrapper library.\n");
97 return EINVAL;
98 }
99 }
100 if (thread_in_trace) {
101 return mutex_unlock(mutex);
102 }
103
104 thread_in_trace = 1;
105 retval = mutex_unlock(mutex);
106 lttng_ust_tracepoint(lttng_ust_pthread, pthread_mutex_unlock, mutex,
107 retval, LTTNG_UST_CALLER_IP());
108 thread_in_trace = 0;
109 return retval;
110 }
This page took 0.03063 seconds and 4 git commands to generate.