|
From: <sv...@va...> - 2008-03-24 08:33:43
|
Author: bart
Date: 2008-03-24 08:33:47 +0000 (Mon, 24 Mar 2008)
New Revision: 7769
Log:
Make sure no error message is printed when pthread_mutex_trylock() is called on a non-recursive mutex from the thread that holds a lock on the mutex.
Modified:
trunk/exp-drd/drd_clientreq.c
trunk/exp-drd/drd_clientreq.h
trunk/exp-drd/drd_main.c
trunk/exp-drd/drd_mutex.c
trunk/exp-drd/drd_mutex.h
trunk/exp-drd/drd_pthread_intercepts.c
trunk/exp-drd/drd_track.h
Modified: trunk/exp-drd/drd_clientreq.c
===================================================================
--- trunk/exp-drd/drd_clientreq.c 2008-03-24 06:41:30 UTC (rev 7768)
+++ trunk/exp-drd/drd_clientreq.c 2008-03-24 08:33:47 UTC (rev 7769)
@@ -147,7 +147,7 @@
case VG_USERREQ__PRE_MUTEX_LOCK:
if (thread_enter_synchr(drd_tid) == 0)
- drd_pre_mutex_lock(arg[1], arg[2]);
+ drd_pre_mutex_lock(arg[1], arg[2], arg[3]);
break;
case VG_USERREQ__POST_MUTEX_LOCK:
Modified: trunk/exp-drd/drd_clientreq.h
===================================================================
--- trunk/exp-drd/drd_clientreq.h 2008-03-24 06:41:30 UTC (rev 7768)
+++ trunk/exp-drd/drd_clientreq.h 2008-03-24 08:33:47 UTC (rev 7769)
@@ -57,7 +57,7 @@
/* args: Addr, MutexT */
/* to notify the drd tool of pthread_mutex_lock calls */
VG_USERREQ__PRE_MUTEX_LOCK,
- /* args: Addr, MutexT */
+ /* args: Addr, MutexT, Bool */
/* to notify the drd tool of pthread_mutex_lock calls */
VG_USERREQ__POST_MUTEX_LOCK,
/* args: Addr, Bool */
Modified: trunk/exp-drd/drd_main.c
===================================================================
--- trunk/exp-drd/drd_main.c 2008-03-24 06:41:30 UTC (rev 7768)
+++ trunk/exp-drd/drd_main.c 2008-03-24 08:33:47 UTC (rev 7769)
@@ -628,9 +628,10 @@
mutex_post_destroy(mutex);
}
-void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type)
+void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type,
+ const Bool trylock)
{
- mutex_pre_lock(mutex, mutex_type);
+ mutex_pre_lock(mutex, mutex_type, trylock);
}
void drd_post_mutex_lock(const Addr mutex, const Bool took_lock)
Modified: trunk/exp-drd/drd_mutex.c
===================================================================
--- trunk/exp-drd/drd_mutex.c 2008-03-24 06:41:30 UTC (rev 7768)
+++ trunk/exp-drd/drd_mutex.c 2008-03-24 08:33:47 UTC (rev 7769)
@@ -201,14 +201,12 @@
* an attempt is made to lock recursively a synchronization object that must
* not be locked recursively.
*/
-void mutex_pre_lock(const Addr mutex, MutexT mutex_type)
+void mutex_pre_lock(const Addr mutex, const MutexT mutex_type,
+ const Bool trylock)
{
struct mutex_info* p;
p = mutex_get_or_allocate(mutex, mutex_type);
-
- tl_assert(p);
-
if (s_trace_mutex)
{
VG_(message)(Vg_UserMsg,
@@ -217,10 +215,23 @@
thread_get_running_tid(),
mutex_get_typename(p),
mutex,
- p->recursion_count,
- p->owner);
+ p ? p->recursion_count : -1,
+ p ? p->owner : DRD_INVALID_THREADID);
}
+ if (p == 0)
+ {
+ GenericErrInfo GEI;
+ VG_(maybe_record_error)(VG_(get_running_tid)(),
+ GenericErr,
+ VG_(get_IP)(VG_(get_running_tid)()),
+ "Not a mutex",
+ &GEI);
+ return;
+ }
+
+ tl_assert(p);
+
if (mutex_type == mutex_type_invalid_mutex)
{
GenericErrInfo GEI;
@@ -232,7 +243,8 @@
return;
}
- if (p->owner == thread_get_running_tid()
+ if (! trylock
+ && p->owner == thread_get_running_tid()
&& p->recursion_count >= 1
&& mutex_type != mutex_type_recursive_mutex)
{
Modified: trunk/exp-drd/drd_mutex.h
===================================================================
--- trunk/exp-drd/drd_mutex.h 2008-03-24 06:41:30 UTC (rev 7768)
+++ trunk/exp-drd/drd_mutex.h 2008-03-24 08:33:47 UTC (rev 7769)
@@ -44,8 +44,8 @@
const MutexT mutex_type);
void mutex_post_destroy(const Addr mutex);
struct mutex_info* mutex_get(const Addr mutex);
-void mutex_pre_lock(const Addr mutex,
- const MutexT mutex_type);
+void mutex_pre_lock(const Addr mutex, const MutexT mutex_type,
+ const Bool trylock);
void mutex_post_lock(const Addr mutex, const Bool took_lock);
void mutex_unlock(const Addr mutex, const MutexT mutex_type);
const char* mutex_get_typename(struct mutex_info* const p);
Modified: trunk/exp-drd/drd_pthread_intercepts.c
===================================================================
--- trunk/exp-drd/drd_pthread_intercepts.c 2008-03-24 06:41:30 UTC (rev 7768)
+++ trunk/exp-drd/drd_pthread_intercepts.c 2008-03-24 08:33:47 UTC (rev 7769)
@@ -375,7 +375,7 @@
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
- mutex, mutex_type(mutex), 0, 0, 0);
+ mutex, mutex_type(mutex), 1, 0, 0);
CALL_FN_W_W(ret, fn, mutex);
VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
mutex, ret == 0, 0, 0, 0);
Modified: trunk/exp-drd/drd_track.h
===================================================================
--- trunk/exp-drd/drd_track.h 2008-03-24 06:41:30 UTC (rev 7768)
+++ trunk/exp-drd/drd_track.h 2008-03-24 08:33:47 UTC (rev 7769)
@@ -29,7 +29,8 @@
void drd_pre_mutex_init(Addr mutex, const MutexT mutex_type);
void drd_post_mutex_destroy(Addr mutex, const MutexT mutex_type);
-void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type);
+void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type,
+ const Bool trylock);
void drd_post_mutex_lock(Addr mutex, const Bool took_lock);
void drd_pre_mutex_unlock(const Addr mutex, const MutexT mutex_type);
|