Fix: event-notifier: not propagating error counter indexes
[lttng-ust.git] / liblttng-ust-libc-wrapper / lttng-ust-pthread.c
CommitLineData
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
d7e89462
MD
19/*
20 * Do _not_ define _LGPL_SOURCE because we don't want to create a
21 * circular dependency loop between this malloc wrapper, liburcu and
22 * libc.
23 */
f02baefb 24#include <lttng/ust-dlfcn.h>
171fcc6f 25#include <helper.h>
600f634a
SS
26#include <pthread.h>
27
28#define TRACEPOINT_DEFINE
29#define TRACEPOINT_CREATE_PROBES
35176231 30#define TP_IP_PARAM ip
600f634a
SS
31#include "ust_pthread.h"
32
16adecf1 33static __thread int thread_in_trace;
600f634a
SS
34
35int pthread_mutex_lock(pthread_mutex_t *mutex)
36{
37 static int (*mutex_lock)(pthread_mutex_t *);
38 int retval;
39
40 if (!mutex_lock) {
41 mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
42 if (!mutex_lock) {
43 if (thread_in_trace) {
44 abort();
45 }
46 fprintf(stderr, "unable to initialize pthread wrapper library.\n");
47 return EINVAL;
48 }
49 }
50 if (thread_in_trace) {
51 return mutex_lock(mutex);
52 }
53
54 thread_in_trace = 1;
35176231 55 tracepoint(lttng_ust_pthread, pthread_mutex_lock_req, mutex,
171fcc6f 56 LTTNG_UST_CALLER_IP());
600f634a 57 retval = mutex_lock(mutex);
35176231 58 tracepoint(lttng_ust_pthread, pthread_mutex_lock_acq, mutex,
171fcc6f 59 retval, LTTNG_UST_CALLER_IP());
600f634a
SS
60 thread_in_trace = 0;
61 return retval;
62}
63
64int pthread_mutex_trylock(pthread_mutex_t *mutex)
65{
66 static int (*mutex_trylock)(pthread_mutex_t *);
67 int retval;
68
69 if (!mutex_trylock) {
70 mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
71 if (!mutex_trylock) {
72 if (thread_in_trace) {
73 abort();
74 }
75 fprintf(stderr, "unable to initialize pthread wrapper library.\n");
76 return EINVAL;
77 }
78 }
79 if (thread_in_trace) {
80 return mutex_trylock(mutex);
81 }
82
83 thread_in_trace = 1;
84 retval = mutex_trylock(mutex);
35176231 85 tracepoint(lttng_ust_pthread, pthread_mutex_trylock, mutex,
171fcc6f 86 retval, LTTNG_UST_CALLER_IP());
600f634a
SS
87 thread_in_trace = 0;
88 return retval;
89}
90
91int pthread_mutex_unlock(pthread_mutex_t *mutex)
92{
93 static int (*mutex_unlock)(pthread_mutex_t *);
94 int retval;
95
96 if (!mutex_unlock) {
97 mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
98 if (!mutex_unlock) {
99 if (thread_in_trace) {
100 abort();
101 }
102 fprintf(stderr, "unable to initialize pthread wrapper library.\n");
103 return EINVAL;
104 }
105 }
106 if (thread_in_trace) {
107 return mutex_unlock(mutex);
108 }
109
110 thread_in_trace = 1;
111 retval = mutex_unlock(mutex);
35176231 112 tracepoint(lttng_ust_pthread, pthread_mutex_unlock, mutex,
171fcc6f 113 retval, LTTNG_UST_CALLER_IP());
600f634a
SS
114 thread_in_trace = 0;
115 return retval;
116}
This page took 0.033454 seconds and 4 git commands to generate.