blob: e72286ac1572f7ca86c0fbfd58a7af84ea6cc2a4 [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
2 This file is part of drd, a data race detector.
3
sewardj85642922008-01-14 11:54:56 +00004 Copyright (C) 2006-2008 Bart Van Assche
sewardjaf44c822007-11-25 14:01:38 +00005 bart.vanassche@gmail.com
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307, USA.
21
22 The GNU General Public License is contained in the file COPYING.
23*/
24
25
bart4bb53d82008-02-28 19:06:34 +000026#include "drd_clientobj.h"
sewardjaf44c822007-11-25 14:01:38 +000027#include "drd_error.h"
28#include "drd_mutex.h"
sewardj721ad7b2007-11-30 08:30:29 +000029#include "priv_drd_clientreq.h"
sewardjaf44c822007-11-25 14:01:38 +000030#include "pub_tool_errormgr.h" // VG_(maybe_record_error)()
31#include "pub_tool_libcassert.h" // tl_assert()
bart5bd9f2d2008-03-03 20:31:58 +000032#include "pub_tool_libcbase.h" // VG_(strlen)
bart4bb53d82008-02-28 19:06:34 +000033#include "pub_tool_libcprint.h" // VG_(message)()
sewardjaf44c822007-11-25 14:01:38 +000034#include "pub_tool_machine.h" // VG_(get_IP)()
35#include "pub_tool_threadstate.h" // VG_(get_running_tid)()
36
37
sewardj347eeba2008-01-21 14:19:07 +000038// Local functions.
39
bart46d5f172008-02-28 19:49:37 +000040static void mutex_cleanup(struct mutex_info* p);
bart5357fcb2008-02-27 15:46:00 +000041static Bool mutex_is_locked(struct mutex_info* const p);
sewardj347eeba2008-01-21 14:19:07 +000042
43
sewardjaf44c822007-11-25 14:01:38 +000044// Local variables.
45
46static Bool s_trace_mutex;
47static ULong s_mutex_lock_count;
sewardjaf44c822007-11-25 14:01:38 +000048
49
50// Function definitions.
51
52void mutex_set_trace(const Bool trace_mutex)
53{
54 tl_assert(!! trace_mutex == trace_mutex);
55 s_trace_mutex = trace_mutex;
56}
57
58static
59void mutex_initialize(struct mutex_info* const p,
bart0268dfa2008-03-11 20:10:21 +000060 const Addr mutex, const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +000061{
62 tl_assert(mutex != 0);
sewardjaf44c822007-11-25 14:01:38 +000063
bart4bb53d82008-02-28 19:06:34 +000064 tl_assert(p->a1 == mutex);
barta2b6e1b2008-03-17 18:32:39 +000065 p->cleanup = (void(*)(DrdClientobj*))&mutex_cleanup;
66 p->mutex_type = mutex_type;
67 p->recursion_count = 0;
68 p->owner = DRD_INVALID_THREADID;
69 p->last_locked_segment = 0;
sewardjaf44c822007-11-25 14:01:38 +000070}
71
bart46d5f172008-02-28 19:49:37 +000072/** Deallocate the memory that was allocated by mutex_initialize(). */
73static void mutex_cleanup(struct mutex_info* p)
74{
bartb78312c2008-02-29 11:00:17 +000075 if (s_trace_mutex)
76 {
bart3b1ee452008-02-29 19:28:15 +000077 VG_(message)(Vg_UserMsg,
78 "[%d/%d] mutex_destroy %s 0x%lx",
79 VG_(get_running_tid)(),
80 thread_get_running_tid(),
bartb78312c2008-02-29 11:00:17 +000081 mutex_get_typename(p),
82 p->a1);
83 }
84
bart46d5f172008-02-28 19:49:37 +000085 if (mutex_is_locked(p))
86 {
87 MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
88 VG_(maybe_record_error)(VG_(get_running_tid)(),
89 MutexErr,
90 VG_(get_IP)(VG_(get_running_tid)()),
91 "Destroying locked mutex",
92 &MEI);
93 }
94
barta2b6e1b2008-03-17 18:32:39 +000095 sg_put(p->last_locked_segment);
96 p->last_locked_segment = 0;
bart46d5f172008-02-28 19:49:37 +000097}
98
sewardjaf44c822007-11-25 14:01:38 +000099static
sewardj721ad7b2007-11-30 08:30:29 +0000100struct mutex_info*
bart0268dfa2008-03-11 20:10:21 +0000101mutex_get_or_allocate(const Addr mutex, const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +0000102{
bart4bb53d82008-02-28 19:06:34 +0000103 struct mutex_info* p;
sewardj721ad7b2007-11-30 08:30:29 +0000104
bart4bb53d82008-02-28 19:06:34 +0000105 tl_assert(offsetof(DrdClientobj, mutex) == 0);
bart72b751c2008-03-01 13:44:24 +0000106 p = &clientobj_get(mutex, ClientMutex)->mutex;
bart4bb53d82008-02-28 19:06:34 +0000107 if (p)
108 {
bart4bb53d82008-02-28 19:06:34 +0000109 return p;
110 }
sewardj721ad7b2007-11-30 08:30:29 +0000111
bart0268dfa2008-03-11 20:10:21 +0000112 if (clientobj_present(mutex, mutex + 1))
sewardj721ad7b2007-11-30 08:30:29 +0000113 {
bart5bd9f2d2008-03-03 20:31:58 +0000114 GenericErrInfo GEI;
115 VG_(maybe_record_error)(VG_(get_running_tid)(),
116 GenericErr,
117 VG_(get_IP)(VG_(get_running_tid)()),
118 "Not a mutex",
119 &GEI);
120 return 0;
sewardj721ad7b2007-11-30 08:30:29 +0000121 }
bart4bb53d82008-02-28 19:06:34 +0000122
bart0268dfa2008-03-11 20:10:21 +0000123 p = &clientobj_add(mutex, ClientMutex)->mutex;
124 mutex_initialize(p, mutex, mutex_type);
bart4bb53d82008-02-28 19:06:34 +0000125 return p;
sewardjaf44c822007-11-25 14:01:38 +0000126}
127
bart3b1ee452008-02-29 19:28:15 +0000128struct mutex_info* mutex_get(const Addr mutex)
129{
130 tl_assert(offsetof(DrdClientobj, mutex) == 0);
bart72b751c2008-03-01 13:44:24 +0000131 return &clientobj_get(mutex, ClientMutex)->mutex;
bart3b1ee452008-02-29 19:28:15 +0000132}
133
bart00344642008-03-01 15:27:41 +0000134/** Called before pthread_mutex_init(). */
sewardj721ad7b2007-11-30 08:30:29 +0000135struct mutex_info*
bart0268dfa2008-03-11 20:10:21 +0000136mutex_init(const Addr mutex, const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +0000137{
bart00344642008-03-01 15:27:41 +0000138 struct mutex_info* p;
sewardjaf44c822007-11-25 14:01:38 +0000139
sewardjaf44c822007-11-25 14:01:38 +0000140 if (s_trace_mutex)
141 {
bart3b1ee452008-02-29 19:28:15 +0000142 VG_(message)(Vg_UserMsg,
143 "[%d/%d] mutex_init %s 0x%lx",
144 VG_(get_running_tid)(),
145 thread_get_running_tid(),
sewardj347eeba2008-01-21 14:19:07 +0000146 mutex_type_name(mutex_type),
sewardjaf44c822007-11-25 14:01:38 +0000147 mutex);
148 }
149
bart00344642008-03-01 15:27:41 +0000150 if (mutex_type == mutex_type_invalid_mutex)
151 {
152 GenericErrInfo GEI;
153 VG_(maybe_record_error)(VG_(get_running_tid)(),
154 GenericErr,
155 VG_(get_IP)(VG_(get_running_tid)()),
bart777f7fe2008-03-02 17:43:18 +0000156 "Not a mutex",
bart00344642008-03-01 15:27:41 +0000157 &GEI);
158 return 0;
159 }
160
161 p = mutex_get(mutex);
162 if (p)
sewardj347eeba2008-01-21 14:19:07 +0000163 {
164 const ThreadId vg_tid = VG_(get_running_tid)();
165 MutexErrInfo MEI
bart00344642008-03-01 15:27:41 +0000166 = { p->a1, p->recursion_count, p->owner };
sewardj347eeba2008-01-21 14:19:07 +0000167 VG_(maybe_record_error)(vg_tid,
168 MutexErr,
169 VG_(get_IP)(vg_tid),
170 "Mutex reinitialization",
171 &MEI);
bart00344642008-03-01 15:27:41 +0000172 return p;
sewardj347eeba2008-01-21 14:19:07 +0000173 }
bart0268dfa2008-03-11 20:10:21 +0000174 p = mutex_get_or_allocate(mutex, mutex_type);
sewardj347eeba2008-01-21 14:19:07 +0000175
bart00344642008-03-01 15:27:41 +0000176 return p;
sewardjaf44c822007-11-25 14:01:38 +0000177}
178
bart46d5f172008-02-28 19:49:37 +0000179/** Called after pthread_mutex_destroy(). */
sewardj347eeba2008-01-21 14:19:07 +0000180void mutex_post_destroy(const Addr mutex)
181{
bart72b751c2008-03-01 13:44:24 +0000182 struct mutex_info* p;
sewardj347eeba2008-01-21 14:19:07 +0000183
bart72b751c2008-03-01 13:44:24 +0000184 p = mutex_get(mutex);
185 if (p == 0)
186 {
187 GenericErrInfo GEI;
188 VG_(maybe_record_error)(VG_(get_running_tid)(),
189 GenericErr,
190 VG_(get_IP)(VG_(get_running_tid)()),
191 "Not a mutex",
192 &GEI);
193 return;
194 }
195
196 clientobj_remove(mutex, ClientMutex);
sewardj347eeba2008-01-21 14:19:07 +0000197}
198
bart8bba1f72008-02-27 16:13:05 +0000199/** Called before pthread_mutex_lock() is invoked. If a data structure for
200 * the client-side object was not yet created, do this now. Also check whether
201 * an attempt is made to lock recursively a synchronization object that must
202 * not be locked recursively.
203 */
bart2e3a3c12008-03-24 08:33:47 +0000204void mutex_pre_lock(const Addr mutex, const MutexT mutex_type,
205 const Bool trylock)
bart8bba1f72008-02-27 16:13:05 +0000206{
bart635cb162008-02-28 08:30:43 +0000207 struct mutex_info* p;
208
bart0268dfa2008-03-11 20:10:21 +0000209 p = mutex_get_or_allocate(mutex, mutex_type);
bart00344642008-03-01 15:27:41 +0000210 if (s_trace_mutex)
211 {
212 VG_(message)(Vg_UserMsg,
213 "[%d/%d] pre_mutex_lock %s 0x%lx rc %d owner %d",
214 VG_(get_running_tid)(),
215 thread_get_running_tid(),
bart0268dfa2008-03-11 20:10:21 +0000216 mutex_get_typename(p),
bart00344642008-03-01 15:27:41 +0000217 mutex,
bart2e3a3c12008-03-24 08:33:47 +0000218 p ? p->recursion_count : -1,
219 p ? p->owner : DRD_INVALID_THREADID);
bart00344642008-03-01 15:27:41 +0000220 }
221
bart2e3a3c12008-03-24 08:33:47 +0000222 if (p == 0)
223 {
224 GenericErrInfo GEI;
225 VG_(maybe_record_error)(VG_(get_running_tid)(),
226 GenericErr,
227 VG_(get_IP)(VG_(get_running_tid)()),
228 "Not a mutex",
229 &GEI);
230 return;
231 }
232
233 tl_assert(p);
234
bart00344642008-03-01 15:27:41 +0000235 if (mutex_type == mutex_type_invalid_mutex)
236 {
237 GenericErrInfo GEI;
238 VG_(maybe_record_error)(VG_(get_running_tid)(),
239 GenericErr,
240 VG_(get_IP)(VG_(get_running_tid)()),
bart777f7fe2008-03-02 17:43:18 +0000241 "Not a mutex",
bart00344642008-03-01 15:27:41 +0000242 &GEI);
243 return;
244 }
245
bart2e3a3c12008-03-24 08:33:47 +0000246 if (! trylock
247 && p->owner == thread_get_running_tid()
bart8bba1f72008-02-27 16:13:05 +0000248 && p->recursion_count >= 1
249 && mutex_type != mutex_type_recursive_mutex)
250 {
bart4bb53d82008-02-28 19:06:34 +0000251 MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
bart8bba1f72008-02-27 16:13:05 +0000252 VG_(maybe_record_error)(VG_(get_running_tid)(),
253 MutexErr,
254 VG_(get_IP)(VG_(get_running_tid)()),
255 "Recursive locking not allowed",
256 &MEI);
257 }
258}
259
sewardjaf44c822007-11-25 14:01:38 +0000260/**
261 * Update mutex_info state when locking the pthread_mutex_t mutex.
262 * Note: this function must be called after pthread_mutex_lock() has been
263 * called, or a race condition is triggered !
264 */
bart777f7fe2008-03-02 17:43:18 +0000265void mutex_post_lock(const Addr mutex, const Bool took_lock)
sewardjaf44c822007-11-25 14:01:38 +0000266{
bart3b1ee452008-02-29 19:28:15 +0000267 const DrdThreadId drd_tid = thread_get_running_tid();
bart00344642008-03-01 15:27:41 +0000268 struct mutex_info* p;
269
270 p = mutex_get(mutex);
sewardjaf44c822007-11-25 14:01:38 +0000271
272 if (s_trace_mutex)
273 {
bart3b1ee452008-02-29 19:28:15 +0000274 VG_(message)(Vg_UserMsg,
275 "[%d/%d] post_mutex_lock %s 0x%lx rc %d owner %d",
276 VG_(get_running_tid)(),
sewardjaf44c822007-11-25 14:01:38 +0000277 drd_tid,
bart00344642008-03-01 15:27:41 +0000278 p ? mutex_get_typename(p) : "(?)",
sewardjaf44c822007-11-25 14:01:38 +0000279 mutex,
280 p ? p->recursion_count : 0,
281 p ? p->owner : VG_INVALID_THREADID);
282 }
283
bart777f7fe2008-03-02 17:43:18 +0000284 if (! p || ! took_lock)
bart5bd9f2d2008-03-03 20:31:58 +0000285 return;
bart5357fcb2008-02-27 15:46:00 +0000286
sewardjaf44c822007-11-25 14:01:38 +0000287 if (p->recursion_count == 0)
288 {
bart5bd9f2d2008-03-03 20:31:58 +0000289 const DrdThreadId last_owner = p->owner;
290
291 if (last_owner != drd_tid && last_owner != DRD_INVALID_THREADID)
barta2b6e1b2008-03-17 18:32:39 +0000292 {
293 tl_assert(p->last_locked_segment);
294 thread_combine_vc2(drd_tid, &p->last_locked_segment->vc);
295 }
bart5bd9f2d2008-03-03 20:31:58 +0000296 thread_new_segment(drd_tid);
297
sewardjaf44c822007-11-25 14:01:38 +0000298 p->owner = drd_tid;
299 s_mutex_lock_count++;
300 }
301 else if (p->owner != drd_tid)
302 {
bart3b1ee452008-02-29 19:28:15 +0000303 VG_(message)(Vg_UserMsg,
sewardjaf44c822007-11-25 14:01:38 +0000304 "The impossible happened: mutex 0x%lx is locked"
305 " simultaneously by two threads (recursion count %d,"
306 " owners %d and %d) !",
bart4bb53d82008-02-28 19:06:34 +0000307 p->a1, p->recursion_count, p->owner, drd_tid);
sewardj347eeba2008-01-21 14:19:07 +0000308 p->owner = drd_tid;
sewardjaf44c822007-11-25 14:01:38 +0000309 }
310 p->recursion_count++;
sewardjaf44c822007-11-25 14:01:38 +0000311}
312
313/**
314 * Update mutex_info state when unlocking the pthread_mutex_t mutex.
315 * Note: this function must be called before pthread_mutex_unlock() is called,
316 * or a race condition is triggered !
bartb78312c2008-02-29 11:00:17 +0000317 * @return New value of the mutex recursion count.
sewardjaf44c822007-11-25 14:01:38 +0000318 * @param mutex Pointer to pthread_mutex_t data structure in the client space.
319 * @param tid ThreadId of the thread calling pthread_mutex_unlock().
320 * @param vc Pointer to the current vector clock of thread tid.
321 */
bart777f7fe2008-03-02 17:43:18 +0000322void mutex_unlock(const Addr mutex, const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +0000323{
bartb78312c2008-02-29 11:00:17 +0000324 const DrdThreadId drd_tid = thread_get_running_tid();
325 const ThreadId vg_tid = VG_(get_running_tid)();
sewardjaf44c822007-11-25 14:01:38 +0000326 struct mutex_info* const p = mutex_get(mutex);
327
bart777f7fe2008-03-02 17:43:18 +0000328 if (s_trace_mutex)
sewardjaf44c822007-11-25 14:01:38 +0000329 {
bart3b1ee452008-02-29 19:28:15 +0000330 VG_(message)(Vg_UserMsg,
331 "[%d/%d] mutex_unlock %s 0x%lx rc %d",
332 vg_tid,
333 drd_tid,
bart777f7fe2008-03-02 17:43:18 +0000334 p ? mutex_get_typename(p) : "?",
sewardjaf44c822007-11-25 14:01:38 +0000335 mutex,
barta2b6e1b2008-03-17 18:32:39 +0000336 p ? p->recursion_count : 0);
sewardjaf44c822007-11-25 14:01:38 +0000337 }
338
bart777f7fe2008-03-02 17:43:18 +0000339 if (p == 0 || mutex_type == mutex_type_invalid_mutex)
bartab7a6442008-02-25 19:46:14 +0000340 {
bart5bd9f2d2008-03-03 20:31:58 +0000341 GenericErrInfo GEI;
342 VG_(maybe_record_error)(vg_tid,
343 GenericErr,
344 VG_(get_IP)(vg_tid),
345 "Not a mutex",
346 &GEI);
347 return;
bartab7a6442008-02-25 19:46:14 +0000348 }
349
bart5357fcb2008-02-27 15:46:00 +0000350 if (p->owner == DRD_INVALID_THREADID)
351 {
bart4bb53d82008-02-28 19:06:34 +0000352 MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
bart5357fcb2008-02-27 15:46:00 +0000353 VG_(maybe_record_error)(vg_tid,
354 MutexErr,
355 VG_(get_IP)(vg_tid),
356 "Mutex not locked",
357 &MEI);
bart5bd9f2d2008-03-03 20:31:58 +0000358 return;
bart5357fcb2008-02-27 15:46:00 +0000359 }
360
sewardjaf44c822007-11-25 14:01:38 +0000361 tl_assert(p);
bart5357fcb2008-02-27 15:46:00 +0000362 if (p->mutex_type != mutex_type)
363 {
barta2b6e1b2008-03-17 18:32:39 +0000364 VG_(message)(Vg_UserMsg, "??? mutex 0x%lx: type changed from %d into %d",
bart5bd9f2d2008-03-03 20:31:58 +0000365 p->a1, p->mutex_type, mutex_type);
bart5357fcb2008-02-27 15:46:00 +0000366 }
sewardj721ad7b2007-11-30 08:30:29 +0000367 tl_assert(p->mutex_type == mutex_type);
sewardjaf44c822007-11-25 14:01:38 +0000368 tl_assert(p->owner != DRD_INVALID_THREADID);
sewardj721ad7b2007-11-30 08:30:29 +0000369
bart777f7fe2008-03-02 17:43:18 +0000370 if (p->owner != drd_tid || p->recursion_count <= 0)
sewardjaf44c822007-11-25 14:01:38 +0000371 {
bart4bb53d82008-02-28 19:06:34 +0000372 MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
sewardjaf44c822007-11-25 14:01:38 +0000373 VG_(maybe_record_error)(vg_tid,
374 MutexErr,
375 VG_(get_IP)(vg_tid),
bart777f7fe2008-03-02 17:43:18 +0000376 "Mutex not locked by calling thread",
sewardjaf44c822007-11-25 14:01:38 +0000377 &MEI);
bart777f7fe2008-03-02 17:43:18 +0000378 return;
sewardjaf44c822007-11-25 14:01:38 +0000379 }
bart777f7fe2008-03-02 17:43:18 +0000380 tl_assert(p->recursion_count > 0);
sewardjaf44c822007-11-25 14:01:38 +0000381 p->recursion_count--;
bart777f7fe2008-03-02 17:43:18 +0000382 tl_assert(p->recursion_count >= 0);
sewardj347eeba2008-01-21 14:19:07 +0000383
sewardjaf44c822007-11-25 14:01:38 +0000384 if (p->recursion_count == 0)
385 {
386 /* This pthread_mutex_unlock() call really unlocks the mutex. Save the */
387 /* current vector clock of the thread such that it is available when */
388 /* this mutex is locked again. */
sewardjaf44c822007-11-25 14:01:38 +0000389
barta2b6e1b2008-03-17 18:32:39 +0000390 thread_get_latest_segment(&p->last_locked_segment, drd_tid);
sewardjaf44c822007-11-25 14:01:38 +0000391 thread_new_segment(drd_tid);
392 }
sewardjaf44c822007-11-25 14:01:38 +0000393}
394
395const char* mutex_get_typename(struct mutex_info* const p)
396{
397 tl_assert(p);
sewardj721ad7b2007-11-30 08:30:29 +0000398
sewardj347eeba2008-01-21 14:19:07 +0000399 return mutex_type_name(p->mutex_type);
400}
401
402const char* mutex_type_name(const MutexT mt)
403{
404 switch (mt)
sewardjaf44c822007-11-25 14:01:38 +0000405 {
bart635cb162008-02-28 08:30:43 +0000406 case mutex_type_invalid_mutex:
407 return "invalid mutex";
bart5357fcb2008-02-27 15:46:00 +0000408 case mutex_type_recursive_mutex:
409 return "recursive mutex";
410 case mutex_type_errorcheck_mutex:
411 return "error checking mutex";
412 case mutex_type_default_mutex:
sewardjaf44c822007-11-25 14:01:38 +0000413 return "mutex";
sewardj721ad7b2007-11-30 08:30:29 +0000414 case mutex_type_spinlock:
sewardjaf44c822007-11-25 14:01:38 +0000415 return "spinlock";
416 default:
417 tl_assert(0);
418 }
419 return "?";
420}
421
bart5357fcb2008-02-27 15:46:00 +0000422/** Return true if the specified mutex is locked by any thread. */
423static Bool mutex_is_locked(struct mutex_info* const p)
424{
425 tl_assert(p);
426 return (p->recursion_count > 0);
427}
428
sewardjaf44c822007-11-25 14:01:38 +0000429Bool mutex_is_locked_by(const Addr mutex, const DrdThreadId tid)
430{
431 struct mutex_info* const p = mutex_get(mutex);
sewardjaf44c822007-11-25 14:01:38 +0000432 if (p)
433 {
434 return (p->recursion_count > 0 && p->owner == tid);
435 }
436 return False;
437}
438
sewardjaf44c822007-11-25 14:01:38 +0000439int mutex_get_recursion_count(const Addr mutex)
440{
441 struct mutex_info* const p = mutex_get(mutex);
442 tl_assert(p);
443 return p->recursion_count;
444}
445
446/**
bart301c3112008-02-24 18:22:37 +0000447 * Call this function when thread tid stops to exist, such that the
sewardjaf44c822007-11-25 14:01:38 +0000448 * "last owner" field can be cleared if it still refers to that thread.
sewardjaf44c822007-11-25 14:01:38 +0000449 */
bart301c3112008-02-24 18:22:37 +0000450void mutex_thread_delete(const DrdThreadId tid)
sewardjaf44c822007-11-25 14:01:38 +0000451{
bart4bb53d82008-02-28 19:06:34 +0000452 struct mutex_info* p;
453
bart72b751c2008-03-01 13:44:24 +0000454 clientobj_resetiter();
455 for ( ; (p = &clientobj_next(ClientMutex)->mutex) != 0; )
sewardjaf44c822007-11-25 14:01:38 +0000456 {
bart4bb53d82008-02-28 19:06:34 +0000457 if (p->owner == tid && p->recursion_count > 0)
sewardjaf44c822007-11-25 14:01:38 +0000458 {
bart5357fcb2008-02-27 15:46:00 +0000459 MutexErrInfo MEI
bart4bb53d82008-02-28 19:06:34 +0000460 = { p->a1, p->recursion_count, p->owner };
bart5357fcb2008-02-27 15:46:00 +0000461 VG_(maybe_record_error)(VG_(get_running_tid)(),
462 MutexErr,
463 VG_(get_IP)(VG_(get_running_tid)()),
464 "Mutex still locked at thread exit",
465 &MEI);
sewardjaf44c822007-11-25 14:01:38 +0000466 p->owner = VG_INVALID_THREADID;
467 }
468 }
469}
470
sewardjaf44c822007-11-25 14:01:38 +0000471ULong get_mutex_lock_count(void)
472{
473 return s_mutex_lock_count;
474}