blob: e45c6a692a900ed2c133e2e11257a31473a5266d [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
26#include "drd_error.h"
27#include "drd_mutex.h"
28#include "drd_suppression.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()
32#include "pub_tool_libcprint.h" // VG_(printf)()
33#include "pub_tool_machine.h" // VG_(get_IP)()
34#include "pub_tool_threadstate.h" // VG_(get_running_tid)()
35
36
37// Type definitions.
38
39struct mutex_info
40{
41 Addr mutex; // Pointer to client mutex.
42 SizeT size; // Size in bytes of client-side object.
sewardj721ad7b2007-11-30 08:30:29 +000043 MutexT mutex_type; // pthread_mutex_t or pthread_spinlock_t.
sewardjaf44c822007-11-25 14:01:38 +000044 int recursion_count; // 0 if free, >= 1 if locked.
45 DrdThreadId owner; // owner if locked, last owner if free.
46 VectorClock vc; // vector clock associated with last unlock.
47};
48
49
sewardj347eeba2008-01-21 14:19:07 +000050// Local functions.
51
bart5357fcb2008-02-27 15:46:00 +000052static Bool mutex_is_locked(struct mutex_info* const p);
sewardj347eeba2008-01-21 14:19:07 +000053static void mutex_destroy(struct mutex_info* const p);
54
55
sewardjaf44c822007-11-25 14:01:38 +000056// Local variables.
57
58static Bool s_trace_mutex;
59static ULong s_mutex_lock_count;
60struct mutex_info s_mutex[256];
61
62
63// Function definitions.
64
65void mutex_set_trace(const Bool trace_mutex)
66{
67 tl_assert(!! trace_mutex == trace_mutex);
68 s_trace_mutex = trace_mutex;
69}
70
71static
72void mutex_initialize(struct mutex_info* const p,
73 const Addr mutex,
sewardj721ad7b2007-11-30 08:30:29 +000074 const SizeT size,
75 const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +000076{
77 tl_assert(mutex != 0);
78 tl_assert(size > 0);
bart5357fcb2008-02-27 15:46:00 +000079#if 0
sewardj721ad7b2007-11-30 08:30:29 +000080 tl_assert(mutex_type == mutex_type_mutex
81 || mutex_type == mutex_type_spinlock);
bart5357fcb2008-02-27 15:46:00 +000082#endif
sewardjaf44c822007-11-25 14:01:38 +000083
84 p->mutex = mutex;
85 p->size = size;
sewardj721ad7b2007-11-30 08:30:29 +000086 p->mutex_type = mutex_type;
sewardjaf44c822007-11-25 14:01:38 +000087 p->recursion_count = 0;
88 p->owner = DRD_INVALID_THREADID;
89 vc_init(&p->vc, 0, 0);
90}
91
92static
sewardj721ad7b2007-11-30 08:30:29 +000093struct mutex_info*
94mutex_get_or_allocate(const Addr mutex,
95 const SizeT size,
96 const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +000097{
98 int i;
sewardj721ad7b2007-11-30 08:30:29 +000099
bart5357fcb2008-02-27 15:46:00 +0000100#if 0
sewardj721ad7b2007-11-30 08:30:29 +0000101 tl_assert(mutex_type == mutex_type_mutex
102 || mutex_type == mutex_type_spinlock);
bart5357fcb2008-02-27 15:46:00 +0000103#endif
sewardj721ad7b2007-11-30 08:30:29 +0000104
sewardjaf44c822007-11-25 14:01:38 +0000105 for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++)
sewardj721ad7b2007-11-30 08:30:29 +0000106 {
sewardjaf44c822007-11-25 14:01:38 +0000107 if (s_mutex[i].mutex == mutex)
sewardj721ad7b2007-11-30 08:30:29 +0000108 {
bart5357fcb2008-02-27 15:46:00 +0000109 if (s_mutex[i].mutex_type != mutex_type)
110 {
111 VG_(message)(Vg_DebugMsg, "??? mutex %p: type changed from %d into %d",
112 s_mutex[i].mutex, s_mutex[i].mutex_type, mutex_type);
113 }
sewardj721ad7b2007-11-30 08:30:29 +0000114 tl_assert(s_mutex[i].mutex_type == mutex_type);
115 tl_assert(s_mutex[i].size == size);
sewardjaf44c822007-11-25 14:01:38 +0000116 return &s_mutex[i];
sewardj721ad7b2007-11-30 08:30:29 +0000117 }
118 }
sewardjaf44c822007-11-25 14:01:38 +0000119 for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++)
120 {
121 if (s_mutex[i].mutex == 0)
122 {
bartab7a6442008-02-25 19:46:14 +0000123 if (drd_is_any_suppressed(mutex, mutex + size))
124 {
barte883bc82008-02-26 19:13:04 +0000125 GenericErrInfo GEI;
bartab7a6442008-02-25 19:46:14 +0000126 VG_(maybe_record_error)(VG_(get_running_tid)(),
barte883bc82008-02-26 19:13:04 +0000127 GenericErr,
bartab7a6442008-02-25 19:46:14 +0000128 VG_(get_IP)(VG_(get_running_tid)()),
129 "Not a mutex",
barte883bc82008-02-26 19:13:04 +0000130 &GEI);
bartab7a6442008-02-25 19:46:14 +0000131 return 0;
132 }
sewardj721ad7b2007-11-30 08:30:29 +0000133 mutex_initialize(&s_mutex[i], mutex, size, mutex_type);
sewardjaf44c822007-11-25 14:01:38 +0000134 drd_start_suppression(mutex, mutex + size,
135 mutex_get_typename(&s_mutex[i]));
136 return &s_mutex[i];
137 }
138 }
139 tl_assert(0);
140 return 0;
141}
142
sewardj721ad7b2007-11-30 08:30:29 +0000143struct mutex_info*
144mutex_init(const Addr mutex, const SizeT size, const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +0000145{
146 struct mutex_info* mutex_p;
147
sewardjaf44c822007-11-25 14:01:38 +0000148 if (s_trace_mutex)
149 {
150 const ThreadId vg_tid = VG_(get_running_tid)();
151 const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(vg_tid);
152 VG_(message)(Vg_DebugMsg,
153 "drd_post_mutex_init tid = %d/%d, %s 0x%lx",
154 vg_tid, drd_tid,
sewardj347eeba2008-01-21 14:19:07 +0000155 mutex_type_name(mutex_type),
sewardjaf44c822007-11-25 14:01:38 +0000156 mutex);
157 }
158
bart5357fcb2008-02-27 15:46:00 +0000159#if 0
sewardj347eeba2008-01-21 14:19:07 +0000160 tl_assert(mutex_type == mutex_type_mutex
161 || mutex_type == mutex_type_spinlock);
bart5357fcb2008-02-27 15:46:00 +0000162#endif
163
sewardj347eeba2008-01-21 14:19:07 +0000164 mutex_p = mutex_get(mutex);
165 if (mutex_p)
166 {
167 const ThreadId vg_tid = VG_(get_running_tid)();
168 MutexErrInfo MEI
169 = { mutex_p->mutex, mutex_p->recursion_count, mutex_p->owner };
170 VG_(maybe_record_error)(vg_tid,
171 MutexErr,
172 VG_(get_IP)(vg_tid),
173 "Mutex reinitialization",
174 &MEI);
175 mutex_destroy(mutex_p);
176 }
177 mutex_p = mutex_get_or_allocate(mutex, size, mutex_type);
178
sewardjaf44c822007-11-25 14:01:38 +0000179 return mutex_p;
180}
181
sewardj347eeba2008-01-21 14:19:07 +0000182static void mutex_destroy(struct mutex_info* const p)
sewardjaf44c822007-11-25 14:01:38 +0000183{
184 if (s_trace_mutex)
185 {
186 const ThreadId vg_tid = VG_(get_running_tid)();
187 const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(vg_tid);
188 VG_(message)(Vg_DebugMsg,
189 "drd_pre_mutex_destroy tid = %d/%d, %s 0x%lx",
190 vg_tid, drd_tid,
191 mutex_get_typename(p),
192 p->mutex);
193 }
194
bart5357fcb2008-02-27 15:46:00 +0000195 if (mutex_is_locked(p))
196 {
197 MutexErrInfo MEI = { p->mutex, p->recursion_count, p->owner };
198 VG_(maybe_record_error)(VG_(get_running_tid)(),
199 MutexErr,
200 VG_(get_IP)(VG_(get_running_tid)()),
201 "Destroying locked mutex",
202 &MEI);
203 }
204
sewardjaf44c822007-11-25 14:01:38 +0000205 drd_finish_suppression(p->mutex, p->mutex + p->size);
206
207 vc_cleanup(&p->vc);
208 p->mutex = 0;
209}
210
sewardj347eeba2008-01-21 14:19:07 +0000211void mutex_pre_destroy(struct mutex_info* const p)
212{
213 return mutex_destroy(p);
214}
215
216void mutex_post_destroy(const Addr mutex)
217{
218 struct mutex_info* p;
219
220 p = mutex_get(mutex);
221 tl_assert(p);
222 if (p)
223 {
224 if (mutex_get_recursion_count(mutex) > 0)
225 {
226 const ThreadId vg_tid = VG_(get_running_tid)();
227 MutexErrInfo MEI = { p->mutex, p->recursion_count, p->owner };
228 VG_(maybe_record_error)(vg_tid,
229 MutexErr,
230 VG_(get_IP)(vg_tid),
231 "Destroying locked mutex",
232 &MEI);
233 }
234 mutex_pre_destroy(p);
235 }
236}
237
sewardjaf44c822007-11-25 14:01:38 +0000238struct mutex_info* mutex_get(const Addr mutex)
239{
240 int i;
241 for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++)
242 if (s_mutex[i].mutex == mutex)
243 return &s_mutex[i];
244 return 0;
245}
246
bart8bba1f72008-02-27 16:13:05 +0000247/** Called before pthread_mutex_lock() is invoked. If a data structure for
248 * the client-side object was not yet created, do this now. Also check whether
249 * an attempt is made to lock recursively a synchronization object that must
250 * not be locked recursively.
251 */
252void mutex_pre_lock(const Addr mutex, const SizeT size, MutexT mutex_type)
253{
bart635cb162008-02-28 08:30:43 +0000254 struct mutex_info* p;
255
256 p = mutex_get(mutex);
bart8bba1f72008-02-27 16:13:05 +0000257 if (p == 0)
258 {
259 mutex_init(mutex, size, mutex_type);
260 p = mutex_get(mutex);
261 }
bart635cb162008-02-28 08:30:43 +0000262
bart8bba1f72008-02-27 16:13:05 +0000263 tl_assert(p);
264
265 if (p->owner == thread_get_running_tid()
266 && p->recursion_count >= 1
267 && mutex_type != mutex_type_recursive_mutex)
268 {
269 MutexErrInfo MEI = { p->mutex, p->recursion_count, p->owner };
270 VG_(maybe_record_error)(VG_(get_running_tid)(),
271 MutexErr,
272 VG_(get_IP)(VG_(get_running_tid)()),
273 "Recursive locking not allowed",
274 &MEI);
275 }
276}
277
sewardjaf44c822007-11-25 14:01:38 +0000278/**
279 * Update mutex_info state when locking the pthread_mutex_t mutex.
280 * Note: this function must be called after pthread_mutex_lock() has been
281 * called, or a race condition is triggered !
282 */
bart8bba1f72008-02-27 16:13:05 +0000283int mutex_post_lock(const Addr mutex, const SizeT size, MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +0000284{
285 const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(VG_(get_running_tid)());
sewardj721ad7b2007-11-30 08:30:29 +0000286 struct mutex_info* const p = mutex_get_or_allocate(mutex, size, mutex_type);
sewardjaf44c822007-11-25 14:01:38 +0000287
288 if (s_trace_mutex)
289 {
290 const ThreadId tid = DrdThreadIdToVgThreadId(drd_tid);
291 VG_(message)(Vg_DebugMsg,
292 "drd_post_mutex_lock tid = %d/%d, %s 0x%lx rc %d owner %d",
293 tid,
294 drd_tid,
295 mutex_get_typename(p),
296 mutex,
297 p ? p->recursion_count : 0,
298 p ? p->owner : VG_INVALID_THREADID);
299 }
300
bart635cb162008-02-28 08:30:43 +0000301 if (mutex_type == mutex_type_invalid_mutex)
302 {
303 GenericErrInfo GEI;
304 VG_(maybe_record_error)(VG_(get_running_tid)(),
305 GenericErr,
306 VG_(get_IP)(VG_(get_running_tid)()),
307 "Invalid mutex",
308 &GEI);
309 }
310
bartab7a6442008-02-25 19:46:14 +0000311 if (p == 0)
312 {
barte883bc82008-02-26 19:13:04 +0000313 GenericErrInfo GEI;
bartab7a6442008-02-25 19:46:14 +0000314 VG_(maybe_record_error)(VG_(get_running_tid)(),
barte883bc82008-02-26 19:13:04 +0000315 GenericErr,
bartab7a6442008-02-25 19:46:14 +0000316 VG_(get_IP)(VG_(get_running_tid)()),
317 "Not a mutex",
barte883bc82008-02-26 19:13:04 +0000318 &GEI);
bartab7a6442008-02-25 19:46:14 +0000319 return 0;
320 }
321
bart5357fcb2008-02-27 15:46:00 +0000322#if 0
sewardj721ad7b2007-11-30 08:30:29 +0000323 tl_assert(mutex_type == mutex_type_mutex
324 || mutex_type == mutex_type_spinlock);
bart5357fcb2008-02-27 15:46:00 +0000325#endif
326
sewardj721ad7b2007-11-30 08:30:29 +0000327 tl_assert(p->mutex_type == mutex_type);
328 tl_assert(p->size == size);
329
sewardjaf44c822007-11-25 14:01:38 +0000330 if (p->recursion_count == 0)
331 {
332 p->owner = drd_tid;
333 s_mutex_lock_count++;
334 }
335 else if (p->owner != drd_tid)
336 {
337 VG_(message)(Vg_DebugMsg,
338 "The impossible happened: mutex 0x%lx is locked"
339 " simultaneously by two threads (recursion count %d,"
340 " owners %d and %d) !",
341 p->mutex, p->recursion_count, p->owner, drd_tid);
sewardj347eeba2008-01-21 14:19:07 +0000342 p->owner = drd_tid;
sewardjaf44c822007-11-25 14:01:38 +0000343 }
344 p->recursion_count++;
345
346 if (p->recursion_count == 1)
347 {
bartab7a6442008-02-25 19:46:14 +0000348 const DrdThreadId last_owner = p->owner;
349
sewardjaf44c822007-11-25 14:01:38 +0000350 if (last_owner != drd_tid && last_owner != DRD_INVALID_THREADID)
351 thread_combine_vc2(drd_tid, mutex_get_last_vc(mutex));
352 thread_new_segment(drd_tid);
353 }
354
355 return p->recursion_count;
356}
357
358/**
359 * Update mutex_info state when unlocking the pthread_mutex_t mutex.
360 * Note: this function must be called before pthread_mutex_unlock() is called,
361 * or a race condition is triggered !
362 * @param mutex Pointer to pthread_mutex_t data structure in the client space.
363 * @param tid ThreadId of the thread calling pthread_mutex_unlock().
364 * @param vc Pointer to the current vector clock of thread tid.
365 */
sewardj721ad7b2007-11-30 08:30:29 +0000366int mutex_unlock(const Addr mutex, const MutexT mutex_type)
sewardjaf44c822007-11-25 14:01:38 +0000367{
368 const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(VG_(get_running_tid)());
369 const ThreadId vg_tid = DrdThreadIdToVgThreadId(drd_tid);
370 const VectorClock* const vc = thread_get_vc(drd_tid);
371 struct mutex_info* const p = mutex_get(mutex);
372
373 if (s_trace_mutex)
374 {
375 VG_(message)(Vg_DebugMsg,
376 "drd_pre_mutex_unlock tid = %d/%d, %s 0x%lx rc %d",
377 vg_tid, drd_tid,
378 mutex_get_typename(p),
379 mutex,
380 p->recursion_count,
381 p->owner);
382 }
383
bart635cb162008-02-28 08:30:43 +0000384 if (mutex_type == mutex_type_invalid_mutex)
385 {
386 GenericErrInfo GEI;
387 VG_(maybe_record_error)(VG_(get_running_tid)(),
388 GenericErr,
389 VG_(get_IP)(VG_(get_running_tid)()),
390 "Invalid mutex",
391 &GEI);
392 }
393
bart5357fcb2008-02-27 15:46:00 +0000394 if (p == 0)
bartab7a6442008-02-25 19:46:14 +0000395 {
barte883bc82008-02-26 19:13:04 +0000396 GenericErrInfo GEI;
bartab7a6442008-02-25 19:46:14 +0000397 VG_(maybe_record_error)(vg_tid,
barte883bc82008-02-26 19:13:04 +0000398 GenericErr,
bartab7a6442008-02-25 19:46:14 +0000399 VG_(get_IP)(vg_tid),
400 "Not a mutex",
barte883bc82008-02-26 19:13:04 +0000401 &GEI);
bartab7a6442008-02-25 19:46:14 +0000402 return 0;
403 }
404
bart5357fcb2008-02-27 15:46:00 +0000405 if (p->owner == DRD_INVALID_THREADID)
406 {
407 MutexErrInfo MEI = { p->mutex, p->recursion_count, p->owner };
408 VG_(maybe_record_error)(vg_tid,
409 MutexErr,
410 VG_(get_IP)(vg_tid),
411 "Mutex not locked",
412 &MEI);
413 return 0;
414 }
415
sewardjaf44c822007-11-25 14:01:38 +0000416 tl_assert(p);
bart5357fcb2008-02-27 15:46:00 +0000417 if (p->mutex_type != mutex_type)
418 {
419 VG_(message)(Vg_DebugMsg, "??? mutex %p: type changed from %d into %d",
420 p->mutex, p->mutex_type, mutex_type);
421 }
sewardj721ad7b2007-11-30 08:30:29 +0000422 tl_assert(p->mutex_type == mutex_type);
sewardjaf44c822007-11-25 14:01:38 +0000423 tl_assert(p->owner != DRD_INVALID_THREADID);
bart5357fcb2008-02-27 15:46:00 +0000424#if 0
sewardj721ad7b2007-11-30 08:30:29 +0000425 tl_assert(mutex_type == mutex_type_mutex
426 || mutex_type == mutex_type_spinlock);
bart5357fcb2008-02-27 15:46:00 +0000427#endif
sewardj721ad7b2007-11-30 08:30:29 +0000428
sewardjaf44c822007-11-25 14:01:38 +0000429 if (p->owner != drd_tid)
430 {
431 MutexErrInfo MEI = { p->mutex, p->recursion_count, p->owner };
432 VG_(maybe_record_error)(vg_tid,
433 MutexErr,
434 VG_(get_IP)(vg_tid),
435 "Mutex not unlocked by owner thread",
436 &MEI);
437 }
438 p->recursion_count--;
sewardj347eeba2008-01-21 14:19:07 +0000439 if (p->recursion_count < 0)
440 {
441 MutexErrInfo MEI
442 = { p->mutex, p->recursion_count, p->owner };
443 VG_(maybe_record_error)(vg_tid,
444 MutexErr,
445 VG_(get_IP)(vg_tid),
446 "Attempt to unlock a mutex that is not locked",
447 &MEI);
448 p->recursion_count = 0;
449 }
450
sewardjaf44c822007-11-25 14:01:38 +0000451 if (p->recursion_count == 0)
452 {
453 /* This pthread_mutex_unlock() call really unlocks the mutex. Save the */
454 /* current vector clock of the thread such that it is available when */
455 /* this mutex is locked again. */
bart301c3112008-02-24 18:22:37 +0000456 vc_assign(&p->vc, vc);
sewardjaf44c822007-11-25 14:01:38 +0000457
458 thread_new_segment(drd_tid);
459 }
460 return p->recursion_count;
461}
462
463const char* mutex_get_typename(struct mutex_info* const p)
464{
465 tl_assert(p);
sewardj721ad7b2007-11-30 08:30:29 +0000466
sewardj347eeba2008-01-21 14:19:07 +0000467 return mutex_type_name(p->mutex_type);
468}
469
470const char* mutex_type_name(const MutexT mt)
471{
472 switch (mt)
sewardjaf44c822007-11-25 14:01:38 +0000473 {
bart635cb162008-02-28 08:30:43 +0000474 case mutex_type_invalid_mutex:
475 return "invalid mutex";
bart5357fcb2008-02-27 15:46:00 +0000476 case mutex_type_recursive_mutex:
477 return "recursive mutex";
478 case mutex_type_errorcheck_mutex:
479 return "error checking mutex";
480 case mutex_type_default_mutex:
sewardjaf44c822007-11-25 14:01:38 +0000481 return "mutex";
sewardj721ad7b2007-11-30 08:30:29 +0000482 case mutex_type_spinlock:
sewardjaf44c822007-11-25 14:01:38 +0000483 return "spinlock";
484 default:
485 tl_assert(0);
486 }
487 return "?";
488}
489
bart5357fcb2008-02-27 15:46:00 +0000490/** Return true if the specified mutex is locked by any thread. */
491static Bool mutex_is_locked(struct mutex_info* const p)
492{
493 tl_assert(p);
494 return (p->recursion_count > 0);
495}
496
sewardjaf44c822007-11-25 14:01:38 +0000497Bool mutex_is_locked_by(const Addr mutex, const DrdThreadId tid)
498{
499 struct mutex_info* const p = mutex_get(mutex);
sewardjaf44c822007-11-25 14:01:38 +0000500 if (p)
501 {
502 return (p->recursion_count > 0 && p->owner == tid);
503 }
504 return False;
505}
506
507const VectorClock* mutex_get_last_vc(const Addr mutex)
508{
509 struct mutex_info* const p = mutex_get(mutex);
510 return p ? &p->vc : 0;
511}
512
513int mutex_get_recursion_count(const Addr mutex)
514{
515 struct mutex_info* const p = mutex_get(mutex);
516 tl_assert(p);
517 return p->recursion_count;
518}
519
520/**
bart301c3112008-02-24 18:22:37 +0000521 * Call this function when thread tid stops to exist, such that the
sewardjaf44c822007-11-25 14:01:38 +0000522 * "last owner" field can be cleared if it still refers to that thread.
sewardjaf44c822007-11-25 14:01:38 +0000523 */
bart301c3112008-02-24 18:22:37 +0000524void mutex_thread_delete(const DrdThreadId tid)
sewardjaf44c822007-11-25 14:01:38 +0000525{
526 int i;
527 for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++)
528 {
529 struct mutex_info* const p = &s_mutex[i];
bart5357fcb2008-02-27 15:46:00 +0000530 if (p->mutex && p->owner == tid && p->recursion_count > 0)
sewardjaf44c822007-11-25 14:01:38 +0000531 {
bart5357fcb2008-02-27 15:46:00 +0000532 MutexErrInfo MEI
533 = { p->mutex, p->recursion_count, p->owner };
534 VG_(maybe_record_error)(VG_(get_running_tid)(),
535 MutexErr,
536 VG_(get_IP)(VG_(get_running_tid)()),
537 "Mutex still locked at thread exit",
538 &MEI);
sewardjaf44c822007-11-25 14:01:38 +0000539 p->owner = VG_INVALID_THREADID;
540 }
541 }
542}
543
544void mutex_stop_using_mem(const Addr a1, const Addr a2)
545{
546 unsigned i;
547 for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++)
548 {
549 if (a1 <= s_mutex[i].mutex && s_mutex[i].mutex < a2)
550 {
551 tl_assert(s_mutex[i].mutex + s_mutex[i].size <= a2);
552 mutex_destroy(&s_mutex[i]);
553 }
554 }
555}
556
557ULong get_mutex_lock_count(void)
558{
559 return s_mutex_lock_count;
560}
sewardj347eeba2008-01-21 14:19:07 +0000561
562
563/*
564 * Local variables:
565 * c-basic-offset: 3
566 * End:
567 */