blob: c28487d4abb4303deb11c6c3400c13778e8ee618 [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{
bart6b717612008-03-24 09:29:38 +000075 tl_assert(p);
76
bartb78312c2008-02-29 11:00:17 +000077 if (s_trace_mutex)
78 {
bart3b1ee452008-02-29 19:28:15 +000079 VG_(message)(Vg_UserMsg,
80 "[%d/%d] mutex_destroy %s 0x%lx",
81 VG_(get_running_tid)(),
82 thread_get_running_tid(),
bartb78312c2008-02-29 11:00:17 +000083 mutex_get_typename(p),
84 p->a1);
85 }
86
bart46d5f172008-02-28 19:49:37 +000087 if (mutex_is_locked(p))
88 {
89 MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
90 VG_(maybe_record_error)(VG_(get_running_tid)(),
91 MutexErr,
92 VG_(get_IP)(VG_(get_running_tid)()),
93 "Destroying locked mutex",
94 &MEI);
95 }
96
barta2b6e1b2008-03-17 18:32:39 +000097 sg_put(p->last_locked_segment);
98 p->last_locked_segment = 0;
bart46d5f172008-02-28 19:49:37 +000099}
100
bart6b717612008-03-24 09:29:38 +0000101static void not_a_mutex(const Addr mutex)
102{
103 MutexErrInfo MEI = { mutex, -1, DRD_INVALID_THREADID };
104 VG_(maybe_record_error)(VG_(get_running_tid)(),
105 MutexErr,
106 VG_(get_IP)(VG_(get_running_tid)()),
107 "Not a mutex",
108 &MEI);
109}
110
sewardjaf44c822007-11-25 14:01:38 +0000111static
sewardj721ad7b2007-11-30 08:30:29 +0000112struct mutex_info*
bart0268dfa2008-03-11 20:10:21 +0000113mutex_get_or_allocate(const Addr mutex, const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +0000114{
bart4bb53d82008-02-28 19:06:34 +0000115 struct mutex_info* p;
sewardj721ad7b2007-11-30 08:30:29 +0000116
bart4bb53d82008-02-28 19:06:34 +0000117 tl_assert(offsetof(DrdClientobj, mutex) == 0);
bart72b751c2008-03-01 13:44:24 +0000118 p = &clientobj_get(mutex, ClientMutex)->mutex;
bart4bb53d82008-02-28 19:06:34 +0000119 if (p)
120 {
bart4bb53d82008-02-28 19:06:34 +0000121 return p;
122 }
sewardj721ad7b2007-11-30 08:30:29 +0000123
bart0268dfa2008-03-11 20:10:21 +0000124 if (clientobj_present(mutex, mutex + 1))
sewardj721ad7b2007-11-30 08:30:29 +0000125 {
bart6b717612008-03-24 09:29:38 +0000126 not_a_mutex(mutex);
bart5bd9f2d2008-03-03 20:31:58 +0000127 return 0;
sewardj721ad7b2007-11-30 08:30:29 +0000128 }
bart4bb53d82008-02-28 19:06:34 +0000129
bart0268dfa2008-03-11 20:10:21 +0000130 p = &clientobj_add(mutex, ClientMutex)->mutex;
131 mutex_initialize(p, mutex, mutex_type);
bart4bb53d82008-02-28 19:06:34 +0000132 return p;
sewardjaf44c822007-11-25 14:01:38 +0000133}
134
bart3b1ee452008-02-29 19:28:15 +0000135struct mutex_info* mutex_get(const Addr mutex)
136{
137 tl_assert(offsetof(DrdClientobj, mutex) == 0);
bart72b751c2008-03-01 13:44:24 +0000138 return &clientobj_get(mutex, ClientMutex)->mutex;
bart3b1ee452008-02-29 19:28:15 +0000139}
140
bart00344642008-03-01 15:27:41 +0000141/** Called before pthread_mutex_init(). */
sewardj721ad7b2007-11-30 08:30:29 +0000142struct mutex_info*
bart0268dfa2008-03-11 20:10:21 +0000143mutex_init(const Addr mutex, const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +0000144{
bart00344642008-03-01 15:27:41 +0000145 struct mutex_info* p;
sewardjaf44c822007-11-25 14:01:38 +0000146
sewardjaf44c822007-11-25 14:01:38 +0000147 if (s_trace_mutex)
148 {
bart3b1ee452008-02-29 19:28:15 +0000149 VG_(message)(Vg_UserMsg,
150 "[%d/%d] mutex_init %s 0x%lx",
151 VG_(get_running_tid)(),
152 thread_get_running_tid(),
sewardj347eeba2008-01-21 14:19:07 +0000153 mutex_type_name(mutex_type),
sewardjaf44c822007-11-25 14:01:38 +0000154 mutex);
155 }
156
bart00344642008-03-01 15:27:41 +0000157 if (mutex_type == mutex_type_invalid_mutex)
158 {
bart6b717612008-03-24 09:29:38 +0000159 not_a_mutex(mutex);
bart00344642008-03-01 15:27:41 +0000160 return 0;
161 }
162
163 p = mutex_get(mutex);
164 if (p)
sewardj347eeba2008-01-21 14:19:07 +0000165 {
166 const ThreadId vg_tid = VG_(get_running_tid)();
167 MutexErrInfo MEI
bart00344642008-03-01 15:27:41 +0000168 = { p->a1, p->recursion_count, p->owner };
sewardj347eeba2008-01-21 14:19:07 +0000169 VG_(maybe_record_error)(vg_tid,
170 MutexErr,
171 VG_(get_IP)(vg_tid),
172 "Mutex reinitialization",
173 &MEI);
bart00344642008-03-01 15:27:41 +0000174 return p;
sewardj347eeba2008-01-21 14:19:07 +0000175 }
bart0268dfa2008-03-11 20:10:21 +0000176 p = mutex_get_or_allocate(mutex, mutex_type);
sewardj347eeba2008-01-21 14:19:07 +0000177
bart00344642008-03-01 15:27:41 +0000178 return p;
sewardjaf44c822007-11-25 14:01:38 +0000179}
180
bart46d5f172008-02-28 19:49:37 +0000181/** Called after pthread_mutex_destroy(). */
sewardj347eeba2008-01-21 14:19:07 +0000182void mutex_post_destroy(const Addr mutex)
183{
bart72b751c2008-03-01 13:44:24 +0000184 struct mutex_info* p;
sewardj347eeba2008-01-21 14:19:07 +0000185
bart72b751c2008-03-01 13:44:24 +0000186 p = mutex_get(mutex);
187 if (p == 0)
188 {
bart6b717612008-03-24 09:29:38 +0000189 not_a_mutex(mutex);
bart72b751c2008-03-01 13:44:24 +0000190 return;
191 }
192
193 clientobj_remove(mutex, ClientMutex);
sewardj347eeba2008-01-21 14:19:07 +0000194}
195
bart8bba1f72008-02-27 16:13:05 +0000196/** Called before pthread_mutex_lock() is invoked. If a data structure for
197 * the client-side object was not yet created, do this now. Also check whether
198 * an attempt is made to lock recursively a synchronization object that must
199 * not be locked recursively.
200 */
bart2e3a3c12008-03-24 08:33:47 +0000201void mutex_pre_lock(const Addr mutex, const MutexT mutex_type,
202 const Bool trylock)
bart8bba1f72008-02-27 16:13:05 +0000203{
bart635cb162008-02-28 08:30:43 +0000204 struct mutex_info* p;
205
bart0268dfa2008-03-11 20:10:21 +0000206 p = mutex_get_or_allocate(mutex, mutex_type);
bart00344642008-03-01 15:27:41 +0000207 if (s_trace_mutex)
208 {
209 VG_(message)(Vg_UserMsg,
210 "[%d/%d] pre_mutex_lock %s 0x%lx rc %d owner %d",
211 VG_(get_running_tid)(),
212 thread_get_running_tid(),
bart6b717612008-03-24 09:29:38 +0000213 p ? mutex_get_typename(p) : "(?)",
bart00344642008-03-01 15:27:41 +0000214 mutex,
bart2e3a3c12008-03-24 08:33:47 +0000215 p ? p->recursion_count : -1,
216 p ? p->owner : DRD_INVALID_THREADID);
bart00344642008-03-01 15:27:41 +0000217 }
218
bart2e3a3c12008-03-24 08:33:47 +0000219 if (p == 0)
220 {
bart6b717612008-03-24 09:29:38 +0000221 not_a_mutex(mutex);
bart2e3a3c12008-03-24 08:33:47 +0000222 return;
223 }
224
225 tl_assert(p);
226
bart00344642008-03-01 15:27:41 +0000227 if (mutex_type == mutex_type_invalid_mutex)
228 {
bart6b717612008-03-24 09:29:38 +0000229 not_a_mutex(mutex);
bart00344642008-03-01 15:27:41 +0000230 return;
231 }
232
bart2e3a3c12008-03-24 08:33:47 +0000233 if (! trylock
234 && p->owner == thread_get_running_tid()
bart8bba1f72008-02-27 16:13:05 +0000235 && p->recursion_count >= 1
236 && mutex_type != mutex_type_recursive_mutex)
237 {
bart4bb53d82008-02-28 19:06:34 +0000238 MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
bart8bba1f72008-02-27 16:13:05 +0000239 VG_(maybe_record_error)(VG_(get_running_tid)(),
240 MutexErr,
241 VG_(get_IP)(VG_(get_running_tid)()),
242 "Recursive locking not allowed",
243 &MEI);
244 }
245}
246
sewardjaf44c822007-11-25 14:01:38 +0000247/**
248 * Update mutex_info state when locking the pthread_mutex_t mutex.
249 * Note: this function must be called after pthread_mutex_lock() has been
250 * called, or a race condition is triggered !
251 */
bart4a975e12008-03-30 13:28:33 +0000252void mutex_post_lock(const Addr mutex, const Bool took_lock,
253 const Bool post_cond_wait)
sewardjaf44c822007-11-25 14:01:38 +0000254{
bart3b1ee452008-02-29 19:28:15 +0000255 const DrdThreadId drd_tid = thread_get_running_tid();
bart00344642008-03-01 15:27:41 +0000256 struct mutex_info* p;
257
258 p = mutex_get(mutex);
sewardjaf44c822007-11-25 14:01:38 +0000259
260 if (s_trace_mutex)
261 {
bart3b1ee452008-02-29 19:28:15 +0000262 VG_(message)(Vg_UserMsg,
bart4a975e12008-03-30 13:28:33 +0000263 "[%d/%d] %s %s 0x%lx rc %d owner %d%s",
bart3b1ee452008-02-29 19:28:15 +0000264 VG_(get_running_tid)(),
sewardjaf44c822007-11-25 14:01:38 +0000265 drd_tid,
bart4a975e12008-03-30 13:28:33 +0000266 post_cond_wait ? "cond_post_wait " : "post_mutex_lock",
bart00344642008-03-01 15:27:41 +0000267 p ? mutex_get_typename(p) : "(?)",
sewardjaf44c822007-11-25 14:01:38 +0000268 mutex,
269 p ? p->recursion_count : 0,
bartfa37c922008-03-30 08:41:59 +0000270 p ? p->owner : VG_INVALID_THREADID,
271 took_lock ? "" : " (locking failed)");
sewardjaf44c822007-11-25 14:01:38 +0000272 }
273
bart777f7fe2008-03-02 17:43:18 +0000274 if (! p || ! took_lock)
bart5bd9f2d2008-03-03 20:31:58 +0000275 return;
bart5357fcb2008-02-27 15:46:00 +0000276
sewardjaf44c822007-11-25 14:01:38 +0000277 if (p->recursion_count == 0)
278 {
bart5bd9f2d2008-03-03 20:31:58 +0000279 const DrdThreadId last_owner = p->owner;
280
281 if (last_owner != drd_tid && last_owner != DRD_INVALID_THREADID)
barta2b6e1b2008-03-17 18:32:39 +0000282 {
283 tl_assert(p->last_locked_segment);
284 thread_combine_vc2(drd_tid, &p->last_locked_segment->vc);
285 }
bart5bd9f2d2008-03-03 20:31:58 +0000286 thread_new_segment(drd_tid);
287
sewardjaf44c822007-11-25 14:01:38 +0000288 p->owner = drd_tid;
289 s_mutex_lock_count++;
290 }
291 else if (p->owner != drd_tid)
292 {
bart3b1ee452008-02-29 19:28:15 +0000293 VG_(message)(Vg_UserMsg,
sewardjaf44c822007-11-25 14:01:38 +0000294 "The impossible happened: mutex 0x%lx is locked"
295 " simultaneously by two threads (recursion count %d,"
296 " owners %d and %d) !",
bart4bb53d82008-02-28 19:06:34 +0000297 p->a1, p->recursion_count, p->owner, drd_tid);
sewardj347eeba2008-01-21 14:19:07 +0000298 p->owner = drd_tid;
sewardjaf44c822007-11-25 14:01:38 +0000299 }
300 p->recursion_count++;
sewardjaf44c822007-11-25 14:01:38 +0000301}
302
303/**
304 * Update mutex_info state when unlocking the pthread_mutex_t mutex.
305 * Note: this function must be called before pthread_mutex_unlock() is called,
306 * or a race condition is triggered !
bartb78312c2008-02-29 11:00:17 +0000307 * @return New value of the mutex recursion count.
sewardjaf44c822007-11-25 14:01:38 +0000308 * @param mutex Pointer to pthread_mutex_t data structure in the client space.
309 * @param tid ThreadId of the thread calling pthread_mutex_unlock().
310 * @param vc Pointer to the current vector clock of thread tid.
311 */
bart777f7fe2008-03-02 17:43:18 +0000312void mutex_unlock(const Addr mutex, const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +0000313{
bartb78312c2008-02-29 11:00:17 +0000314 const DrdThreadId drd_tid = thread_get_running_tid();
315 const ThreadId vg_tid = VG_(get_running_tid)();
sewardjaf44c822007-11-25 14:01:38 +0000316 struct mutex_info* const p = mutex_get(mutex);
317
bart777f7fe2008-03-02 17:43:18 +0000318 if (s_trace_mutex)
sewardjaf44c822007-11-25 14:01:38 +0000319 {
bart3b1ee452008-02-29 19:28:15 +0000320 VG_(message)(Vg_UserMsg,
321 "[%d/%d] mutex_unlock %s 0x%lx rc %d",
322 vg_tid,
323 drd_tid,
bart6b717612008-03-24 09:29:38 +0000324 p ? mutex_get_typename(p) : "(?)",
sewardjaf44c822007-11-25 14:01:38 +0000325 mutex,
barta2b6e1b2008-03-17 18:32:39 +0000326 p ? p->recursion_count : 0);
sewardjaf44c822007-11-25 14:01:38 +0000327 }
328
bart777f7fe2008-03-02 17:43:18 +0000329 if (p == 0 || mutex_type == mutex_type_invalid_mutex)
bartab7a6442008-02-25 19:46:14 +0000330 {
bart6b717612008-03-24 09:29:38 +0000331 not_a_mutex(mutex);
bart5bd9f2d2008-03-03 20:31:58 +0000332 return;
bartab7a6442008-02-25 19:46:14 +0000333 }
334
bart5357fcb2008-02-27 15:46:00 +0000335 if (p->owner == DRD_INVALID_THREADID)
336 {
bart4bb53d82008-02-28 19:06:34 +0000337 MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
bart5357fcb2008-02-27 15:46:00 +0000338 VG_(maybe_record_error)(vg_tid,
339 MutexErr,
340 VG_(get_IP)(vg_tid),
341 "Mutex not locked",
342 &MEI);
bart5bd9f2d2008-03-03 20:31:58 +0000343 return;
bart5357fcb2008-02-27 15:46:00 +0000344 }
345
sewardjaf44c822007-11-25 14:01:38 +0000346 tl_assert(p);
bart5357fcb2008-02-27 15:46:00 +0000347 if (p->mutex_type != mutex_type)
348 {
barta2b6e1b2008-03-17 18:32:39 +0000349 VG_(message)(Vg_UserMsg, "??? mutex 0x%lx: type changed from %d into %d",
bart5bd9f2d2008-03-03 20:31:58 +0000350 p->a1, p->mutex_type, mutex_type);
bart5357fcb2008-02-27 15:46:00 +0000351 }
sewardj721ad7b2007-11-30 08:30:29 +0000352 tl_assert(p->mutex_type == mutex_type);
sewardjaf44c822007-11-25 14:01:38 +0000353 tl_assert(p->owner != DRD_INVALID_THREADID);
sewardj721ad7b2007-11-30 08:30:29 +0000354
bart777f7fe2008-03-02 17:43:18 +0000355 if (p->owner != drd_tid || p->recursion_count <= 0)
sewardjaf44c822007-11-25 14:01:38 +0000356 {
bart4bb53d82008-02-28 19:06:34 +0000357 MutexErrInfo MEI = { p->a1, p->recursion_count, p->owner };
sewardjaf44c822007-11-25 14:01:38 +0000358 VG_(maybe_record_error)(vg_tid,
359 MutexErr,
360 VG_(get_IP)(vg_tid),
bart777f7fe2008-03-02 17:43:18 +0000361 "Mutex not locked by calling thread",
sewardjaf44c822007-11-25 14:01:38 +0000362 &MEI);
bart777f7fe2008-03-02 17:43:18 +0000363 return;
sewardjaf44c822007-11-25 14:01:38 +0000364 }
bart777f7fe2008-03-02 17:43:18 +0000365 tl_assert(p->recursion_count > 0);
sewardjaf44c822007-11-25 14:01:38 +0000366 p->recursion_count--;
bart777f7fe2008-03-02 17:43:18 +0000367 tl_assert(p->recursion_count >= 0);
sewardj347eeba2008-01-21 14:19:07 +0000368
sewardjaf44c822007-11-25 14:01:38 +0000369 if (p->recursion_count == 0)
370 {
371 /* This pthread_mutex_unlock() call really unlocks the mutex. Save the */
372 /* current vector clock of the thread such that it is available when */
373 /* this mutex is locked again. */
sewardjaf44c822007-11-25 14:01:38 +0000374
barta2b6e1b2008-03-17 18:32:39 +0000375 thread_get_latest_segment(&p->last_locked_segment, drd_tid);
sewardjaf44c822007-11-25 14:01:38 +0000376 thread_new_segment(drd_tid);
377 }
sewardjaf44c822007-11-25 14:01:38 +0000378}
379
380const char* mutex_get_typename(struct mutex_info* const p)
381{
382 tl_assert(p);
sewardj721ad7b2007-11-30 08:30:29 +0000383
sewardj347eeba2008-01-21 14:19:07 +0000384 return mutex_type_name(p->mutex_type);
385}
386
387const char* mutex_type_name(const MutexT mt)
388{
389 switch (mt)
sewardjaf44c822007-11-25 14:01:38 +0000390 {
bart635cb162008-02-28 08:30:43 +0000391 case mutex_type_invalid_mutex:
392 return "invalid mutex";
bart5357fcb2008-02-27 15:46:00 +0000393 case mutex_type_recursive_mutex:
394 return "recursive mutex";
395 case mutex_type_errorcheck_mutex:
396 return "error checking mutex";
397 case mutex_type_default_mutex:
sewardjaf44c822007-11-25 14:01:38 +0000398 return "mutex";
sewardj721ad7b2007-11-30 08:30:29 +0000399 case mutex_type_spinlock:
sewardjaf44c822007-11-25 14:01:38 +0000400 return "spinlock";
401 default:
402 tl_assert(0);
403 }
404 return "?";
405}
406
bart5357fcb2008-02-27 15:46:00 +0000407/** Return true if the specified mutex is locked by any thread. */
408static Bool mutex_is_locked(struct mutex_info* const p)
409{
410 tl_assert(p);
411 return (p->recursion_count > 0);
412}
413
sewardjaf44c822007-11-25 14:01:38 +0000414Bool mutex_is_locked_by(const Addr mutex, const DrdThreadId tid)
415{
416 struct mutex_info* const p = mutex_get(mutex);
sewardjaf44c822007-11-25 14:01:38 +0000417 if (p)
418 {
419 return (p->recursion_count > 0 && p->owner == tid);
420 }
421 return False;
422}
423
sewardjaf44c822007-11-25 14:01:38 +0000424int mutex_get_recursion_count(const Addr mutex)
425{
426 struct mutex_info* const p = mutex_get(mutex);
427 tl_assert(p);
428 return p->recursion_count;
429}
430
431/**
bart301c3112008-02-24 18:22:37 +0000432 * Call this function when thread tid stops to exist, such that the
sewardjaf44c822007-11-25 14:01:38 +0000433 * "last owner" field can be cleared if it still refers to that thread.
sewardjaf44c822007-11-25 14:01:38 +0000434 */
bart301c3112008-02-24 18:22:37 +0000435void mutex_thread_delete(const DrdThreadId tid)
sewardjaf44c822007-11-25 14:01:38 +0000436{
bart4bb53d82008-02-28 19:06:34 +0000437 struct mutex_info* p;
438
bart72b751c2008-03-01 13:44:24 +0000439 clientobj_resetiter();
440 for ( ; (p = &clientobj_next(ClientMutex)->mutex) != 0; )
sewardjaf44c822007-11-25 14:01:38 +0000441 {
bart4bb53d82008-02-28 19:06:34 +0000442 if (p->owner == tid && p->recursion_count > 0)
sewardjaf44c822007-11-25 14:01:38 +0000443 {
bart5357fcb2008-02-27 15:46:00 +0000444 MutexErrInfo MEI
bart4bb53d82008-02-28 19:06:34 +0000445 = { p->a1, p->recursion_count, p->owner };
bart5357fcb2008-02-27 15:46:00 +0000446 VG_(maybe_record_error)(VG_(get_running_tid)(),
447 MutexErr,
448 VG_(get_IP)(VG_(get_running_tid)()),
449 "Mutex still locked at thread exit",
450 &MEI);
sewardjaf44c822007-11-25 14:01:38 +0000451 p->owner = VG_INVALID_THREADID;
452 }
453 }
454}
455
sewardjaf44c822007-11-25 14:01:38 +0000456ULong get_mutex_lock_count(void)
457{
458 return s_mutex_lock_count;
459}