Commit | Line | Data |
---|---|---|
600f634a SS |
1 | /* |
2 | * Copyright (C) 2013 Mentor Graphics | |
3 | * | |
4 | * This library is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU Lesser General Public | |
6 | * License as published by the Free Software Foundation; either | |
7 | * version 2.1 of the License, or (at your option) any later version. | |
8 | * | |
9 | * This library is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * Lesser General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU Lesser General Public | |
15 | * License along with this library; if not, write to the Free Software | |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | */ | |
18 | ||
19 | #define _GNU_SOURCE | |
d7e89462 MD |
20 | /* |
21 | * Do _not_ define _LGPL_SOURCE because we don't want to create a | |
22 | * circular dependency loop between this malloc wrapper, liburcu and | |
23 | * libc. | |
24 | */ | |
f02baefb | 25 | #include <lttng/ust-dlfcn.h> |
553bbf7f | 26 | #include <urcu/tls-compat.h> |
171fcc6f | 27 | #include <helper.h> |
600f634a SS |
28 | #include <pthread.h> |
29 | ||
30 | #define TRACEPOINT_DEFINE | |
31 | #define TRACEPOINT_CREATE_PROBES | |
35176231 | 32 | #define TP_IP_PARAM ip |
600f634a SS |
33 | #include "ust_pthread.h" |
34 | ||
553bbf7f | 35 | static DEFINE_URCU_TLS_IE(int, thread_in_trace); |
600f634a SS |
36 | |
37 | int pthread_mutex_lock(pthread_mutex_t *mutex) | |
38 | { | |
39 | static int (*mutex_lock)(pthread_mutex_t *); | |
40 | int retval; | |
41 | ||
42 | if (!mutex_lock) { | |
43 | mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock"); | |
44 | if (!mutex_lock) { | |
45 | if (thread_in_trace) { | |
46 | abort(); | |
47 | } | |
48 | fprintf(stderr, "unable to initialize pthread wrapper library.\n"); | |
49 | return EINVAL; | |
50 | } | |
51 | } | |
52 | if (thread_in_trace) { | |
53 | return mutex_lock(mutex); | |
54 | } | |
55 | ||
56 | thread_in_trace = 1; | |
35176231 | 57 | tracepoint(lttng_ust_pthread, pthread_mutex_lock_req, mutex, |
171fcc6f | 58 | LTTNG_UST_CALLER_IP()); |
600f634a | 59 | retval = mutex_lock(mutex); |
35176231 | 60 | tracepoint(lttng_ust_pthread, pthread_mutex_lock_acq, mutex, |
171fcc6f | 61 | retval, LTTNG_UST_CALLER_IP()); |
600f634a SS |
62 | thread_in_trace = 0; |
63 | return retval; | |
64 | } | |
65 | ||
66 | int pthread_mutex_trylock(pthread_mutex_t *mutex) | |
67 | { | |
68 | static int (*mutex_trylock)(pthread_mutex_t *); | |
69 | int retval; | |
70 | ||
71 | if (!mutex_trylock) { | |
72 | mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock"); | |
73 | if (!mutex_trylock) { | |
74 | if (thread_in_trace) { | |
75 | abort(); | |
76 | } | |
77 | fprintf(stderr, "unable to initialize pthread wrapper library.\n"); | |
78 | return EINVAL; | |
79 | } | |
80 | } | |
81 | if (thread_in_trace) { | |
82 | return mutex_trylock(mutex); | |
83 | } | |
84 | ||
85 | thread_in_trace = 1; | |
86 | retval = mutex_trylock(mutex); | |
35176231 | 87 | tracepoint(lttng_ust_pthread, pthread_mutex_trylock, mutex, |
171fcc6f | 88 | retval, LTTNG_UST_CALLER_IP()); |
600f634a SS |
89 | thread_in_trace = 0; |
90 | return retval; | |
91 | } | |
92 | ||
93 | int pthread_mutex_unlock(pthread_mutex_t *mutex) | |
94 | { | |
95 | static int (*mutex_unlock)(pthread_mutex_t *); | |
96 | int retval; | |
97 | ||
98 | if (!mutex_unlock) { | |
99 | mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock"); | |
100 | if (!mutex_unlock) { | |
101 | if (thread_in_trace) { | |
102 | abort(); | |
103 | } | |
104 | fprintf(stderr, "unable to initialize pthread wrapper library.\n"); | |
105 | return EINVAL; | |
106 | } | |
107 | } | |
108 | if (thread_in_trace) { | |
109 | return mutex_unlock(mutex); | |
110 | } | |
111 | ||
112 | thread_in_trace = 1; | |
113 | retval = mutex_unlock(mutex); | |
35176231 | 114 | tracepoint(lttng_ust_pthread, pthread_mutex_unlock, mutex, |
171fcc6f | 115 | retval, LTTNG_UST_CALLER_IP()); |
600f634a SS |
116 | thread_in_trace = 0; |
117 | return retval; | |
118 | } |